From: Aki Tuomi Date: Wed, 23 Aug 2017 10:42:09 +0000 (+0300) Subject: lib: Simplify timing_add_usecs X-Git-Tag: 2.3.0.rc1~1078 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=21f76ca1a50182b44f45aee8ae854f06a15264a0;p=thirdparty%2Fdovecot%2Fcore.git lib: Simplify timing_add_usecs i_rand is guaranteed to return 32 bit integer --- diff --git a/src/lib/timing.c b/src/lib/timing.c index 960db8492e..8b80ab2906 100644 --- a/src/lib/timing.c +++ b/src/lib/timing.c @@ -39,12 +39,7 @@ void timing_add_usecs(struct timing *timing, uint64_t usecs) if (timing->count == 0) timing->min = timing->max = usecs; } else { - unsigned int count = timing->count; - unsigned int idx; - if (count > RAND_MAX >> 6) - idx = (i_rand()*((uint64_t)RAND_MAX+1) + i_rand()) % count; - else - idx = i_rand() % count; + unsigned int idx = i_rand() % timing->count; if (idx < TIMING_SUBSAMPLING_BUFFER) timing->samples[idx] = usecs; }