mirror of
https://github.com/gbdev/rgbds.git
synced 2025-11-20 18:22:07 +00:00
Fix BANK(@) outside sections causing crashes
This commit is contained in:
@@ -143,7 +143,10 @@ void rpn_BankSelf(struct Expression *expr)
|
|||||||
{
|
{
|
||||||
rpn_Init(expr);
|
rpn_Init(expr);
|
||||||
|
|
||||||
if (pCurrentSection->nBank == -1) {
|
if (!pCurrentSection) {
|
||||||
|
yyerror("PC has no bank outside a section");
|
||||||
|
expr->nVal = 1;
|
||||||
|
} else if (pCurrentSection->nBank == -1) {
|
||||||
makeUnknown(expr, "Current section's bank is not known");
|
makeUnknown(expr, "Current section's bank is not known");
|
||||||
expr->nRPNPatchSize++;
|
expr->nRPNPatchSize++;
|
||||||
*reserveSpace(expr, 1) = RPN_BANK_SELF;
|
*reserveSpace(expr, 1) = RPN_BANK_SELF;
|
||||||
|
|||||||
@@ -282,7 +282,12 @@ static int32_t computeRPNExpr(struct Patch const *patch,
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
case RPN_BANK_SELF:
|
case RPN_BANK_SELF:
|
||||||
|
if (!patch->pcSection) {
|
||||||
|
error("%s: PC has no bank outside a section");
|
||||||
|
value = 1;
|
||||||
|
} else {
|
||||||
value = patch->pcSection->bank;
|
value = patch->pcSection->bank;
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case RPN_HRAM:
|
case RPN_HRAM:
|
||||||
|
|||||||
1
test/asm/assert-nosect-bank.asm
Normal file
1
test/asm/assert-nosect-bank.asm
Normal file
@@ -0,0 +1 @@
|
|||||||
|
assert BANK(@) == 1
|
||||||
3
test/asm/assert-nosect-bank.err
Normal file
3
test/asm/assert-nosect-bank.err
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
ERROR: assert-nosect-bank.asm(1):
|
||||||
|
PC has no bank outside a section
|
||||||
|
error: Assembly aborted (1 errors)!
|
||||||
0
test/asm/assert-nosect-bank.out
Normal file
0
test/asm/assert-nosect-bank.out
Normal file
Reference in New Issue
Block a user