Fix underflow of ALIGN[16, offset] (#2090)

This commit is contained in:
Rangi
2026-09-15 20:22:33 -04:00
committed by GitHub
parent d81ab2fb23
commit f4c6221eb1
3 changed files with 17 additions and 2 deletions
+11 -2
View File
@@ -717,8 +717,17 @@ void sect_AlignPC(uint8_t alignment, uint16_t offset) {
} else if (alignment == 16) {
// Treat an alignment large enough as fixing the address.
// Note that this also ensures that a section's alignment never becomes 16 or greater.
sect->align = 0; // Reset the alignment, since we're fixing the address.
sect->org = offset - curOffset;
if (offset < curOffset) {
error(
"Section already contains %" PRIu32
" bytes, higher than this aligned address $%04" PRIx32,
curOffset,
offset
);
} else {
sect->align = 0; // Reset the alignment, since we're fixing the address.
sect->org = offset - curOffset;
}
} else if (alignment > sect->align) {
sect->align = alignment;
// We need `(sect->alignOfs + curOffset) & alignMask == offset`
+3
View File
@@ -0,0 +1,3 @@
SECTION "test", ROM0
db 1, 2, 3
align 16, 2
+3
View File
@@ -0,0 +1,3 @@
error: Section already contains 3 bytes, higher than this aligned address $0002
at align-beyond-size.asm(3)
Assembly aborted with 1 error