diff --git a/src/asm/section.c b/src/asm/section.c index e77018ea..44a816f2 100644 --- a/src/asm/section.c +++ b/src/asm/section.c @@ -87,15 +87,10 @@ static inline void reserveSpace(uint32_t delta_size) 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; } @@ -376,6 +371,11 @@ void out_NewSection(char const *name, uint32_t type, uint32_t org, 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); changeSection(); diff --git a/test/asm/new-pushed-section.asm b/test/asm/new-pushed-section.asm new file mode 100644 index 00000000..c94bcda3 --- /dev/null +++ b/test/asm/new-pushed-section.asm @@ -0,0 +1,7 @@ +SECTION FRAGMENT "A", ROM0 + db 1 +PUSHS +SECTION FRAGMENT "A", ROM0 + db 2 +POPS + db 3 diff --git a/test/asm/new-pushed-section.err b/test/asm/new-pushed-section.err new file mode 100644 index 00000000..8a1b9beb --- /dev/null +++ b/test/asm/new-pushed-section.err @@ -0,0 +1,2 @@ +FATAL: new-pushed-section.asm(4): + Section 'A' is already on the stack diff --git a/test/asm/new-pushed-section.out b/test/asm/new-pushed-section.out new file mode 100644 index 00000000..e69de29b