From 8beec4f0e78cebce9cd14d72fa4a622538b7c045 Mon Sep 17 00:00:00 2001 From: Guy Benoish Date: Tue, 5 Nov 2019 19:23:37 +0530 Subject: Make sure Redis does not reply with negative zero --- src/util.c | 4 ++++ tests/unit/type/incr.tcl | 6 ++++++ 2 files changed, 10 insertions(+) diff --git a/src/util.c b/src/util.c index 062a572d4..80b5a2453 100644 --- a/src/util.c +++ b/src/util.c @@ -560,6 +560,10 @@ int ld2string(char *buf, size_t len, long double value, ld2string_mode mode) { } if (*p == '.') l--; } + if (l == 2 && buf[0] == '-' && buf[1] == '0') { + buf[0] = '0'; + l = 1; + } break; default: return 0; /* Invalid mode. */ } diff --git a/tests/unit/type/incr.tcl b/tests/unit/type/incr.tcl index a58710d39..63bf2e116 100644 --- a/tests/unit/type/incr.tcl +++ b/tests/unit/type/incr.tcl @@ -151,4 +151,10 @@ start_server {tags {"incr"}} { catch {r incrbyfloat foo 1} err format $err } {ERR*valid*} + + test {No negative zero} { + r incrbyfloat foo [expr double(1)/41] + r incrbyfloat foo [expr double(-1)/41] + r get foo + } {0} } -- cgit v1.2.1