From 4b79c4fb565ab521eb943034918d92dd7fa7db75 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Carlo=20Marcelo=20Arenas=20Bel=C3=B3n?= Date: Sat, 24 Jul 2021 11:54:30 -0700 Subject: [PATCH] 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 --- docs/examples/cookie_interface.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/examples/cookie_interface.c b/docs/examples/cookie_interface.c index 42cbe4649f..fb2b9fb7ce 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) { -- 2.47.2