]> git.saurik.com Git - redis.git/blobdiff - redis.c
fix unexpected behavior on an out of range end index for LRANGE and LTRIM
[redis.git] / redis.c
diff --git a/redis.c b/redis.c
index 6ac410d0e523f8d16be9bc4e1b84320c1dd78d9a..085d35532a8f4bc1ed3dec83a9829b8fdb072b99 100644 (file)
--- a/redis.c
+++ b/redis.c
@@ -5404,9 +5404,9 @@ static void lrangeCommand(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) {
         /* Out of range start or start > end result in empty list */
         addReply(c,shared.emptymultibulk);
@@ -5444,9 +5444,9 @@ static void ltrimCommand(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) {
         /* Out of range start or start > end result in empty list */
         ltrim = llen;