Skip to content

Commit

Permalink
Using isnan and isinf macros if they are defined (fixes issue kgabis#104
Browse files Browse the repository at this point in the history
).
  • Loading branch information
kgabis committed Aug 2, 2018
1 parent 4f3eaa6 commit b58ac75
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion parson.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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));
Expand Down

0 comments on commit b58ac75

Please sign in to comment.