diff options
author | Vsevolod Stakhov <vsevolod@highsecure.ru> | 2017-11-16 18:53:52 +0000 |
---|---|---|
committer | Vsevolod Stakhov <vsevolod@highsecure.ru> | 2017-11-16 18:56:17 +0000 |
commit | 84c2524e855dd0ccd27724e54e6cf09fb2419d86 (patch) | |
tree | 5f4a63ecab9dcef6ebde632e9c8555511c1946b6 /src/libutil | |
parent | fe41f43de4bea57b93689c132bce4dcbb3cbb524 (diff) | |
download | rspamd-84c2524e855dd0ccd27724e54e6cf09fb2419d86.tar.gz rspamd-84c2524e855dd0ccd27724e54e6cf09fb2419d86.zip |
[Fix] Deal with nan and inf encoding in json/ucl
Diffstat (limited to 'src/libutil')
-rw-r--r-- | src/libutil/str_util.c | 34 |
1 files changed, 20 insertions, 14 deletions
diff --git a/src/libutil/str_util.c b/src/libutil/str_util.c index 004204881..22d63c302 100644 --- a/src/libutil/str_util.c +++ b/src/libutil/str_util.c @@ -1862,15 +1862,18 @@ rspamd_gstring_append_double (double val, void *ud) GString *buf = ud; const double delta = 0.0000001; - if (val == (double) (int) val) { - rspamd_printf_gstring (buf, "%.1f", val); - } - else if (fabs (val - (double) (int) val) < delta) { - /* Write at maximum precision */ - rspamd_printf_gstring (buf, "%.*g", DBL_DIG, val); + if (isfinite (val)) { + if (val == (double) (int) val) { + rspamd_printf_gstring (buf, "%.1f", val); + } else if (fabs (val - (double) (int) val) < delta) { + /* Write at maximum precision */ + rspamd_printf_gstring (buf, "%.*g", DBL_DIG, val); + } else { + rspamd_printf_gstring (buf, "%f", val); + } } else { - rspamd_printf_gstring (buf, "%f", val); + rspamd_printf_gstring (buf, "null"); } return 0; @@ -1931,15 +1934,18 @@ rspamd_fstring_emit_append_double (double val, void *ud) rspamd_fstring_t **buf = ud; const double delta = 0.0000001; - if (val == (double)((gint) val)) { - rspamd_printf_fstring (buf, "%.1f", val); - } - else if (fabs (val - (double) (int) val) < delta) { - /* Write at maximum precision */ - rspamd_printf_fstring (buf, "%.*g", DBL_DIG, val); + if (isfinite (val)) { + if (val == (double) ((gint) val)) { + rspamd_printf_fstring (buf, "%.1f", val); + } else if (fabs (val - (double) (int) val) < delta) { + /* Write at maximum precision */ + rspamd_printf_fstring (buf, "%.*g", DBL_DIG, val); + } else { + rspamd_printf_fstring (buf, "%f", val); + } } else { - rspamd_printf_fstring (buf, "%f", val); + rspamd_printf_fstring (buf, "null"); } return 0; |