]> granicus.if.org Git - icinga2/commitdiff
Make print_number work for non-finite numbers again.
authorGunnar Beutner <gunnar@beutner.name>
Sun, 20 Apr 2014 17:21:55 +0000 (19:21 +0200)
committerGunnar Beutner <gunnar@beutner.name>
Sun, 20 Apr 2014 17:21:55 +0000 (19:21 +0200)
Refs #4865

third-party/cJSON/cJSON.c

index 70ed0014b0ee446ed05a95d435a08f52b3fd91ac..f1bef65ffe859799c12ee5c566f75cd83cb80696 100644 (file)
@@ -127,12 +127,20 @@ static char *print_number(cJSON *item)
        }
        else
        {
-               str=(char*)cJSON_malloc(64 + (int)log10(fabs(d)));      /* This is a nice tradeoff. */
-               if (str)
+               if (d != d)
                {
-                       if (d != d)                                             strcpy(str, "0");
-                       else if (fabs(floor(d)-d)<=DBL_EPSILON)                 sprintf(str,"%.0f",d);
-                       else                                                    sprintf(str,"%.*e",(int)log10(d) + 6,d);
+                       str=(char*)cJSON_malloc(2);
+                       if (str)
+                               strcpy(str, "0");
+               }
+               else
+               {
+                       str = (char*)cJSON_malloc(64 + (int)log10(fabs(d)));    /* This is a nice tradeoff. */
+                       if (str)
+                       {
+                               if (fabs(floor(d) - d) <= DBL_EPSILON)                  sprintf(str, "%.0f", d);
+                               else                                                    sprintf(str, "%.*e", (int)log10(d) + 6, d);
+                       }
                }
        }
        return str;