summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorantirez <antirez@gmail.com>2016-07-06 11:43:33 +0200
committerantirez <antirez@gmail.com>2016-07-06 11:43:33 +0200
commit23791828f1cd54ebea95d8c860058e55ff28aebf (patch)
tree6580ebe3b803c06273f10075d323e2c065776446
parentef6a4df29c17e3c79a1e9b328fe3e2d1f2a9df39 (diff)
downloadredis-23791828f1cd54ebea95d8c860058e55ff28aebf.tar.gz
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.
-rw-r--r--src/object.c16
1 files changed, 1 insertions, 15 deletions
diff --git a/src/object.c b/src/object.c
index 447e5fc30..ad29c1bd2 100644
--- a/src/object.c
+++ b/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 {