shithub: rgbds

Download patch

ref: dddff0f4507f297c0bd36d77caf5180be7f56acd
parent: a919f922a1372f0fd9617c6b71a6ebd92ec729c3
author: Rangi <remy.oukaour+rangi42@gmail.com>
date: Fri Feb 12 10:54:15 EST 2021

Cannot start a new section that's already on the stack

This is only relevant for FRAGMENT or UNION sections, since
normal ones would fail with "Section already defined previously".

Fixes #730

--- a/src/asm/section.c
+++ b/src/asm/section.c
@@ -87,15 +87,10 @@
 
 struct Section *out_FindSectionByName(const char *name)
 {
-	struct Section *sect = pSectionList;
-
-	while (sect) {
+	for (struct Section *sect = pSectionList; sect; sect = sect->next) {
 		if (strcmp(name, sect->name) == 0)
 			return sect;
-
-		sect = sect->next;
 	}
-
 	return NULL;
 }
 
@@ -375,6 +370,11 @@
 {
 	if (currentLoadSection)
 		fatalerror("Cannot change the section within a `LOAD` block\n");
+
+	for (struct SectionStackEntry *stack = sectionStack; stack; stack = stack->next) {
+		if (stack->section && !strcmp(name, stack->section->name))
+			fatalerror("Section '%s' is already on the stack\n", name);
+	}
 
 	struct Section *sect = getSection(name, type, org, attribs, mod);
 
--- /dev/null
+++ b/test/asm/new-pushed-section.asm
@@ -1,0 +1,7 @@
+SECTION FRAGMENT "A", ROM0
+	db 1
+PUSHS
+SECTION FRAGMENT "A", ROM0
+	db 2
+POPS
+	db 3
--- /dev/null
+++ b/test/asm/new-pushed-section.err
@@ -1,0 +1,2 @@
+FATAL: new-pushed-section.asm(4):
+    Section 'A' is already on the stack