kgabis/parson

Parson cannot parse generated document

Closed this issue · 1 comments

sgh commented

Using parson my software has generated the following json document.

{"xyz":[0,6.9041432094973937e-310,6.9041432094973937e-310]}

Parson however cannot parse the document.

In my debugger the doubles I pass to json_array_append_number look exactly like the ones written.

The problem seems to be errno being set to ERANGE after the call to strtod in parse_number_value during parsing.

The strtod manpage say the following regarding ERANGE.

"If the correct value would cause underflow, a value with magnitude no larger than DBL_MIN, FLT_MIN, or LDBL_MIN is returned and ERANGE is stored in errno."

So I guess the solution could be simmilar to this :

static JSON_Value * parse_number_value(const char **string) {
    char *end;
    double number = 0;
    errno = 0;
    number = strtod(*string, &end);
    if ((errno!=0 && errno!=ERANGE) || !is_decimal(*string, end - *string)) {
        return NULL;
    }
    *string = end;
    return json_value_init_number(number);
}

Screenshot_20210525_103312

Thanks, I've fixed it in 2d7b3dd.