Describe the bug ` zskiplistNode zslInsert(zskiplist zsl, double score, sds ele) {
zskiplistNode update[ZSKIPLIST_MAXLEVEL], x;
unsigned int rank[ZSKIPLIST_MAXLEVEL];
`
A short description of the bug.
To reproduce
Steps to reproduce the behavior and/or a minimal code sample.
Expected behavior ` zskiplistNode zslInsert(zskiplist zsl, double score, sds ele) {
//---------------------------impovement-------------------------------------------
int level = zslRandomLevel(); // 1st obtains new level value
int max = max(level, zsl->level);
zskiplistNode *update[max]; // low probability to reach ZSKIPLIST_MAXLEVEL
//------------------------------------bug fix--------------------------------------------------------------
// from server.h
// unsigned long length; unsigned long span;
// #define ZSKIPLIST_MAXLEVEL 32 / Should be enough for 2^64 elements /
// #define ZSKIPLIST_P 0.25 / Skiplist P = 1/4 /
// if x will be inserted at the end of list, and length has been greater than max of unsigned int, overflow can occur.
unsigned long rank[max];// long not int
` A description of what you expected to happen.
Additional information
Any additional information that is relevant to the problem.
Comment From: oranagra
@galleChristian your text is really hard to follow. please try to clean it up (both formatting issues, and also maybe you can add more context or make it easier to follow).
if i understand correctly, you're complaining about two things:
1. the these two arrays of 64 elements are too big (we won't actually reach the high indexes. what number do you suggest? p.s. few more bytes on the stack won't cause any damage..
2. the type of the rank array needs to be unsigned long rather than unsigned int. since it would overflow if the skiplist has more than 2G elements.
is that right? do you wanna open a pull request?
Comment From: yangbodong22011
- the these two arrays of 64 elements are too big (we won't actually reach the high indexes. what number do you suggest? p.s. few more bytes on the stack won't cause any damage..
hello, @galleChristian about update[ZSKIPLIST_MAXLEVEL] to update[max(zslRandomLevel(), zsl->level)], i agree with @oranagra , it just sizeof(zskiplistNode *) * ZSKIPLIST_MAXLEVEL = 8 * 32 = 256 bytes, it doesn't matter.
About unsigned int rank[ZSKIPLIST_MAXLEVEL] to unsigned long rank[ZSKIPLIST_MAXLEVEL], i agree, you can open a PR to solve it.
Comment From: yangbodong22011
Closed for https://github.com/redis/redis/pull/9249