X-Git-Url: http://www.project-moonshot.org/gitweb/?a=blobdiff_plain;f=src%2Fvalue.c;fp=src%2Fvalue.c;h=ba9908edd08ae54b0d29c9dc9327ed0986f2e235;hb=4118315afa994ff71c2970c9f8933ab48178dbcb;hp=547eb5df2d306aa57c3e350ba13b5828a5491b79;hpb=ee13c667f10ab6e3ccde9493e71f7ac79496f9e7;p=jansson.git diff --git a/src/value.c b/src/value.c index 547eb5d..ba9908e 100644 --- a/src/value.c +++ b/src/value.c @@ -10,12 +10,20 @@ #include #include #include +#include #include "jansson.h" #include "hashtable.h" #include "jansson_private.h" #include "utf.h" +/* Work around nonstandard isnan() and isinf() implementations */ +#ifndef isnan +static JSON_INLINE int isnan(double x) { return x != x; } +#endif +#ifndef isinf +static JSON_INLINE int isinf(double x) { return !isnan(x) && isnan(x - x); } +#endif static JSON_INLINE void json_init(json_t *json, json_type type) { @@ -731,7 +739,12 @@ static json_t *json_integer_copy(json_t *integer) json_t *json_real(double value) { - json_real_t *real = jsonp_malloc(sizeof(json_real_t)); + json_real_t *real; + + if(isnan(value) || isinf(value)) + return NULL; + + real = jsonp_malloc(sizeof(json_real_t)); if(!real) return NULL; json_init(&real->json, JSON_REAL); @@ -750,7 +763,7 @@ double json_real_value(const json_t *json) int json_real_set(json_t *json, double value) { - if(!json_is_real(json)) + if(!json_is_real(json) || isnan(value) || isinf(value)) return -1; json_to_real(json)->value = value;