stat: increase the size of base to avoid overflow
authorRichard Liu <liuhanche@pku.edu.cn>
Wed, 23 Aug 2017 10:49:58 +0000 (18:49 +0800)
committerRichard Liu <liuhanche@pku.edu.cn>
Wed, 23 Aug 2017 10:49:58 +0000 (18:49 +0800)
commitc8b44cfacd6c5c782bc049f6db5797ed5088aa4d
tree0c0f7911e0468dcacf412b7eb2883e26a9c3c6cd
parentdeeb3c11c212e99e8d1162e03e0ef734bd0d01a7
stat: increase the size of base to avoid overflow

plat_idx_to_val() in stat.c has a variable base that is defined as an
unsigned int but it was designed to fit old settings where
FIO_IO_U_PLAT_GROUP_NR = 19.
With the alteration from usec to nsec in commit
d6bb626ef37d3905221ade2887b422717a07af09(nanosecond: update completion
latency recording and normal, json output to use nanoseconds)
FIO_IO_U_PLAT_GROUP_NR is now 29 and the range of latency changed from
uint32_t to uint64_t. This means in plat_idx_to_val(), variable base
can easily exceed a 32-bit range and overflow after error_bits reaches 26.

Eg.
Group MSB #discarded range of #buckets
error_bits value
27 32 26 [42949672968589934591]     64
base = 1 << (error_bits + FIO_IO_U_PLAT_BITS);
(1 << 32) will overflow
if change to:
base = ((unsigned long long) 1) << (error_bits + FIO_IO_U_PLAT_BITS);
base itself will still overflow
so base should be unsigned long long
stat.c