From 99ebbee2b260b3466672b4fa351cf1cb5e9b5fe9 Mon Sep 17 00:00:00 2001 From: Ozan Tezcan Date: Thu, 11 Aug 2022 15:28:16 +0300 Subject: [PATCH] Fix overflow in redis-benchmark (#11102) Fix overflow in redis-benchmark affecting latency measurements on 32bit builds. If `long` is 4 bytes (typical on 32 bit systems), multiplication overflows. Using `long long` will fix the issue as it is guaranteed to be at least 8 bytes. Also, I've added a change to reuse `ustime()` for `mstime()`. --- src/redis-benchmark.c | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/src/redis-benchmark.c b/src/redis-benchmark.c index d727c4b63..489a6b3a3 100644 --- a/src/redis-benchmark.c +++ b/src/redis-benchmark.c @@ -229,19 +229,13 @@ static long long ustime(void) { long long ust; gettimeofday(&tv, NULL); - ust = ((long)tv.tv_sec)*1000000; + ust = ((long long)tv.tv_sec)*1000000; ust += tv.tv_usec; return ust; } static long long mstime(void) { - struct timeval tv; - long long mst; - - gettimeofday(&tv, NULL); - mst = ((long long)tv.tv_sec)*1000; - mst += tv.tv_usec/1000; - return mst; + return ustime()/1000; } static uint64_t dictSdsHash(const void *key) {