shithub: rgbds

Download patch

ref: c4fb5591eeddd2baad12fc32400dfea2bdd20fcf
parent: c0ce1da4c34f01493bbc5c4fd0735eb0cc2c4bfe
author: ISSOtm <eldredhabert0@gmail.com>
date: Wed Dec 30 10:50:09 EST 2020

Fix size of unterminated REPT/FOREACH blocks

Do not "uncapture" ENDR if it was not read in the first place

--- a/src/asm/lexer.c
+++ b/src/asm/lexer.c
@@ -2127,6 +2127,11 @@
 
 			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 @@
 finish:
 	assert(!lexerState->capturing);
 	*capture = captureStart;
-	*size = lexerState->captureSize - strlen("ENDR");
+	*size = lexerState->captureSize;
 	lexerState->captureBuf = NULL;
 	lexerState->disableMacroArgs = false;
 	lexerState->disableInterpolation = false;