mirror of
https://github.com/gbdev/rgbds.git
synced 2026-08-25 00:04:38 +00:00
Prevent SECTION FRAGMENT combined sizes from overflowing their uint16_t size
This commit is contained in:
@@ -146,6 +146,15 @@ static void mergeSections(Section &target, std::unique_ptr<Section> &&other) {
|
||||
|
||||
case SECTION_FRAGMENT:
|
||||
checkPieceCompat(target, *other, target.size);
|
||||
// Check that `target.size += other->size` below will not overflow
|
||||
if (target.size + other->size > UINT16_MAX) {
|
||||
fatalTwoAt(
|
||||
target,
|
||||
*other,
|
||||
"Section \"%s\" fragments combined are larger than the GB address space",
|
||||
target.name.c_str()
|
||||
);
|
||||
}
|
||||
// Append `other` to `target`
|
||||
other->offset = target.size;
|
||||
target.size += other->size;
|
||||
|
||||
@@ -0,0 +1,2 @@
|
||||
SECTION FRAGMENT "output", ROM0
|
||||
ds $4000
|
||||
@@ -0,0 +1,5 @@
|
||||
FATAL: Section "output" fragments combined are larger than the GB address space
|
||||
at section-fragment/size-overflow/a.asm(1)
|
||||
and also:
|
||||
at section-fragment/size-overflow/a.asm(1)
|
||||
Linking aborted with 1 error
|
||||
@@ -398,6 +398,14 @@ rgblinkQuiet -o "$gbtemp" "$otemp" "$gbtemp2"
|
||||
tryCmpRom "$test"/ref.out.bin
|
||||
evaluateTest
|
||||
|
||||
test="section-fragment/size-overflow"
|
||||
startTest
|
||||
"$RGBASM" -o "$otemp" "$test"/a.asm
|
||||
continueTest
|
||||
rgblinkQuiet "$otemp" "$otemp" "$otemp" "$otemp" 2>"$outtemp"
|
||||
tryDiff "$test"/out.err "$outtemp"
|
||||
evaluateTest
|
||||
|
||||
test="section-fragment/jr-offset"
|
||||
startTest
|
||||
"$RGBASM" -o "$otemp" "$test"/a.asm
|
||||
|
||||
Reference in New Issue
Block a user