shithub: rgbds

Download patch

ref: 84cd9f2db9bea744d99b2afc2c89d480732c3e23
parent: 06fe27c51601e1822b9b3212f350c21609bdf9e9
author: ISSOtm <[email protected]>
date: Fri Mar 27 07:37:29 EDT 2020

Fix segfaults when using PC outside a section

--- a/src/asm/rpn.c
+++ b/src/asm/rpn.c
@@ -106,7 +106,10 @@
 {
 	struct sSymbol *sym = sym_FindSymbol(tzSym);
 
-	if (!sym || !sym_IsConstant(sym)) {
+	if (sym == pPCSymbol && !pPCSymbol->pSection) {
+		yyerror("PC has no value outside a section");
+		rpn_Number(expr, 0);
+	} else if (!sym || !sym_IsConstant(sym)) {
 		rpn_Init(expr);
 		expr->isSymbol = true;
 
--- a/src/asm/symbol.c
+++ b/src/asm/symbol.c
@@ -230,7 +230,9 @@
 	struct sSymbol const *psym = sym_FindSymbol(s);
 
 	if (psym == pPCSymbol) {
-		if (pCurrentSection->nOrg == -1)
+		if (!pCurrentSection)
+			yyerror("PC has no value outside a section");
+		else if (pCurrentSection->nOrg == -1)
 			yyerror("Expected constant PC but section is not fixed");
 		else
 			return sym_GetValue(psym);
--- /dev/null
+++ b/test/asm/[email protected]
@@ -1,0 +1,1 @@
+assert @ || 1
--- /dev/null
+++ b/test/asm/[email protected]
@@ -1,0 +1,3 @@
+ERROR: [email protected](1):
+    PC has no value outside a section
+error: Assembly aborted (1 errors)!
--- /dev/null
+++ b/test/asm/[email protected]
@@ -1,0 +1,2 @@
+if {@}
+endc
--- /dev/null
+++ b/test/asm/[email protected]
@@ -1,0 +1,3 @@
+ERROR: [email protected](1):
+    PC has no value outside a section
+error: Assembly aborted (1 errors)!