]> git.ipfire.org Git - thirdparty/systemd.git/commit
macro: handle DECIMAL_STR_MAX() special cases more accurately
authorLennart Poettering <lennart@poettering.net>
Mon, 14 Mar 2022 13:44:54 +0000 (14:44 +0100)
committerLennart Poettering <lennart@poettering.net>
Mon, 14 Mar 2022 17:18:24 +0000 (18:18 +0100)
commit56da8d5af37bda6950f058066fa05c5fdcc20f6e
tree53474755b81812e382ad7f3450f39969aa2088c6
parent845ed472315e5e4ac6960d809ee03ad841fa14ec
macro: handle DECIMAL_STR_MAX() special cases more accurately

So far DECIMAL_STR_MAX() overestimated the types in two ways: it would
also adds space for a "-" for unsigned types.

And it would always return the same size for 64bit values regardless of
signedness, even though the longest maximum numbers for signed and
unsigned differ in length by one digit. i.e. 2^64-1 (i.e. UINT64_MAX) is
one decimal digit longer than -2^63 (INT64_MIN) - for the other integer
widths the number of digits in the "longest" decimal value is always the
same, regardless of signedness. by example: strlen("65535") ==
strlen("32768") (i.e. the relevant 16 bit limits) holds — and similar
for 8bit and 32bit integer width limits — but
strlen("18446744073709551615") > strlen("9223372036854775808") (i.e. the
relevant 64 bit limits).

Let's fix both misestimations.
src/basic/macro.h
src/test/test-format-util.c