diff options
author | Oran Agra <oran@redislabs.com> | 2022-04-05 14:25:02 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-04-05 14:25:02 +0300 |
commit | fb4e0d400ff82117104bde5296c477ad95f8dd41 (patch) | |
tree | 4ede2d02b134a84ff29bb7398902c398cd4ff454 /src/t_zset.c | |
parent | d2b5a579dd8b785690aa7714df8776ffc452d242 (diff) | |
parent | 8b242ef977b88d6cae38d451130a88116bcbb638 (diff) | |
download | redis-7.0-rc3.tar.gz |
Merge pull request #10532 from oranagra/7.0-rc37.0-rc3
Release 7.0 rc3
Diffstat (limited to 'src/t_zset.c')
-rw-r--r-- | src/t_zset.c | 9 |
1 files changed, 5 insertions, 4 deletions
diff --git a/src/t_zset.c b/src/t_zset.c index bc947c965..77ca7c83a 100644 --- a/src/t_zset.c +++ b/src/t_zset.c @@ -120,8 +120,9 @@ void zslFree(zskiplist *zsl) { * (both inclusive), with a powerlaw-alike distribution where higher * levels are less likely to be returned. */ int zslRandomLevel(void) { + static const int threshold = ZSKIPLIST_P*RAND_MAX; int level = 1; - while ((random()&0xFFFF) < (ZSKIPLIST_P * 0xFFFF)) + while (random() < threshold) level += 1; return (level<ZSKIPLIST_MAXLEVEL) ? level : ZSKIPLIST_MAXLEVEL; } @@ -720,8 +721,8 @@ zskiplistNode *zslLastInLexRange(zskiplist *zsl, zlexrangespec *range) { double zzlStrtod(unsigned char *vstr, unsigned int vlen) { char buf[128]; - if (vlen > sizeof(buf)) - vlen = sizeof(buf); + if (vlen > sizeof(buf) - 1) + vlen = sizeof(buf) - 1; memcpy(buf,vstr,vlen); buf[vlen] = '\0'; return strtod(buf,NULL); @@ -1026,7 +1027,7 @@ unsigned char *zzlDelete(unsigned char *zl, unsigned char *eptr) { unsigned char *zzlInsertAt(unsigned char *zl, unsigned char *eptr, sds ele, double score) { unsigned char *sptr; - char scorebuf[128]; + char scorebuf[MAX_D2STRING_CHARS]; int scorelen; scorelen = d2string(scorebuf,sizeof(scorebuf),score); |