mirror of
https://github.com/kgabis/parson.git
synced 2025-01-28 06:32:55 +08:00
Checking errno after strtod call.
This commit is contained in:
parent
defb57f2d3
commit
cb14736e96
16
parson.c
16
parson.c
@ -33,6 +33,7 @@
|
|||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <ctype.h>
|
#include <ctype.h>
|
||||||
#include <math.h>
|
#include <math.h>
|
||||||
|
#include <errno.h>
|
||||||
|
|
||||||
#define STARTING_CAPACITY 15
|
#define STARTING_CAPACITY 15
|
||||||
#define ARRAY_MAX_CAPACITY 122880 /* 15*(2^13) */
|
#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) {
|
static JSON_Value * parse_number_value(const char **string) {
|
||||||
char *end;
|
char *end;
|
||||||
double number = strtod(*string, &end);
|
double number = 0;
|
||||||
JSON_Value *output_value;
|
errno = 0;
|
||||||
if (is_decimal(*string, end - *string)) {
|
number = strtod(*string, &end);
|
||||||
*string = end;
|
if (errno || !is_decimal(*string, end - *string)) {
|
||||||
output_value = json_value_init_number(number);
|
return NULL;
|
||||||
} else {
|
|
||||||
output_value = NULL;
|
|
||||||
}
|
}
|
||||||
return output_value;
|
*string = end;
|
||||||
|
return json_value_init_number(number);
|
||||||
}
|
}
|
||||||
|
|
||||||
static JSON_Value * parse_null_value(const char **string) {
|
static JSON_Value * parse_null_value(const char **string) {
|
||||||
|
2
tests.c
2
tests.c
@ -291,6 +291,8 @@ void test_suite_3(void) {
|
|||||||
TEST(json_parse_string("[-007]") == NULL);
|
TEST(json_parse_string("[-007]") == NULL);
|
||||||
TEST(json_parse_string("[-07.0]") == NULL);
|
TEST(json_parse_string("[-07.0]") == NULL);
|
||||||
TEST(json_parse_string("[\"\\uDF67\\uD834\"]") == NULL); /* wrong order surrogate pair */
|
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() {
|
void test_suite_4() {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user