Using isnan and isinf macros if they are defined (fixes issue #104).

This commit is contained in:
Krzysztof Gabis 2018-08-02 21:20:39 +02:00
parent 4f3eaa6849
commit b58ac757a8

View File

@ -53,6 +53,12 @@
#undef malloc #undef malloc
#undef free #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_Malloc_Function parson_malloc = malloc;
static JSON_Free_Function parson_free = free; 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 * json_value_init_number(double number) {
JSON_Value *new_value = NULL; JSON_Value *new_value = NULL;
if ((number * 0.0) != 0.0) { /* nan and inf test */ if (IS_NUMBER_INVALID(number)) {
return NULL; return NULL;
} }
new_value = (JSON_Value*)parson_malloc(sizeof(JSON_Value)); new_value = (JSON_Value*)parson_malloc(sizeof(JSON_Value));