Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions src/t_hash.c
Original file line number Diff line number Diff line change
Expand Up @@ -1280,7 +1280,7 @@ void hincrbyfloatCommand(client *c) {
mstime_t expiry = EXPIRY_NONE;

if (getLongDoubleFromObjectOrReply(c, c->argv[3], &incr, NULL) != C_OK) return;
if (isnan(incr) || isinf(incr)) {
if (isinf(incr)) {
addReplyError(c, "value is NaN or Infinity");
return;
}
Expand All @@ -1300,8 +1300,8 @@ void hincrbyfloatCommand(client *c) {
}

value += incr;
if (isnan(value) || isinf(value)) {
addReplyError(c, "increment would produce NaN or Infinity");
if (isinf(value)) {
addReplyError(c, "increment would produce Infinity");
return;
}

Expand Down
4 changes: 0 additions & 4 deletions src/t_string.c
Original file line number Diff line number Diff line change
Expand Up @@ -880,10 +880,6 @@ void increxCommand(client *c) {
return;
}
value_ld = oldvalue_ld + incr_ld;
if (isnan(value_ld)) {
addReplyError(c, "Increment is not a valid float");
return;
}
if (isinf(value_ld)) {
addReplyArrayLen(c, 2);
addReplyHumanLongDouble(c, oldvalue_ld);
Expand Down
15 changes: 15 additions & 0 deletions tests/unit/type/hash.tcl
Original file line number Diff line number Diff line change
Expand Up @@ -960,6 +960,21 @@ start_server {tags {"hash"}} {
assert_error "*value is NaN or Infinity*" {r hincrbyfloat hfoo field +inf}
assert_equal 0 [r exists hfoo]
} {} {valgrind:skip}

test {HINCRBYFLOAT rejects a NaN increment} {
r del hfoo
assert_error "*value is not a valid float*" {r hincrbyfloat hfoo field nan}
}

test {HINCRBYFLOAT with an infinite field value} {
r del hfoo
r hset hfoo field inf
assert_error "*would produce Infinity*" {r hincrbyfloat hfoo field 1}
assert_equal inf [r hget hfoo field]
# An infinite increment is dropped before the result is ever computed.
assert_error "*value is NaN or Infinity*" {r hincrbyfloat hfoo field -inf}
assert_equal inf [r hget hfoo field]
} {} {valgrind:skip}
}

start_server {config "minimal.conf" tags {"hash" "external:skip"} overrides {io-threads 4 io-threads-always-active yes hash-max-listpack-entries 0}} {
Expand Down
11 changes: 11 additions & 0 deletions tests/unit/type/incr.tcl
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,17 @@ start_server {tags {"incr"}} {
# perform divisions.
} {ERR *would produce*} {valgrind:skip}

test {INCRBYFLOAT rejects a NaN increment} {
r set foo 0
assert_error "*value is not a valid float*" {r incrbyfloat foo nan}
}

test {INCRBYFLOAT with an infinite field value} {
r set foo inf
assert_error "*would produce NaN or Infinity*" {r incrbyfloat foo -inf}
assert_equal inf [r get foo]
} {} {valgrind:skip}

test {INCRBYFLOAT decrement} {
r set foo 1
roundFloat [r incrbyfloat foo -1.1]
Expand Down
Loading