diff options
author | antirez <antirez@gmail.com> | 2013-07-17 15:04:22 +0200 |
---|---|---|
committer | antirez <antirez@gmail.com> | 2013-07-17 15:05:25 +0200 |
commit | b9cc90a1192a3ac2edbdac63540f889843f37284 (patch) | |
tree | 59c0fbdf22ef1528665026515e2605338bb82135 | |
parent | f590dd82cec9e06a2bdc5bd80f643705103a3e1b (diff) | |
download | redis-b9cc90a1192a3ac2edbdac63540f889843f37284.tar.gz |
addReplyDouble(): format infinite in a libc agnostic way.
There are systems that when printing +/- infinte with printf-family
functions will not use the usual "inf" "-inf", but different strings.
Handle that explicitly.
Fixes issue #930.
-rw-r--r-- | src/networking.c | 13 |
1 files changed, 10 insertions, 3 deletions
diff --git a/src/networking.c b/src/networking.c index 77c37af87..e2cbf9ad8 100644 --- a/src/networking.c +++ b/src/networking.c @@ -29,6 +29,7 @@ #include "redis.h" #include <sys/uio.h> +#include <math.h> static void setProtocolError(redisClient *c, int pos); @@ -415,9 +416,15 @@ void setDeferredMultiBulkLength(redisClient *c, void *node, long length) { void addReplyDouble(redisClient *c, double d) { char dbuf[128], sbuf[128]; int dlen, slen; - dlen = snprintf(dbuf,sizeof(dbuf),"%.17g",d); - slen = snprintf(sbuf,sizeof(sbuf),"$%d\r\n%s\r\n",dlen,dbuf); - addReplyString(c,sbuf,slen); + if (isinf(d)) { + /* Libc in odd systems (Hi Solaris!) will format infinite in a + * different way, so better to handle it in an explicit way. */ + addReplyBulkCString(c, d > 0 ? "inf" : "-inf"); + } else { + dlen = snprintf(dbuf,sizeof(dbuf),"%.17g",d); + slen = snprintf(sbuf,sizeof(sbuf),"$%d\r\n%s\r\n",dlen,dbuf); + addReplyString(c,sbuf,slen); + } } /* Add a long long as integer reply or bulk len / multi bulk count. |