1
0
mirror of https://github.com/kgabis/parson.git synced 2025-01-14 06:12:54 +08:00

Checking errno after strtod call.

This commit is contained in:
Krzysztof Gabis 2017-01-06 21:35:29 +01:00
parent defb57f2d3
commit cb14736e96
2 changed files with 10 additions and 8 deletions

View File

@ -33,6 +33,7 @@
#include <string.h>
#include <ctype.h>
#include <math.h>
#include <errno.h>
#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) {

View File

@ -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() {