Fix size of unterminated REPT/FOREACH blocks

Do not "uncapture" ENDR if it was not read in the first place
This commit is contained in:
ISSOtm
2020-12-30 15:50:09 +01:00
parent c0ce1da4c3
commit c4fb5591ee

View File

@@ -2127,6 +2127,11 @@ void lexer_CaptureRept(char **capture, size_t *size)
case T_POP_ENDR: case T_POP_ENDR:
if (!level) { 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 */ /* Read (but don't capture) until EOL or EOF */
lexerState->capturing = false; lexerState->capturing = false;
do { do {
@@ -2159,7 +2164,7 @@ void lexer_CaptureRept(char **capture, size_t *size)
finish: finish:
assert(!lexerState->capturing); assert(!lexerState->capturing);
*capture = captureStart; *capture = captureStart;
*size = lexerState->captureSize - strlen("ENDR"); *size = lexerState->captureSize;
lexerState->captureBuf = NULL; lexerState->captureBuf = NULL;
lexerState->disableMacroArgs = false; lexerState->disableMacroArgs = false;
lexerState->disableInterpolation = false; lexerState->disableInterpolation = false;