【问题标题】:Redis zslGetElementByRank(t_zset.c) return error addressRedis zslGetElementByRank(t_zset.c) 返回错误地址
【发布时间】:2017-11-12 02:20:56
【问题描述】:

当我调试 Redis SkipList 时,我想使用 zslGetElementByRank(t_zset.c)。我把Redis的主要功能代码替换为:

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;
}

$ 制作
$ ./src/redis 服务器
[1] 29749 分段错误 ./src/redis-server // 我得到一个分段错误

然后,我调试代码,在 zslGetElementByRank 和 main 中打印地址,地址是:

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

为什么地址从0x7ffff6e25000变成0xfffffffff6e25000,我很困惑。

不好意思忘记了,我的Redis版本是4.0.1

谢谢!

【问题讨论】:

  • 我用 glibc malloc 重新编译代码: $ make MALLOC=libc $./src/redis-server 等级等于 4 是 :tony->95.000000 答案是正确的,但我没有原因。

标签: redis skip-lists


【解决方案1】:

我找到了答案,只是因为我没有在 server.c 中声明 zslGetElementByRank。
警告是:
assignment makes pointer from integer without a cast [enabled by default]

【讨论】:

    猜你喜欢
    • 2015-08-26
    • 2012-03-02
    • 2021-01-24
    • 1970-01-01
    • 2021-07-05
    • 2010-12-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多