1
0
mirror of https://github.com/facebook/zstd.git synced 2025-07-29 11:21:22 +03:00

Merge pull request #4346 from Cyan4973/wintime

fix a risk of overflow on a time counter on Windows
This commit is contained in:
Yann Collet
2025-03-27 21:07:57 -07:00
committed by GitHub

View File

@ -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;
}
}