From 2f282aee0b8e500697b627254b170f21d93dd4a8 Mon Sep 17 00:00:00 2001 From: antirez Date: Wed, 1 Aug 2018 19:01:40 +0200 Subject: [PATCH] Fix zslUpdateScore() edge case. When the element new score is the same of prev/next node, the lexicographical order kicks in, so we can safely update the node in place only when the new score is strictly between the adjacent nodes but never equal to one of them. Technically speaking we could do extra checks to make sure that even if the score is the same as one of the adjacent nodes, we can still update on place, but this rarely happens, so probably not a good deal to make it more complex. Related to #5179. --- src/t_zset.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/t_zset.c b/src/t_zset.c index a794b44c..db381b59 100644 --- a/src/t_zset.c +++ b/src/t_zset.c @@ -281,8 +281,8 @@ zskiplistNode *zslUpdateScore(zskiplist *zsl, double curscore, sds ele, double n /* If the node, after the score update, would be still exactly * at the same position, we can just update the score without * actually removing and re-inserting the element in the skiplist. */ - if ((x->backward == NULL || x->backward->score <= newscore) && - (x->level[0].forward == NULL || x->level[0].forward->score >= newscore)) + if ((x->backward == NULL || x->backward->score < newscore) && + (x->level[0].forward == NULL || x->level[0].forward->score > newscore)) { x->score = newscore; return x;