summaryrefslogtreecommitdiff
path: root/src/t_zset.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/t_zset.c')
-rw-r--r--src/t_zset.c9
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);