New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Parse error when arrays are empty #46
Comments
Thanks, I didn't know |
And then changed my mind and did it your way in 8c4b18f because I realised my way violated the "[never] allocates more memory than it needs" claim. Do you have a name for the AUTHORS file? |
This website (http://www.cplusplus.com/reference/cstdlib/malloc/) says the return value of malloc is implementation defined when allocating 0 bytes. On 30 jun. 2014, at 18:27, James McLaughlin notifications@github.com wrote:
|
My full name is: Matthijs Boelstra Thanx! On 30 jun. 2014, at 18:31, James McLaughlin notifications@github.com wrote:
|
Thank you. 👍 |
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
The text was updated successfully, but these errors were encountered: