mirror of
https://github.com/znc/znc.git
synced 2026-03-28 17:42:41 +01:00
Fix inverted gettimeofday() return value handling
The gettimeofday function returns 0 for success, not for failure. As a result of the inverted logic we were losing millisecond precision when parsing incoming messages on non-HAVE_CLOCK_GETTIME systems (macOS).
This commit is contained in:
@@ -96,11 +96,14 @@ TEST(UtilsTest, ServerTime) {
|
||||
EXPECT_EQ("2011-10-19T16:40:51.620Z", str1);
|
||||
|
||||
timeval now;
|
||||
if (!gettimeofday(&now, nullptr)) {
|
||||
if (gettimeofday(&now, nullptr)) {
|
||||
now.tv_sec = time(nullptr);
|
||||
now.tv_usec = 0;
|
||||
}
|
||||
|
||||
// Strip microseconds, server time is ms only
|
||||
now.tv_usec = (now.tv_usec / 1000) * 1000;
|
||||
|
||||
CString str2 = CUtils::FormatServerTime(now);
|
||||
timeval tv2 = CUtils::ParseServerTime(str2);
|
||||
EXPECT_EQ(now.tv_sec, tv2.tv_sec);
|
||||
|
||||
Reference in New Issue
Block a user