shithub: rgbds

Download patch

ref: 0665146dcdfd83c5f8576a4fbf8a26240e268d0a
parent: 1f8422575ee90a9421771f0abfd2a374061fa3c4
author: ISSOtm <[email protected]>
date: Mon Jan 20 22:12:43 EST 2020

Report line info on empty RPN stack

--- a/src/link/patch.c
+++ b/src/link/patch.c
@@ -52,10 +52,11 @@
 	stack.size++;
 }
 
-static int32_t popRPN(void)
+static int32_t popRPN(char const *fileName, int32_t lineNo)
 {
 	if (stack.size == 0)
-		errx(1, "Internal error, RPN stack empty");
+		errx(1, "%s(%d): Internal error, RPN stack empty", fileName,
+		     lineNo);
 
 	stack.size--;
 	return stack.buf[stack.size];
@@ -85,6 +86,9 @@
 static int32_t computeRPNExpr(struct Patch const *patch,
 			      struct Section const *section)
 {
+/* Small shortcut to avoid a lot of repetition */
+#define popRPN() popRPN(patch->fileName, patch->lineNo)
+
 	uint8_t const *expression = patch->rpnExpression;
 	int32_t size = patch->rpnSize;
 
@@ -287,6 +291,8 @@
 		      patch->fileName, patch->lineNo, stack.size);
 
 	return popRPN();
+
+#undef popRPN
 }
 
 /**