-
Notifications
You must be signed in to change notification settings - Fork 291
Closed
Description
Hi,
The parser fails when the following JSON is provided: {"myArray": [] }
In code:
static char str[] = "{ "myArray": [] }";
json_value * root = json_parse(str, strlen(str));
This is because malloc is called with a size of 0, due to the empty array. However some implementations of malloc will return NULL when asked to allocate 0 bytes and in this case the parser stops. I think this is wrong. In my opinion the parser should not try to allocate 0 bytes. A simple check in the newValue method for the json_array case can prevent this:
In code:
if (value->u.array.length == 0) {
break;
}
With these three lines of code the parser can also handle the above input.
Regards,
Matthijs
Metadata
Metadata
Assignees
Labels
No labels