SUBSTR fix for integer encoded vals

This commit is contained in:
antirez 2010-03-04 13:10:50 +01:00
parent 67cac14343
commit 8fe7fad771

View File

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