ref: 9f82fa4cf7df9e18d8b44bc91c525411a51f8e2e
parent: 562835308b23c51fdba1d1923c489a1fd3a7d056
author: ISSOtm <[email protected]>
date: Tue Apr 7 11:45:30 EDT 2020
Fix `BANK(@)` outside sections causing crashes
--- a/src/asm/rpn.c
+++ b/src/asm/rpn.c
@@ -143,7 +143,10 @@
{
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");
expr->nRPNPatchSize++;
*reserveSpace(expr, 1) = RPN_BANK_SELF;
--- a/src/link/patch.c
+++ b/src/link/patch.c
@@ -282,7 +282,12 @@
break;
case RPN_BANK_SELF:
- value = patch->pcSection->bank;
+ if (!patch->pcSection) {
+ error("%s: PC has no bank outside a section");
+ value = 1;
+ } else {
+ value = patch->pcSection->bank;
+ }
break;
case RPN_HRAM:
--- /dev/null
+++ b/test/asm/assert-nosect-bank.asm
@@ -1,0 +1,1 @@
+assert BANK(@) == 1
--- /dev/null
+++ b/test/asm/assert-nosect-bank.err
@@ -1,0 +1,3 @@
+ERROR: assert-nosect-bank.asm(1):
+ PC has no bank outside a section
+error: Assembly aborted (1 errors)!