Search code examples
redisskip-lists

Redis zslGetElementByRank(t_zset.c) return error address


When i debugging Redis SkipList, I wanna use zslGetElementByRank(t_zset.c). I replaced Redis main function code as:

int main(int argc, char **argv) {

    zskiplistNode *node;

    zskiplist *zsl = zslCreate();           //create a skiplist

    zslInsert(zsl, 65.5, sdsnew("tom"));  //insert some data
    zslInsert(zsl, 87.5, sdsnew("jack"));
    zslInsert(zsl, 70.0, sdsnew("alice"));
    zslInsert(zsl, 95.0, sdsnew("tony"));

    printf("The Rank equal 4 is :");         
    node = zslGetElementByRank(zsl, 4);       //get element by rank
    printf("%s->%f\n", node->ele, node->score); 

    return 0;
}

$ make
$ ./src/redis-server
[1] 29749 segmentation fault ./src/redis-server // i get a segmentfault

then , i debug the code, i print the address in zslGetElementByRank and main , the address is:

(gdb) p x x is zslGetElementByRank returnd
$1 = (zskiplistNode *) 0x7ffff6e25000
(gdb) p node
$2 = (zskiplistNode *) 0xfffffffff6e25000

why the address changed from 0x7ffff6e25000 to 0xfffffffff6e25000, I am confused.

Sorry to forget it,My Redis Version is 4.0.1

Thanks!


Solution

  • I find the answer , just because i don't declare zslGetElementByRank in server.c .
    the warning is :
    assignment makes pointer from integer without a cast [enabled by default]