libstirshaken
libstirshaken copied to clipboard
Fix size_t and time_t format specifiers
Use "%zu" for size_t and cast time_t to (long long) before printing with "%lld". Fixes the below mentioned warnings.
time_t:
src/stir_shaken_passport.c:818:98: error: format '%zu' expects argument of type 'size_t', but argument 4 has type 'time_t' {aka 'long long int'} [-Werror=format=]
818 | snprintf(err_buf, STIR_SHAKEN_ERROR_BUF_LEN, "PASSporT's @iat (in seconds) is: %zu, freshness is: %u, BUT now is %zu (this is PASSporT to the future, too young, not valid yet)", iat, iat_freshness, now_s);
| ~~^ ~~~
| | |
| unsigned int time_t {aka long long int}
| %llu
size_t:
util/src/stir_shaken_ca.c:128:84: warning: format '%lu' expects argument of type 'long unsigned int', but argument 5 has type 'size_t' {aka 'unsigned int'} [-Wformat=]
128 | mg_printf(nc, "HTTP/1.1 %s %s\r\nContent-Length: %lu\r\nContent-Type: application/json\r\n\r\n%s\r\n\r\n", STIR_SHAKEN_HTTP_REQ_404_NOT_FOUND, error_phrase, strlen(error_body), error_body);
| ~~^ ~~~~~~~~~~~~~~~~~~
| | |
| long unsigned int size_t {aka unsigned int}
| %u
Signed-off-by: Sebastian Kemper [email protected]
These format specifiers actually differ by platform. what os/arch are you targeting where you have issues here?
These format specifiers actually differ by platform. what os/arch are you targeting where you have issues here?
Hi there, Linux/OpenWrt, lots of targets (ppc, mips, mipsel, mips64, aarch64, arc...)
Regarding time_t see also https://github.com/signalwire/freeswitch/pull/1409 (where @crienzo asked you to review a while ago).
Regarding size_t the common answer on stackoveflow as to what format specifier to use seems to be use "z" when you're dealing with compilers supporting C99. You already use "z" elsewhere in the lib, so I figure it's fine.
Looks like this is probably the resolution to the issue I just created #117
Any reason it hasn't been committed yet? I was just preparing to create a PR with the same change from %lu to %zu for all of the strlen calls.
Shouldn't we have %zu in all the places without a cast?
Hi Andrey,
Not sure what you mean. Can you be specific and provide an example?
Kind regards, Seb
Voting again that this be merged. Doesn't seem like anyone has had an objection in a year now.
Why do you cast variables?
Am 20. Dezember 2022 16:14:47 UTC schrieb Andrey Volk @.***>:
Why do you cast variables?
Because of Y2K38
https://en.m.wikipedia.org/wiki/Year_2038_problem
Is there a way to fix the issue without casting?