Skip to content

Commit 7f0519d

Browse files
authored
Merge pull request #4346 from Cyan4973/wintime
fix a risk of overflow on a time counter on Windows
2 parents 23e8812 + 33f4d40 commit 7f0519d

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

programs/timefn.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,18 +28,20 @@
2828
UTIL_time_t UTIL_getTime(void)
2929
{
3030
static LARGE_INTEGER ticksPerSecond;
31+
static double nsFactor = 1.0;
3132
static int init = 0;
3233
if (!init) {
3334
if (!QueryPerformanceFrequency(&ticksPerSecond)) {
3435
perror("timefn::QueryPerformanceFrequency");
3536
abort();
3637
}
38+
nsFactor = 1000000000.0 / (double)ticksPerSecond.QuadPart;
3739
init = 1;
3840
}
3941
{ UTIL_time_t r;
4042
LARGE_INTEGER x;
4143
QueryPerformanceCounter(&x);
42-
r.t = (PTime)(x.QuadPart * 1000000000ULL / ticksPerSecond.QuadPart);
44+
r.t = (PTime)((double)x.QuadPart * nsFactor);
4345
return r;
4446
}
4547
}

0 commit comments

Comments
 (0)