From c4fb5591eeddd2baad12fc32400dfea2bdd20fcf Mon Sep 17 00:00:00 2001 From: ISSOtm Date: Wed, 30 Dec 2020 15:50:09 +0100 Subject: [PATCH] Fix size of unterminated REPT/FOREACH blocks Do not "uncapture" ENDR if it was not read in the first place --- src/asm/lexer.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/asm/lexer.c b/src/asm/lexer.c index 50bec439..32a3a684 100644 --- a/src/asm/lexer.c +++ b/src/asm/lexer.c @@ -2127,6 +2127,11 @@ void lexer_CaptureRept(char **capture, size_t *size) case T_POP_ENDR: if (!level) { + /* + * The final ENDR has been captured, but we don't want it! + * We know we have read exactly "ENDR", not e.g. an EQUS + */ + lexerState->captureSize -= strlen("ENDR"); /* Read (but don't capture) until EOL or EOF */ lexerState->capturing = false; do { @@ -2159,7 +2164,7 @@ void lexer_CaptureRept(char **capture, size_t *size) finish: assert(!lexerState->capturing); *capture = captureStart; - *size = lexerState->captureSize - strlen("ENDR"); + *size = lexerState->captureSize; lexerState->captureBuf = NULL; lexerState->disableMacroArgs = false; lexerState->disableInterpolation = false;