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

cookie_interface: avoid printing time_t directly #7490

Closed
wants to merge 1 commit into from

Conversation

@carenas
Copy link
Contributor

@carenas carenas commented Jul 24, 2021

time_t representation is undefined and varies on bitsize and signedness,
and as of C11 could be even non integer.

instead of casting to unsigned long (which would truncate in systems with
a 32bit long after 2106) use difftime to get the elapsed time as a double
and print that (without decimals) instead.

alternatively a cast to curl_off_t and its corresponding print formatting
could have been used (at least in POSIX) but portability and curl agnostic
code was prioritized.

time_t representation is undefined and varies on bitsize and signedness,
and as of C11 could be even non integer.

instead of casting to unsigned long (which would truncate in systems with
a 32bit long after 2106) use difftime to get the elapsed time as a double
and print that (without decimals) instead.

alternatively a cast to curl_off_t and its corresponding print formatting
could have been used (at least in POSIX) but portability and curl agnostic
code was prioritized.
bagder
bagder approved these changes Jul 25, 2021
@bagder
Copy link
Member

@bagder bagder commented Jul 25, 2021

Thanks!

@bagder bagder closed this in 4b79c4f Jul 25, 2021
@carenas carenas deleted the y2k38 branch Jul 26, 2021
@bagder
Copy link
Member

@bagder bagder commented Jul 26, 2021

Unfortunately, this caused scan-build to yell:

cookie_interface.c: In function ‘main’:
cookie_interface.c:96:53: error: ‘%.0lf’ directive output may be truncated writing between 1 and 310 bytes into a region of size 230 [-Werror=format-truncation=]
     snprintf(nline, sizeof(nline), "%s\t%s\t%s\t%s\t%.0lf\t%s\t%s",
                                                     ^~~~~
cookie_interface.c:96:5: note: ‘snprintf’ output between 70 and 379 bytes into a destination of size 256
     snprintf(nline, sizeof(nline), "%s\t%s\t%s\t%s\t%.0lf\t%s\t%s",
     ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
              ".example.com", "TRUE", "/", "FALSE",
              ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
              difftime(time(NULL) + 31337, (time_t)0),
              ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
              "PREF", "hello example, i like you very much!");
              ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
cc1: all warnings being treated as errors

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

Successfully merging this pull request may close these issues.

None yet

2 participants