]> 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)
committerAmos Jeffries <yadij@users.noreply.github.com>
Tue, 23 May 2023 04:53:00 +0000 (16:53 +1200)
    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 d97de8dafdc082318c408837cae301382f11eb88..1a1cf9212045aa65f0896ee1020873f531cc3ff5 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';