printf-hook-builtin: Don't rely on isinf() return value signedness
authorMartin Willi <martin@revosec.ch>
Thu, 24 Oct 2013 13:17:30 +0000 (15:17 +0200)
committerMartin Willi <martin@revosec.ch>
Thu, 24 Oct 2013 13:37:20 +0000 (15:37 +0200)
Many systems don't return a negative value for negative infinities; so do
a separate check.

src/libstrongswan/utils/printf_hook/printf_hook_builtin.c

index ec0a418..d00abef 100644 (file)
@@ -926,15 +926,16 @@ int builtin_vsnprintf(char *buffer, size_t n, const char *format, va_list ap)
                                                                double dval;
 
                                                                dval = va_arg(ap, double);
-                                                               if (isinf(dval) == 1)
+                                                               if (isinf(dval))
                                                                {
-                                                                       sarg = flags & FL_UPPER ? "INF" : "inf";
-                                                                       slen = strlen(sarg);
-                                                                       goto is_string;
-                                                               }
-                                                               if (isinf(dval) == -1)
-                                                               {
-                                                                       sarg = flags & FL_UPPER ? "-INF" : "-inf";
+                                                                       if (isgreater(dval, 0.0))
+                                                                       {
+                                                                               sarg = flags & FL_UPPER ? "INF" : "inf";
+                                                                       }
+                                                                       else
+                                                                       {
+                                                                               sarg = flags & FL_UPPER ? "-INF" : "-inf";
+                                                                       }
                                                                        slen = strlen(sarg);
                                                                        goto is_string;
                                                                }