Skip to content

Commit

Permalink
getLongLongFromObject: use string2ll() instead of strict_strtoll().
Browse files Browse the repository at this point in the history
strict_strtoll() has a bug that reports the empty string as ok and
parses it as zero.

Apparently nobody ever replaced this old call with the faster/saner
string2ll() which is used otherwise in the rest of the Redis core.

This commit close redis#3333.
  • Loading branch information
antirez committed Jul 6, 2016
1 parent ef6a4df commit 2379182
Showing 1 changed file with 1 addition and 15 deletions.
16 changes: 1 addition & 15 deletions src/object.c
Expand Up @@ -619,20 +619,6 @@ int getLongDoubleFromObjectOrReply(client *c, robj *o, long double *target, cons
return C_OK;
}

/* Helper function for getLongLongFromObject(). The function parses the string
* as a long long value in a strict way (no spaces before/after). On success
* C_OK is returned, otherwise C_ERR is returned. */
int strict_strtoll(char *str, long long *vp) {
char *eptr;
long long value;

errno = 0;
value = strtoll(str, &eptr, 10);
if (isspace(str[0]) || eptr[0] != '\0' || errno == ERANGE) return C_ERR;
if (vp) *vp = value;
return C_OK;
}

int getLongLongFromObject(robj *o, long long *target) {
long long value;

Expand All @@ -641,7 +627,7 @@ int getLongLongFromObject(robj *o, long long *target) {
} else {
serverAssertWithInfo(NULL,o,o->type == OBJ_STRING);
if (sdsEncodedObject(o)) {
if (strict_strtoll(o->ptr,&value) == C_ERR) return C_ERR;
if (string2ll(o->ptr,sdslen(o->ptr),&value) == 0) return C_ERR;
} else if (o->encoding == OBJ_ENCODING_INT) {
value = (long)o->ptr;
} else {
Expand Down

0 comments on commit 2379182

Please sign in to comment.