Skip to content

Commit

Permalink
Fix time_t type conflicts in libdebug (#1357)
Browse files Browse the repository at this point in the history
    error: cannot convert 'const long int*' to 'const time_t*'

On Windows, time_t is 64-bit, and long is not.
  • Loading branch information
yadij authored and squid-anubis committed May 22, 2023
1 parent c6aa169 commit 1520f3a
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions src/debug/debug.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1227,21 +1227,22 @@ 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));
assert(0 < sz && sz < static_cast<int>(sizeof(buf)));
// 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';
Expand Down

0 comments on commit 1520f3a

Please sign in to comment.