aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorVsevolod Stakhov <vsevolod@highsecure.ru>2015-06-25 09:44:53 +0100
committerVsevolod Stakhov <vsevolod@highsecure.ru>2015-06-25 09:44:53 +0100
commita683065a653c65aefc257e1a5443d81d0622cbfe (patch)
treef8c8afd49b9676f939904c878c001049941b69e1
parente3a61120f831ca275f95b0edf9e3fc94a384955f (diff)
downloadrspamd-a683065a653c65aefc257e1a5443d81d0622cbfe.tar.gz
rspamd-a683065a653c65aefc257e1a5443d81d0622cbfe.zip
Handle non-normal FP numbers in printf.
-rw-r--r--src/libutil/printf.c70
1 files changed, 42 insertions, 28 deletions
diff --git a/src/libutil/printf.c b/src/libutil/printf.c
index 64deab209..14e372f4e 100644
--- a/src/libutil/printf.c
+++ b/src/libutil/printf.c
@@ -577,43 +577,57 @@ rspamd_vprintf_common (rspamd_printf_append_func func,
else {
f = (long double) va_arg (args, long double);
}
- p = numbuf;
- last = p + sizeof (numbuf);
- if (f < 0) {
- *p++ = '-';
- f = -f;
- }
- if (frac_width == 0) {
- frac_width = 6;
- }
- ui64 = (gint64) f;
+ if (isnormal (f)) {
+ p = numbuf;
+ last = p + sizeof (numbuf);
+ if (f < 0) {
+ *p++ = '-';
+ f = -f;
+ }
+ if (frac_width == 0) {
+ frac_width = 6;
+ }
- p = rspamd_sprintf_num (p, last, ui64, zero, 0, width);
+ ui64 = (gint64) f;
- if (frac_width) {
+ p = rspamd_sprintf_num (p, last, ui64, zero, 0, width);
- if (p < last) {
- *p++ = '.';
- }
+ if (frac_width) {
- scale = 1.0;
+ if (p < last) {
+ *p++ = '.';
+ }
- for (i = 0; i < frac_width; i++) {
- scale *= 10.0;
- }
+ scale = 1.0;
- /*
- * (gint64) cast is required for msvc6:
- * it can not convert guint64 to double
- */
- ui64 = (guint64) ((f - (gint64) ui64) * scale);
+ for (i = 0; i < frac_width; i++) {
+ scale *= 10.0;
+ }
- p = rspamd_sprintf_num (p, last, ui64, '0', 0, frac_width);
- }
+ /*
+ * (gint64) cast is required for msvc6:
+ * it can not convert guint64 to double
+ */
+ ui64 = (guint64) ((f - (gint64) ui64) * scale);
- slen = p - numbuf;
- RSPAMD_PRINTF_APPEND (numbuf, slen);
+ p = rspamd_sprintf_num (p, last, ui64, '0', 0, frac_width);
+ }
+
+ slen = p - numbuf;
+ RSPAMD_PRINTF_APPEND (numbuf, slen);
+ }
+ else if (isnan (f)) {
+ RSPAMD_PRINTF_APPEND ("NaN", 3);
+ }
+ else {
+ if (signbit (f)) {
+ RSPAMD_PRINTF_APPEND ("-Inf", 4);
+ }
+ else {
+ RSPAMD_PRINTF_APPEND ("+Inf", 4);
+ }
+ }
continue;