diff --git a/parson.c b/parson.c index 65fa0da..b914ae8 100644 --- a/parson.c +++ b/parson.c @@ -33,6 +33,7 @@ #include #include #include +#include #define STARTING_CAPACITY 15 #define ARRAY_MAX_CAPACITY 122880 /* 15*(2^13) */ @@ -737,15 +738,14 @@ static JSON_Value * parse_boolean_value(const char **string) { static JSON_Value * parse_number_value(const char **string) { char *end; - double number = strtod(*string, &end); - JSON_Value *output_value; - if (is_decimal(*string, end - *string)) { - *string = end; - output_value = json_value_init_number(number); - } else { - output_value = NULL; + double number = 0; + errno = 0; + number = strtod(*string, &end); + if (errno || !is_decimal(*string, end - *string)) { + return NULL; } - return output_value; + *string = end; + return json_value_init_number(number); } static JSON_Value * parse_null_value(const char **string) { diff --git a/tests.c b/tests.c index 0bdd834..9355688 100644 --- a/tests.c +++ b/tests.c @@ -291,6 +291,8 @@ void test_suite_3(void) { TEST(json_parse_string("[-007]") == NULL); TEST(json_parse_string("[-07.0]") == NULL); TEST(json_parse_string("[\"\\uDF67\\uD834\"]") == NULL); /* wrong order surrogate pair */ + TEST(json_parse_string("[1.7976931348623157e309]") == NULL); + TEST(json_parse_string("[-1.7976931348623157e309]") == NULL); } void test_suite_4() {