mirror of
https://github.com/gbdev/rgbds.git
synced 2026-09-16 18:57:07 +00:00
Fix underflowing SECTION FRAGMENT fixed address (#2091)
This commit is contained in:
+12
-4
@@ -214,10 +214,8 @@ static void mergeFragments(Section §, uint32_t org, uint8_t alignment, uint1
|
|||||||
// combination of both.
|
// combination of both.
|
||||||
// The merging is however performed at the *end* of the original section!
|
// The merging is however performed at the *end* of the original section!
|
||||||
if (org != UINT32_MAX) {
|
if (org != UINT32_MAX) {
|
||||||
uint16_t curOrg = org - sect.size;
|
// If both are fixed, they must be compatible
|
||||||
|
if (uint16_t curOrg = org - sect.size; sect.org != UINT32_MAX && sect.org != curOrg) {
|
||||||
// If both are fixed, they must be the same
|
|
||||||
if (sect.org != UINT32_MAX && sect.org != curOrg) {
|
|
||||||
sectError(
|
sectError(
|
||||||
"Section \"%s\" already declared as fixed at incompatible address $%04" PRIx32,
|
"Section \"%s\" already declared as fixed at incompatible address $%04" PRIx32,
|
||||||
sect.name.c_str(),
|
sect.name.c_str(),
|
||||||
@@ -231,6 +229,16 @@ static void mergeFragments(Section §, uint32_t org, uint8_t alignment, uint1
|
|||||||
sectAlignSize,
|
sectAlignSize,
|
||||||
sect.alignOfs
|
sect.alignOfs
|
||||||
);
|
);
|
||||||
|
} else if (org < sect.size) {
|
||||||
|
// Check that `curOrg` did not underflow. Note that it's safe for the above checks to
|
||||||
|
// use an underflowed value, since their reported errors will still be accurate.
|
||||||
|
sectError(
|
||||||
|
"Section \"%s\" already contains %" PRIu32
|
||||||
|
" bytes, higher than this fragment's fixed address $%04" PRIx32,
|
||||||
|
sect.name.c_str(),
|
||||||
|
sect.size,
|
||||||
|
org
|
||||||
|
);
|
||||||
} else {
|
} else {
|
||||||
// Otherwise, just override
|
// Otherwise, just override
|
||||||
sect.org = curOrg;
|
sect.org = curOrg;
|
||||||
|
|||||||
@@ -0,0 +1,4 @@
|
|||||||
|
SECTION FRAGMENT "test", ROM0
|
||||||
|
ds $11, 42
|
||||||
|
|
||||||
|
SECTION FRAGMENT "test", ROM0[$10]
|
||||||
@@ -0,0 +1,2 @@
|
|||||||
|
FATAL: Section "test" already contains 17 bytes, higher than this fragment's fixed address $0010
|
||||||
|
at fragment-org-beyond-size.asm(4)
|
||||||
Reference in New Issue
Block a user