From: Amos Jeffries Date: Mon, 22 May 2023 04:30:00 +0000 (+0000) Subject: Fix time_t type conflicts in libdebug (#1357) X-Git-Tag: SQUID_6_0_3~4 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=d14b10e14ab155c272d27e2847d6ca914f1cfa8e;p=thirdparty%2Fsquid.git Fix time_t type conflicts in libdebug (#1357) error: cannot convert 'const long int*' to 'const time_t*' On Windows, time_t is 64-bit, and long is not. --- diff --git a/src/debug/debug.cc b/src/debug/debug.cc index d97de8dafd..1a1cf92120 100644 --- a/src/debug/debug.cc +++ b/src/debug/debug.cc @@ -1227,10 +1227,11 @@ debugLogTime(const timeval &t) static time_t last_t = 0; if (Debug::Level() > 1) { + last_t = t.tv_sec; // 4 bytes smaller than buf to ensure .NNN catenation by snprintf() // is safe and works even if strftime() fills its buffer. char buf2[sizeof(buf)-4]; - const auto tm = localtime(&t.tv_sec); + const auto tm = localtime(&last_t); strftime(buf2, sizeof(buf2), "%Y/%m/%d %H:%M:%S", tm); buf2[sizeof(buf2)-1] = '\0'; const auto sz = snprintf(buf, sizeof(buf), "%s.%03d", buf2, static_cast(t.tv_usec / 1000)); @@ -1238,10 +1239,10 @@ debugLogTime(const timeval &t) // force buf reset for subsequent level-0/1 messages that should have no milliseconds last_t = 0; } else if (t.tv_sec != last_t) { - const auto tm = localtime(&t.tv_sec); + last_t = t.tv_sec; + const auto tm = localtime(&last_t); const int sz = strftime(buf, sizeof(buf), "%Y/%m/%d %H:%M:%S", tm); assert(0 < sz && sz <= static_cast(sizeof(buf))); - last_t = t.tv_sec; } buf[sizeof(buf)-1] = '\0';