From dc9b954b62145d114cbf9039ed6c8fb57b30ac36 Mon Sep 17 00:00:00 2001 From: Petri Lehtinen Date: Sun, 21 Jun 2009 16:04:43 +0300 Subject: [PATCH] Print correct error message on premature end of array --- src/load.c | 30 ++++++++++++++++-------------- 1 file changed, 16 insertions(+), 14 deletions(-) diff --git a/src/load.c b/src/load.c index 5f49fbc..9f8d22f 100644 --- a/src/load.c +++ b/src/load.c @@ -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;