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; return NULL;
json_lex_scan(lex); json_lex_scan(lex);
if(lex->token != ']') { if(lex->token == ']')
while(1) { return array;
json_t *elem = json_parse(lex, error);
if(!elem)
goto error;
if(json_array_append(array, elem)) { while(lex->token) {
json_decref(elem); json_t *elem = json_parse(lex, error);
goto error; if(!elem)
} goto error;
if(json_array_append(array, elem)) {
json_decref(elem); json_decref(elem);
goto error;
if(lex->token != ',')
break;
json_lex_scan(lex);
} }
json_decref(elem);
if(lex->token != ',')
break;
json_lex_scan(lex);
} }
if(lex->token != ']') { if(lex->token != ']') {
json_set_error(error, lex, "']' expected"); json_set_error(error, lex, "']' expected");
goto error; goto error;