HomeFreeBSD

libutil: Really fix expand_number(3)

Description

libutil: Really fix expand_number(3)

It is unclear whether this function was originally intended to support
negative numbers. The original implementation used signed integers,
but actually giving it a negative number as input would have invoked
undefined behavior, and the comments (since removed) only mentioned
positive numbers. Fifteen years ago, I “fixed” this by changing the
type from signed to unsigned. However, it would still have accepted
an input with a leading minus sign (though it would have returned its
absolute value). Fifteen years on, change the type back to signed and
fix the logic so it correctly handles both positive and negative
numbers without invoking undefined behavior. This makes it a better
match for humanize_number(3), which it is supposed to complement.

Fixes: bbb2703b4f46
Reviewed by: jhb
Differential Revision: https://reviews.freebsd.org/D51542

Details

Provenance
desAuthored on Aug 2 2025, 2:05 PM
Reviewer
jhb
Differential Revision
D51542: libutil: Really fix expand_number(3)
Parents
rG0c381b7f0570: libutil: Add symbol versioning
Branches
Unknown
Tags
Unknown