summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorfilipe oliveira <filipecosta.90@gmail.com>2022-11-14 16:55:52 +0000
committerGitHub <noreply@github.com>2022-11-14 08:55:52 -0800
commitf0bdf8405b9f16013385bd81895e646aca134d4f (patch)
treed51d2f93de78b5eda25120fd895980761c677c96
parent991b0b0b31d8b6c907db0fafdd4fdabb1b432d4e (diff)
Add support for nan in RESP3 double (#1133)
-rw-r--r--read.c6
-rw-r--r--test.c7
2 files changed, 8 insertions, 5 deletions
diff --git a/read.c b/read.c
index 228d4d0..8e6d21b 100644
--- a/read.c
+++ b/read.c
@@ -303,11 +303,13 @@ static int processLineItem(redisReader *r) {
d = INFINITY; /* Positive infinite. */
} else if (len == 4 && strcasecmp(buf,"-inf") == 0) {
d = -INFINITY; /* Negative infinite. */
+ } else if (len == 3 && strcasecmp(buf,"nan") == 0) {
+ d = NAN; /* nan. */
} else {
d = strtod((char*)buf,&eptr);
/* RESP3 only allows "inf", "-inf", and finite values, while
- * strtod() allows other variations on infinity, NaN,
- * etc. We explicity handle our two allowed infinite cases
+ * strtod() allows other variations on infinity,
+ * etc. We explicity handle our two allowed infinite cases and NaN
* above, so strtod() should only result in finite values. */
if (buf[0] == '\0' || eptr != &buf[len] || !isfinite(d)) {
__redisReaderSetError(r,REDIS_ERR_PROTOCOL,
diff --git a/test.c b/test.c
index 5a75a9c..c1065ff 100644
--- a/test.c
+++ b/test.c
@@ -674,12 +674,13 @@ static void test_reply_reader(void) {
freeReplyObject(reply);
redisReaderFree(reader);
- test("Set error when RESP3 double is NaN: ");
+ test("Correctly parses RESP3 double NaN: ");
reader = redisReaderCreate();
redisReaderFeed(reader, ",nan\r\n",6);
ret = redisReaderGetReply(reader,&reply);
- test_cond(ret == REDIS_ERR &&
- strcasecmp(reader->errstr,"Bad double value") == 0);
+ test_cond(ret == REDIS_OK &&
+ ((redisReply*)reply)->type == REDIS_REPLY_DOUBLE &&
+ isnan(((redisReply*)reply)->dval));
freeReplyObject(reply);
redisReaderFree(reader);