summaryrefslogtreecommitdiff
path: root/src/object.c
diff options
context:
space:
mode:
authorantirez <antirez@gmail.com>2015-09-10 17:26:48 +0200
committerantirez <antirez@gmail.com>2015-10-01 13:02:24 +0200
commit1c247556c691bb61be65734be0670d50512f710c (patch)
treeee68a0d9c769f773e481e51f35e80b4477a6a093 /src/object.c
parentafc4b9241c37f37d1ca15be1ec3130c6a9c04a2a (diff)
downloadredis-1c247556c691bb61be65734be0670d50512f710c.tar.gz
Lazyfree: Hash converted to use plain SDS WIP 1.
Diffstat (limited to 'src/object.c')
-rw-r--r--src/object.c21
1 files changed, 15 insertions, 6 deletions
diff --git a/src/object.c b/src/object.c
index 3a9f60925..5d72abb8c 100644
--- a/src/object.c
+++ b/src/object.c
@@ -635,20 +635,29 @@ 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(o->ptr, &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;
- char *eptr;
if (o == NULL) {
value = 0;
} else {
serverAssertWithInfo(NULL,o,o->type == OBJ_STRING);
if (sdsEncodedObject(o)) {
- errno = 0;
- value = strtoll(o->ptr, &eptr, 10);
- if (isspace(((char*)o->ptr)[0]) || eptr[0] != '\0' ||
- errno == ERANGE)
- return C_ERR;
+ if (strict_strtoll(o->ptr,&value) == C_ERR) return C_ERR;
} else if (o->encoding == OBJ_ENCODING_INT) {
value = (long)o->ptr;
} else {