From 6ad67c330f23e0d44ed4e2de926aeeffe93d1674 Mon Sep 17 00:00:00 2001 From: antirez Date: Wed, 6 Jul 2016 11:43:33 +0200 Subject: [PATCH] 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. --- src/object.c | 16 +--------------- 1 file changed, 1 insertion(+), 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 {