aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/libstrongswan/tests/test_printf.c14
-rw-r--r--src/libstrongswan/utils/printf_hook/printf_hook_builtin.c24
2 files changed, 36 insertions, 2 deletions
diff --git a/src/libstrongswan/tests/test_printf.c b/src/libstrongswan/tests/test_printf.c
index a7b19d96e..6c15fbea1 100644
--- a/src/libstrongswan/tests/test_printf.c
+++ b/src/libstrongswan/tests/test_printf.c
@@ -16,6 +16,7 @@
#include "test_suite.h"
#include <errno.h>
+#include <math.h>
static void verify(char *expected, char *format, ...)
{
@@ -133,6 +134,19 @@ START_TEST(test_printf_float)
verify("-1.12", "%.2f", -1.1249);
verify("-1.124", "%.3f", -1.12351);
verify("-1.123", "%.3f", -1.12349);
+
+#ifdef NAN
+ verify("nan", "%.3f", NAN);
+ verify(" nan", "%5.3f", NAN);
+ verify("NAN", "%.3F", NAN);
+ verify("NAN ", "%-5.3F", NAN);
+#endif
+#ifdef INFINITY
+ verify("inf", "%.3f", INFINITY);
+ verify("-inf", "%.4f", -INFINITY);
+ verify("INF", "%.3F", INFINITY);
+ verify("-INF", "%.4F", -INFINITY);
+#endif
}
END_TEST
diff --git a/src/libstrongswan/utils/printf_hook/printf_hook_builtin.c b/src/libstrongswan/utils/printf_hook/printf_hook_builtin.c
index a28ce7f48..ec0a418d8 100644
--- a/src/libstrongswan/utils/printf_hook/printf_hook_builtin.c
+++ b/src/libstrongswan/utils/printf_hook/printf_hook_builtin.c
@@ -923,9 +923,29 @@ int builtin_vsnprintf(char *buffer, size_t n, const char *format, va_list ap)
}
is_double:
{
+ double dval;
+
+ dval = va_arg(ap, double);
+ if (isinf(dval) == 1)
+ {
+ sarg = flags & FL_UPPER ? "INF" : "inf";
+ slen = strlen(sarg);
+ goto is_string;
+ }
+ if (isinf(dval) == -1)
+ {
+ sarg = flags & FL_UPPER ? "-INF" : "-inf";
+ slen = strlen(sarg);
+ goto is_string;
+ }
+ if (isnan(dval))
+ {
+ sarg = flags & FL_UPPER ? "NAN" : "nan";
+ slen = strlen(sarg);
+ goto is_string;
+ }
sz = format_double(q, (o < n) ? n - o : 0,
- va_arg(ap, double),
- flags, base, width, prec);
+ dval, flags, base, width, prec);
q += sz;
o += sz;
break;