]> git.ipfire.org Git - thirdparty/squid.git/commitdiff
Fix time_t type conflicts in libdebug (#1357)
authorAmos Jeffries <yadij@users.noreply.github.com>
Mon, 22 May 2023 04:30:00 +0000 (04:30 +0000)
committerSquid Anubis <squid-anubis@squid-cache.org>
Mon, 22 May 2023 11:31:04 +0000 (11:31 +0000)
    error: cannot convert 'const long int*' to 'const time_t*'

On Windows, time_t is 64-bit, and long is not.

src/debug/debug.cc

index d58c64cf6df6c170ec11e92b426a58355aeffef8..47d3a0345aa89f63e54b204cc23132bc56728069 100644 (file)
@@ -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<int>(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<int>(sizeof(buf)));
-        last_t = t.tv_sec;
     }
 
     buf[sizeof(buf)-1] = '\0';