History log of /freebsd/lib/libutil/expand_number.3 (Results 1 – 19 of 19)
Revision (<<< Hide revision tags) (Show revision tags >>>) Date Author Comments
# 2e0caa7c 02-Aug-2025 Dag-Erling Smørgrav <des@FreeBSD.org>

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 i

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

show more ...


Revision tags: release/14.3.0-p1, release/14.2.0-p4, release/13.5.0-p2, release/14.3.0, release/13.4.0-p5, release/13.5.0-p1, release/14.2.0-p3, release/13.5.0, release/14.2.0-p2, release/14.1.0-p8, release/13.4.0-p4, release/14.1.0-p7, release/14.2.0-p1, release/13.4.0-p3, release/14.2.0, release/13.4.0, release/14.1.0, release/13.3.0, release/14.0.0
# fa9896e0 16-Aug-2023 Warner Losh <imp@FreeBSD.org>

Remove $FreeBSD$: two-line nroff pattern

Remove /^\.\\"\n\.\\"\s*\$FreeBSD\$$\n/


# 08300d84 13-Jun-2023 Xin LI <delphij@FreeBSD.org>

expand_number: Tighten check of unit.

The current code silently ignores characters after the unit as long
the unit themselves were recognized. This commit makes expand_number(3)
to fail with EINVAL

expand_number: Tighten check of unit.

The current code silently ignores characters after the unit as long
the unit themselves were recognized. This commit makes expand_number(3)
to fail with EINVAL if buf did not terminate after the unit character.

Historically, the function accepts and ignores "B" as a SI unit, this
behavior is preserved and e.g. KB, MB are still accepted as aliases of
K and M, document this behavior in the manual page.

While I am there, also write a few test cases to validate the behavior.

Reviewed-by: emaste
MFC-after: 2 weeks
Differential Revision: https://reviews.freebsd.org/D40482

show more ...


Revision tags: release/13.2.0, release/12.4.0, release/13.1.0, release/12.3.0, release/13.0.0, release/12.2.0, release/11.4.0, release/12.1.0
# a63915c2 28-Jul-2019 Alan Somers <asomers@FreeBSD.org>

MFHead @r350386

Sponsored by: The FreeBSD Foundation


# 72a52ef8 20-Jul-2019 John Baldwin <jhb@FreeBSD.org>

expand_number(3) parses suffixes, not prefixes.

While here, tidy the opening sentence a bit.

MFC after: 2 weeks
Differential Revision: https://reviews.freebsd.org/D20791


Revision tags: release/11.3.0, release/12.0.0, release/11.2.0, release/10.4.0, release/11.1.0, release/11.0.1, release/11.0.0, release/10.3.0, release/10.2.0, release/10.1.0, release/9.3.0
# 9d2ab4a6 27-Apr-2014 Simon J. Gerraty <sjg@FreeBSD.org>

Merge head


# 84e51a1b 23-Apr-2014 Alan Somers <asomers@FreeBSD.org>

IFC @264767


# 485ac45a 04-Feb-2014 Peter Grehan <grehan@FreeBSD.org>

MFC @ r259205 in preparation for some SVM updates. (for real this time)


Revision tags: release/10.0.0
# 654957c2 19-Nov-2013 Gleb Smirnoff <glebius@FreeBSD.org>

Merge head up to r258343.


# 69b2d025 12-Nov-2013 Eitan Adler <eadler@FreeBSD.org>

Indicate that expand_number is case-insensitive.

Reviewed by: -scsi


Revision tags: release/9.2.0, release/8.4.0, release/9.1.0, release/8.3.0_cvs, release/8.3.0, release/9.0.0, release/7.4.0_cvs, release/8.2.0_cvs, release/7.4.0, release/8.2.0
# a2e0c5ae 15-Aug-2010 Dag-Erling Smørgrav <des@FreeBSD.org>

Further simplify the code, and update the manpage.

Submitted by: Christoph Mallon <christoph.mallon@gmx.de>


Revision tags: release/8.1.0_cvs, release/8.1.0, release/7.3.0_cvs, release/7.3.0, release/8.0.0_cvs, release/8.0.0, release/7.2.0_cvs, release/7.2.0, release/7.1.0_cvs, release/7.1.0, release/6.4.0_cvs, release/6.4.0, release/7.0.0_cvs, release/7.0.0, release/6.3.0_cvs, release/6.3.0
# 26fc3730 18-Nov-2007 John Birrell <jb@FreeBSD.org>

Constify the first argument to expand_number() so that it can
be called with a const without the compiler grisling.


# 61881b52 28-Sep-2007 David E. O'Brien <obrien@FreeBSD.org>

Adjust history.

Approved by: re(ken)


# c2fc8ceb 05-Sep-2007 Pawel Jakub Dawidek <pjd@FreeBSD.org>

Point expand_number(3) at humanize_number(3) and nive versa.

Suggested by: trhodes
Approved by: re (kensmith)


# bd35b57d 01-Sep-2007 Pawel Jakub Dawidek <pjd@FreeBSD.org>

Implement expand_number(3), which is the opposite of humanize_number(3), ie.
a number in human-readable form is converted to int64_t, for example:
123b -> 123
10k -> 10240
16G -> 17179869184

First v

Implement expand_number(3), which is the opposite of humanize_number(3), ie.
a number in human-readable form is converted to int64_t, for example:
123b -> 123
10k -> 10240
16G -> 17179869184

First version submitted by: Eric Anderson <anderson@freebsd.org>
Approved by: re (bmah)

show more ...


Revision tags: release/8.1.0_cvs, release/8.1.0, release/7.3.0_cvs, release/7.3.0, release/8.0.0_cvs, release/8.0.0, release/7.2.0_cvs, release/7.2.0, release/7.1.0_cvs, release/7.1.0, release/6.4.0_cvs, release/6.4.0, release/7.0.0_cvs, release/7.0.0, release/6.3.0_cvs, release/6.3.0
# 26fc3730 18-Nov-2007 John Birrell <jb@FreeBSD.org>

Constify the first argument to expand_number() so that it can
be called with a const without the compiler grisling.


# 61881b52 28-Sep-2007 David E. O'Brien <obrien@FreeBSD.org>

Adjust history.

Approved by: re(ken)


# c2fc8ceb 05-Sep-2007 Pawel Jakub Dawidek <pjd@FreeBSD.org>

Point expand_number(3) at humanize_number(3) and nive versa.

Suggested by: trhodes
Approved by: re (kensmith)


# bd35b57d 01-Sep-2007 Pawel Jakub Dawidek <pjd@FreeBSD.org>

Implement expand_number(3), which is the opposite of humanize_number(3), ie.
a number in human-readable form is converted to int64_t, for example:
123b -> 123
10k -> 10240
16G -> 17179869184

First v

Implement expand_number(3), which is the opposite of humanize_number(3), ie.
a number in human-readable form is converted to int64_t, for example:
123b -> 123
10k -> 10240
16G -> 17179869184

First version submitted by: Eric Anderson <anderson@freebsd.org>
Approved by: re (bmah)

show more ...