mirror of
https://github.com/fluencelabs/redis
synced 2025-03-30 22:31:03 +00:00
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.
This commit is contained in:
parent
f590dd82ce
commit
b9cc90a119
@ -29,6 +29,7 @@
|
|||||||
|
|
||||||
#include "redis.h"
|
#include "redis.h"
|
||||||
#include <sys/uio.h>
|
#include <sys/uio.h>
|
||||||
|
#include <math.h>
|
||||||
|
|
||||||
static void setProtocolError(redisClient *c, int pos);
|
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) {
|
void addReplyDouble(redisClient *c, double d) {
|
||||||
char dbuf[128], sbuf[128];
|
char dbuf[128], sbuf[128];
|
||||||
int dlen, slen;
|
int dlen, slen;
|
||||||
dlen = snprintf(dbuf,sizeof(dbuf),"%.17g",d);
|
if (isinf(d)) {
|
||||||
slen = snprintf(sbuf,sizeof(sbuf),"$%d\r\n%s\r\n",dlen,dbuf);
|
/* Libc in odd systems (Hi Solaris!) will format infinite in a
|
||||||
addReplyString(c,sbuf,slen);
|
* 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.
|
/* Add a long long as integer reply or bulk len / multi bulk count.
|
||||||
|
Loading…
x
Reference in New Issue
Block a user