Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/videolan/dav1d.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/tools
diff options
context:
space:
mode:
authorMartin Storsjö <martin@martin.st>2020-06-18 13:00:20 +0300
committerJean-Baptiste Kempf <jb@videolan.org>2020-06-18 16:05:01 +0300
commit7949de70e00a1cac0229f2cfcc7413cb29f43e4e (patch)
treed29dec4bf24fb5dec6798dbf2a1f2178db799225 /tools
parent3e643b1faa2854a7b685ae28b3f58166e872a3a4 (diff)
cli: Avoid large intermediates in the windows get_time_nanos
By multiplicating the performance counter value (within its own time base) by the intended target time base, and only then dividing, we reduce the available numeric range by the factor of the original time base times the new time base. On Windows 10 on ARM64, the performance counter frequency is 19200000 (on x86_64 in a virtual machine, it's 10000000), making the calculation overflow every (1 << 64) / (19200000 * 1000000000) = 960 seconds, i.e. 16 minutes - long before the actual uint64_t nanosecond return value wraps around.
Diffstat (limited to 'tools')
-rw-r--r--tools/dav1d.c4
1 files changed, 3 insertions, 1 deletions
diff --git a/tools/dav1d.c b/tools/dav1d.c
index 129375a..4b97a9f 100644
--- a/tools/dav1d.c
+++ b/tools/dav1d.c
@@ -63,7 +63,9 @@ static uint64_t get_time_nanos(void) {
QueryPerformanceFrequency(&frequency);
LARGE_INTEGER t;
QueryPerformanceCounter(&t);
- return 1000000000 * t.QuadPart / frequency.QuadPart;
+ uint64_t seconds = t.QuadPart / frequency.QuadPart;
+ uint64_t fractions = t.QuadPart % frequency.QuadPart;
+ return 1000000000 * seconds + 1000000000 * fractions / frequency.QuadPart;
#elif defined(HAVE_CLOCK_GETTIME)
struct timespec ts;
clock_gettime(CLOCK_MONOTONIC, &ts);