From b3918a0deed6cf925866b6c076fade593e3db55d Mon Sep 17 00:00:00 2001 From: Christoph Mallon Date: Wed, 12 Dec 2007 08:01:49 +0000 Subject: [PATCH] Fix off-by-two-tokens error in the location of break and continue statements. [r18699] --- parser.c | 35 +++++++++++++++++++---------------- 1 file changed, 19 insertions(+), 16 deletions(-) diff --git a/parser.c b/parser.c index c1c3054..2bf5cb7 100644 --- a/parser.c +++ b/parser.c @@ -5201,18 +5201,19 @@ static statement_t *parse_goto(void) */ static statement_t *parse_continue(void) { - eat(T_continue); - expect(';'); - - statement_t *statement = allocate_ast_zero(sizeof(statement[0])); - statement->kind = STATEMENT_CONTINUE; - statement->base.source_position = token.source_position; - + statement_t *statement; if (current_loop == NULL) { errorf(HERE, "continue statement not within loop"); - return NULL; + statement = NULL; + } else { + statement = allocate_ast_zero(sizeof(statement[0])); + statement->kind = STATEMENT_CONTINUE; + statement->base.source_position = token.source_position; } + eat(T_continue); + expect(';'); + return statement; } @@ -5221,17 +5222,19 @@ static statement_t *parse_continue(void) */ static statement_t *parse_break(void) { - eat(T_break); - expect(';'); - - statement_t *statement = allocate_ast_zero(sizeof(statement[0])); - statement->kind = STATEMENT_BREAK; - statement->base.source_position = token.source_position; - + statement_t *statement; if (current_switch == NULL && current_loop == NULL) { errorf(HERE, "break statement not within loop or switch"); - return NULL; + statement = NULL; + } else { + statement = allocate_ast_zero(sizeof(statement[0])); + statement->kind = STATEMENT_BREAK; + statement->base.source_position = token.source_position; } + + eat(T_break); + expect(';'); + return statement; } -- 2.20.1