From: Yann Collet Date: Sun, 23 Mar 2025 18:42:41 +0000 (-0700) Subject: fix a risk of overflow on a time counter on Windows X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=refs%2Fpull%2F4346%2Fhead;p=thirdparty%2Fzstd.git fix a risk of overflow on a time counter on Windows closes #4126 --- diff --git a/programs/timefn.c b/programs/timefn.c index 4f045226b..d7f330974 100644 --- a/programs/timefn.c +++ b/programs/timefn.c @@ -28,18 +28,20 @@ UTIL_time_t UTIL_getTime(void) { static LARGE_INTEGER ticksPerSecond; + static double nsFactor = 1.0; static int init = 0; if (!init) { if (!QueryPerformanceFrequency(&ticksPerSecond)) { perror("timefn::QueryPerformanceFrequency"); abort(); } + nsFactor = 1000000000.0 / (double)ticksPerSecond.QuadPart; init = 1; } { UTIL_time_t r; LARGE_INTEGER x; QueryPerformanceCounter(&x); - r.t = (PTime)(x.QuadPart * 1000000000ULL / ticksPerSecond.QuadPart); + r.t = (PTime)((double)x.QuadPart * nsFactor); return r; } }