Skip to content
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

Fix size_t and time_t format specifiers #114

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

micmac1
Copy link

@micmac1 micmac1 commented Nov 12, 2021

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]

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]>
@micmac1 micmac1 requested a review from a team November 12, 2021 21:01
@mjerris
Copy link
Contributor

mjerris commented Nov 12, 2021

These format specifiers actually differ by platform. what os/arch are you targeting where you have issues here?

@micmac1
Copy link
Author

micmac1 commented Nov 12, 2021

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 signalwire/freeswitch#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.

@mrtrev
Copy link
Contributor

mrtrev commented Dec 3, 2021

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.

@andywolk
Copy link
Contributor

Shouldn't we have %zu in all the places without a cast?

@micmac1
Copy link
Author

micmac1 commented Dec 22, 2021 via email

@mrtrev
Copy link
Contributor

mrtrev commented Dec 6, 2022

Voting again that this be merged. Doesn't seem like anyone has had an objection in a year now.

@andywolk
Copy link
Contributor

Why do you cast variables?

@micmac1
Copy link
Author

micmac1 commented Dec 20, 2022 via email

@andywolk
Copy link
Contributor

Is there a way to fix the issue without casting?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants