]> git.saurik.com Git - redis.git/blobdiff - redis.c
fix behavior for out-of-range negative end index on ZREMRANGEBYRANK
[redis.git] / redis.c
diff --git a/redis.c b/redis.c
index f6a765dad4299c86900449b8c78f1864fd806198..6ac410d0e523f8d16be9bc4e1b84320c1dd78d9a 100644 (file)
--- a/redis.c
+++ b/redis.c
@@ -6409,9 +6409,9 @@ static void zremrangebyrankCommand(redisClient *c) {
     if (start < 0) start = llen+start;
     if (end < 0) end = llen+end;
     if (start < 0) start = 0;
-    if (end < 0) end = 0;
 
-    /* indexes sanity checks */
+    /* Invariant: start >= 0, so this test will be true when end < 0.
+     * The range is empty when start > end or start >= length. */
     if (start > end || start >= llen) {
         addReply(c,shared.czero);
         return;
@@ -6662,11 +6662,10 @@ static void zrangeGenericCommand(redisClient *c, int reverse) {
     if (start < 0) start = llen+start;
     if (end < 0) end = llen+end;
     if (start < 0) start = 0;
-    if (end < 0) end = 0;
 
-    /* indexes sanity checks */
+    /* Invariant: start >= 0, so this test will be true when end < 0.
+     * The range is empty when start > end or start >= length. */
     if (start > end || start >= llen) {
-        /* Out of range start or start > end result in empty list */
         addReply(c,shared.emptymultibulk);
         return;
     }