gettime: fix cycles_per_msec overflow when using 32 bit longs
authorSitsofe Wheeler <sitsofe@yahoo.com>
Thu, 12 Oct 2017 16:09:48 +0000 (17:09 +0100)
committerSitsofe Wheeler <sitsofe@yahoo.com>
Thu, 12 Oct 2017 16:22:57 +0000 (17:22 +0100)
Compiling fio with clang's undefined behaviour sanitizer and unsigned
wraparound detection enabled on a 32 bit Linux build turned up the
following:

gettime.c:313:28: runtime error: unsigned integer overflow: 3600 * 2600730 cannot be represented in type 'unsigned long'

Fix this by making cycles_per_msec a long long.

Signed-off-by: Sitsofe Wheeler <sitsofe@yahoo.com>
gettime.c

index 79455284a30d715b819a779bf3e7943c602eb549..1cbef84b0d765f224309214067fa92f1048c7fed 100644 (file)
--- a/gettime.c
+++ b/gettime.c
@@ -15,7 +15,7 @@
 
 #if defined(ARCH_HAVE_CPU_CLOCK)
 #ifndef ARCH_CPU_CLOCK_CYCLES_PER_USEC
 
 #if defined(ARCH_HAVE_CPU_CLOCK)
 #ifndef ARCH_CPU_CLOCK_CYCLES_PER_USEC
-static unsigned long cycles_per_msec;
+static unsigned long long cycles_per_msec;
 static unsigned long long cycles_start;
 static unsigned long long clock_mult;
 static unsigned long long max_cycles_mask;
 static unsigned long long cycles_start;
 static unsigned long long clock_mult;
 static unsigned long long max_cycles_mask;