summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorantirez <antirez@gmail.com>2013-07-17 15:04:22 +0200
committerantirez <antirez@gmail.com>2013-07-17 15:04:22 +0200
commita50635bb6c6cce99885418b8752b4939cd4fd62e (patch)
treefa5db2aa07a13e4c30af42dfdb1ae0c40d082b1f
parent2e449d42e0f4dda4d2e71f04a2973b21f8fb6e8c (diff)
downloadredis-a50635bb6c6cce99885418b8752b4939cd4fd62e.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.c13
1 files changed, 10 insertions, 3 deletions
diff --git a/src/networking.c b/src/networking.c
index 848952626..23ada4541 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.