Print correct error message on premature end of array

This commit is contained in:
Petri Lehtinen 2009-06-21 16:04:43 +03:00
parent ae5ed3ff70
commit dc9b954b62

View File

@ -359,25 +359,27 @@ static json_t *json_parse_array(json_lex *lex, json_error_t *error)
return NULL;
json_lex_scan(lex);
if(lex->token != ']') {
while(1) {
json_t *elem = json_parse(lex, error);
if(!elem)
goto error;
if(lex->token == ']')
return array;
if(json_array_append(array, elem)) {
json_decref(elem);
goto error;
}
while(lex->token) {
json_t *elem = json_parse(lex, error);
if(!elem)
goto error;
if(json_array_append(array, elem)) {
json_decref(elem);
if(lex->token != ',')
break;
json_lex_scan(lex);
goto error;
}
json_decref(elem);
if(lex->token != ',')
break;
json_lex_scan(lex);
}
if(lex->token != ']') {
json_set_error(error, lex, "']' expected");
goto error;