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
14ee3418e5
commit
d1f5aa7f87
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;
|
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) {
|
int getLongLongFromObject(robj *o, long long *target) {
|
||||||
long long value;
|
long long value;
|
||||||
|
|
||||||
@ -641,7 +627,7 @@ int getLongLongFromObject(robj *o, long long *target) {
|
|||||||
} else {
|
} else {
|
||||||
serverAssertWithInfo(NULL,o,o->type == OBJ_STRING);
|
serverAssertWithInfo(NULL,o,o->type == OBJ_STRING);
|
||||||
if (sdsEncodedObject(o)) {
|
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) {
|
} else if (o->encoding == OBJ_ENCODING_INT) {
|
||||||
value = (long)o->ptr;
|
value = (long)o->ptr;
|
||||||
} else {
|
} else {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user