From 86cd4629ae5b78eaeecbfed44311a06d7e32fade Mon Sep 17 00:00:00 2001 From: Wen Hui Date: Thu, 20 Aug 2020 17:14:09 -0400 Subject: [PATCH] use dictSlots for getting total slots number in dict (#7691) --- src/dict.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/dict.c b/src/dict.c index a26ef18d3..39af94707 100644 --- a/src/dict.c +++ b/src/dict.c @@ -621,9 +621,7 @@ dictEntry *dictGetRandomKey(dict *d) do { /* We are sure there are no elements in indexes from 0 * to rehashidx-1 */ - h = d->rehashidx + (random() % (d->ht[0].size + - d->ht[1].size - - d->rehashidx)); + h = d->rehashidx + (random() % (dictSlots(d) - d->rehashidx)); he = (h >= d->ht[0].size) ? d->ht[1].table[h - d->ht[0].size] : d->ht[0].table[h]; } while(he == NULL);