summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSalvatore Sanfilippo <antirez@gmail.com>2017-11-24 08:59:23 +0100
committerGitHub <noreply@github.com>2017-11-24 08:59:23 +0100
commit58ac57f6651c1b3c8223cf04fe86a2c51aef1bc7 (patch)
treedba346e4f96a1ab5fcf60fe3535f2e664d15729a
parentde914ede9385c2886770ac462564be1a659b56aa (diff)
parentadf2701cc95085a4a9980da7b7367b1836c5a0f2 (diff)
downloadredis-58ac57f6651c1b3c8223cf04fe86a2c51aef1bc7.tar.gz
Merge pull request #4470 from oranagra/fix_string_to_double
fix string to double conversion, stopped parsing on \0 …
-rw-r--r--src/object.c4
-rw-r--r--tests/unit/type/incr.tcl7
2 files changed, 9 insertions, 2 deletions
diff --git a/src/object.c b/src/object.c
index d2db7963e..0950837c8 100644
--- a/src/object.c
+++ b/src/object.c
@@ -560,7 +560,7 @@ int getDoubleFromObject(const robj *o, double *target) {
value = strtod(o->ptr, &eptr);
if (sdslen(o->ptr) == 0 ||
isspace(((const char*)o->ptr)[0]) ||
- eptr[0] != '\0' ||
+ (size_t)(eptr-(char*)o->ptr) != sdslen(o->ptr) ||
(errno == ERANGE &&
(value == HUGE_VAL || value == -HUGE_VAL || value == 0)) ||
isnan(value))
@@ -602,7 +602,7 @@ int getLongDoubleFromObject(robj *o, long double *target) {
value = strtold(o->ptr, &eptr);
if (sdslen(o->ptr) == 0 ||
isspace(((const char*)o->ptr)[0]) ||
- eptr[0] != '\0' ||
+ (size_t)(eptr-(char*)o->ptr) != sdslen(o->ptr) ||
(errno == ERANGE &&
(value == HUGE_VAL || value == -HUGE_VAL || value == 0)) ||
isnan(value))
diff --git a/tests/unit/type/incr.tcl b/tests/unit/type/incr.tcl
index 2287aaae2..a58710d39 100644
--- a/tests/unit/type/incr.tcl
+++ b/tests/unit/type/incr.tcl
@@ -144,4 +144,11 @@ start_server {tags {"incr"}} {
r set foo 1
roundFloat [r incrbyfloat foo -1.1]
} {-0.1}
+
+ test {string to double with null terminator} {
+ r set foo 1
+ r setrange foo 2 2
+ catch {r incrbyfloat foo 1} err
+ format $err
+ } {ERR*valid*}
}