From 016c4dc11320a5b1a853e6d3e36d6cff45f77c3d Mon Sep 17 00:00:00 2001 From: vms Date: Sun, 30 Jun 2019 21:27:19 +0300 Subject: [PATCH] fix issue with using long double in snprintf --- src/util.c | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/util.c b/src/util.c index ca6ff4e0..44093452 100644 --- a/src/util.c +++ b/src/util.c @@ -540,7 +540,12 @@ int ld2string(char *buf, size_t len, long double value, int humanfriendly) { * way that is "non surprising" for the user (that is, most small * decimal numbers will be represented in a way that when converted * back into a string are exactly the same as what the user typed.) */ +#if __redis_unmodified_upstream // using Lf modifier used for long double crashes Redis l = snprintf(buf,len,"%.17Lf", value); +#else + const double value_tmp = value; + l = snprintf(buf,len,"%lf", value_tmp); +#endif if (l+1 > len) return 0; /* No room. */ /* Now remove trailing zeroes after the '.' */ if (strchr(buf,'.') != NULL) { @@ -552,7 +557,12 @@ int ld2string(char *buf, size_t len, long double value, int humanfriendly) { if (*p == '.') l--; } } else { +#if __redis_unmodified_upstream // using Lf modifier used for long double crashes Redis l = snprintf(buf,len,"%.17Lf", value); +#else + const double value_tmp = value; + l = snprintf(buf,len,"%lf", value_tmp); +#endif if (l+1 > len) return 0; /* No room. */ } buf[l] = '\0';