]> git.saurik.com Git - redis.git/commitdiff
SUBSTR fix for integer encoded vals
authorantirez <antirez@gmail.com>
Thu, 4 Mar 2010 12:10:50 +0000 (13:10 +0100)
committerantirez <antirez@gmail.com>
Thu, 4 Mar 2010 12:10:50 +0000 (13:10 +0100)
redis.c

diff --git a/redis.c b/redis.c
index 6ad439b0c73fa179f227bdef1f6e05cb83f067c5..a0beff284e13e86c9133d44efbb49d511d738253 100644 (file)
--- a/redis.c
+++ b/redis.c
@@ -3778,9 +3778,12 @@ static void substrCommand(redisClient *c) {
         if (o->type != REDIS_STRING) {
             addReply(c,shared.wrongtypeerr);
         } else {
         if (o->type != REDIS_STRING) {
             addReply(c,shared.wrongtypeerr);
         } else {
-            size_t rangelen, strlen = sdslen(o->ptr);
+            size_t rangelen, strlen;
             sds range;
 
             sds range;
 
+            o = getDecodedObject(o);
+            strlen = sdslen(o->ptr);
+
             /* convert negative indexes */
             if (start < 0) start = strlen+start;
             if (end < 0) end = strlen+end;
             /* convert negative indexes */
             if (start < 0) start = strlen+start;
             if (end < 0) end = strlen+end;
@@ -3791,6 +3794,7 @@ static void substrCommand(redisClient *c) {
             if (start > end || (size_t)start >= strlen) {
                 /* Out of range start or start > end result in null reply */
                 addReply(c,shared.nullbulk);
             if (start > end || (size_t)start >= strlen) {
                 /* Out of range start or start > end result in null reply */
                 addReply(c,shared.nullbulk);
+                decrRefCount(o);
                 return;
             }
             if ((size_t)end >= strlen) end = strlen-1;
                 return;
             }
             if ((size_t)end >= strlen) end = strlen-1;
@@ -3801,6 +3805,7 @@ static void substrCommand(redisClient *c) {
             range = sdsnewlen((char*)o->ptr+start,rangelen);
             addReplySds(c,range);
             addReply(c,shared.crlf);
             range = sdsnewlen((char*)o->ptr+start,rangelen);
             addReplySds(c,range);
             addReply(c,shared.crlf);
+            decrRefCount(o);
         }
     }
 }
         }
     }
 }