From b58ac757a89fe85468681dacd504190ef58d2d39 Mon Sep 17 00:00:00 2001 From: Krzysztof Gabis Date: Thu, 2 Aug 2018 21:20:39 +0200 Subject: [PATCH] Using isnan and isinf macros if they are defined (fixes issue #104). --- parson.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/parson.c b/parson.c index d0b7819..afbfd2d 100644 --- a/parson.c +++ b/parson.c @@ -53,6 +53,12 @@ #undef malloc #undef free +#if defined(isnan) && defined(isinf) +#define IS_NUMBER_INVALID(x) (isnan((x)) || isinf((x))) +#else +#define IS_NUMBER_INVALID(x) (((x) * 0.0) != 0.0) +#endif + static JSON_Malloc_Function parson_malloc = malloc; static JSON_Free_Function parson_free = free; @@ -1364,7 +1370,7 @@ JSON_Value * json_value_init_string(const char *string) { JSON_Value * json_value_init_number(double number) { JSON_Value *new_value = NULL; - if ((number * 0.0) != 0.0) { /* nan and inf test */ + if (IS_NUMBER_INVALID(number)) { return NULL; } new_value = (JSON_Value*)parson_malloc(sizeof(JSON_Value));