-
Notifications
You must be signed in to change notification settings - Fork 23
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Log format specifier for 64-bit unsigned integer uses %lu causing issues when long unsigned is not 64-bits #76
Comments
Hey, thanks for bringing this issue up! The issue you're raising here is definitely a valid one. I'll reach back out when I've had a chance to try a few different options and can figure out which may be the most portable. |
None of the solution is perfect but may be adding a cast to |
Apologies for the long delay in "fixing" this issue in PR #81 . This was in favor of adding additional code to check if the value would overflow the I'm a bit curious to know if maybe the issue you had seen was actually due to a print statement that was incorrectly casting a If you feel that the fix in #81 is inadequate please feel free to open another PR, thanks! |
LGTM. I'm pretty sure there was a disconnect between the size of fields in the va_args vs. the formatter reading the format specifier that caused our issue. This should be a plenty sufficient fix. Thanks! |
In the code below, the log format specifier explicitly expects a type of
%lu
when printing the seconds delta:https://github.com/FreeRTOS/coreSNTP/blob/3cb8ad937f70516cb9f08a7d622cfa9195736d3b/source/core_sntp_client.c#L795C1-L798C63
This can cause unexpected formatting function behavior depending on the platform. In our case, it printed out wildly large numbers; this will be different for every implementation of the formatter.
One potential solution would be to use
inttypes.h
or simply to use%llu
. However, for many embedded builds of the standard library, proper support of%llu
is spotty, so this may simply be a lost cause. Perhaps a conversion touint32_t
would be more suitable instead?The text was updated successfully, but these errors were encountered: