summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCarlo Marcelo Arenas Belón <carenas@gmail.com>2021-07-24 11:54:30 -0700
committerDaniel Stenberg <daniel@haxx.se>2021-07-26 00:55:17 +0200
commit4b79c4fb565ab521eb943034918d92dd7fa7db75 (patch)
treeebb64e7e6af86f44c59040b622f893eb5c69573f
parent4a7bf79fcc2c7d0414d7d0a2bdc8fe4f1265739b (diff)
downloadcurl-4b79c4fb565ab521eb943034918d92dd7fa7db75.tar.gz
examples/cookie_interface: avoid printfing time_t directly
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. Closes #7490
-rw-r--r--docs/examples/cookie_interface.c4
1 files changed, 2 insertions, 2 deletions
diff --git a/docs/examples/cookie_interface.c b/docs/examples/cookie_interface.c
index 42cbe4649..fb2b9fb7c 100644
--- a/docs/examples/cookie_interface.c
+++ b/docs/examples/cookie_interface.c
@@ -93,9 +93,9 @@ main(void)
#define snprintf _snprintf
#endif
/* Netscape format cookie */
- snprintf(nline, sizeof(nline), "%s\t%s\t%s\t%s\t%lu\t%s\t%s",
+ snprintf(nline, sizeof(nline), "%s\t%s\t%s\t%s\t%.0lf\t%s\t%s",
".example.com", "TRUE", "/", "FALSE",
- (unsigned long)time(NULL) + 31337UL,
+ difftime(time(NULL) + 31337, (time_t)0),
"PREF", "hello example, i like you very much!");
res = curl_easy_setopt(curl, CURLOPT_COOKIELIST, nline);
if(res != CURLE_OK) {