shithub: rgbds

Download patch

ref: e050803ed1acab5e378647d66c5da00f4f5fee09
parent: 27f38770d4860305ef90922743f399eedf52de63
author: Rangi <[email protected]>
date: Wed Apr 21 09:31:48 EDT 2021

Use `size_t` for measuring nested depths

Multiple functions involve tracking the current depth
of a nested structure (symbol expansions, interpolations,
REPT/FOR blocks, parentheses).

--- a/src/asm/lexer.c
+++ b/src/asm/lexer.c
@@ -684,7 +684,7 @@
 		return;
 
 	if (name) {
-		unsigned int depth = 0;
+		size_t depth = 0;
 
 		for (struct Expansion *exp = lexerState->expansions; exp; exp = exp->parent) {
 			if (depth++ >= maxRecursionDepth)
@@ -896,7 +896,7 @@
 
 /* forward declarations for peek */
 static void shiftChar(void);
-static char const *readInterpolation(unsigned int depth);
+static char const *readInterpolation(size_t depth);
 
 static int peek(void)
 {
@@ -1357,7 +1357,7 @@
 
 /* Functions to read strings */
 
-static char const *readInterpolation(unsigned int depth)
+static char const *readInterpolation(size_t depth)
 {
 	if (depth >= maxRecursionDepth)
 		fatalerror("Recursion limit (%zu) exceeded\n", maxRecursionDepth);
@@ -2056,7 +2056,7 @@
 		 lexer_GetLineNo(), lexer_GetColNo());
 
 	/* This is essentially a modified `appendStringLiteral` */
-	unsigned int parenDepth = 0;
+	size_t parenDepth = 0;
 	size_t i = 0;
 	int c;
 
@@ -2445,7 +2445,7 @@
 	capture->lineNo = lexer_GetLineNo();
 
 	char *captureStart = startCapture();
-	unsigned int level = 0;
+	size_t depth = 0;
 	int c = EOF;
 
 	/*
@@ -2465,12 +2465,12 @@
 			switch (readIdentifier(c)) {
 			case T_POP_REPT:
 			case T_POP_FOR:
-				level++;
+				depth++;
 				/* Ignore the rest of that line */
 				break;
 
 			case T_POP_ENDR:
-				if (!level) {
+				if (!depth) {
 					/*
 					 * The final ENDR has been captured, but we don't want it!
 					 * We know we have read exactly "ENDR", not e.g. an EQUS
@@ -2478,7 +2478,7 @@
 					lexerState->captureSize -= strlen("ENDR");
 					goto finish;
 				}
-				level--;
+				depth--;
 			}
 		}