]> git.ipfire.org Git - thirdparty/systemd.git/commit
basic/macro: make CONST_MAX(DECIMAL_STR_MAX(…), STRLEN(…)) possible
authorZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Tue, 6 Jul 2021 07:49:56 +0000 (09:49 +0200)
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Fri, 9 Jul 2021 09:11:25 +0000 (11:11 +0200)
commitd3e40294572512810c9329933a488619e7ce22fd
tree7d5ea2d84cf1a2c787f19f006dd3e493a1bc3c76
parent22fd4a8f85aacc2c9d5e185f6d692922b4dacc83
basic/macro: make CONST_MAX(DECIMAL_STR_MAX(…), STRLEN(…)) possible

When those two macros were used together in CONST_MAX(), gcc would complain
about a type mismatch. So either DECIMAL_STR_MAX() should be made size_t like
STRLEN(), or STRLEN() be made unsigned.

Since those macros are only usable on arguments of (small) fixed size, any type
should be fine (even char would work…). For buffer size specifications, both
size_t and unsigned are OK. But unsigned was used for DECIMAL_STR_MAX macros
and FORMAT_foo_MAX macros, making STRLEN the only exception, so let's adjust
STRLEN() to be unsigned too.

Also: I don't think this is currently used anywhere, but if any of those macros
were used as an argument to sprintf, size_t would require a cast. ("%*s"
requires an int/unsigned argument.)
src/basic/macro.h
src/test/test-format-util.c