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));