getLongLongFromObject: use string2ll() instead of strict_strtoll().
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 #3333.
This commit is contained in:
parent
ef6a4df29c
commit
23791828f1
16
src/object.c
16
src/object.c
@ -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;
|
||||
|
||||
@ -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 {
|
||||
|
Loading…
x
Reference in New Issue
Block a user