mirror of
https://github.com/gbdev/rgbds.git
synced 2026-09-06 13:57:07 +00:00
Use rpnErrorAt wrapper to ensure setting isError on all RPN errors
Two possible RPN errors were missing `isError = true;`
This commit is contained in:
+23
-29
@@ -47,11 +47,16 @@ static bool isError = false;
|
|||||||
} \
|
} \
|
||||||
} while (0)
|
} while (0)
|
||||||
|
|
||||||
|
#define rpnErrorAt(...) \
|
||||||
|
do { \
|
||||||
|
errorAt(__VA_ARGS__); \
|
||||||
|
isError = true; \
|
||||||
|
} while (0)
|
||||||
|
|
||||||
#define firstErrorAt(...) \
|
#define firstErrorAt(...) \
|
||||||
do { \
|
do { \
|
||||||
if (!isError) { \
|
if (!isError) { \
|
||||||
errorAt(__VA_ARGS__); \
|
rpnErrorAt(__VA_ARGS__); \
|
||||||
isError = true; \
|
|
||||||
} \
|
} \
|
||||||
} while (0)
|
} while (0)
|
||||||
|
|
||||||
@@ -283,16 +288,15 @@ static int32_t computeRPNExpr(Patch const &patch, std::vector<Symbol> const &fil
|
|||||||
if (symID >= fileSymbols.size()) {
|
if (symID >= fileSymbols.size()) {
|
||||||
fatalAt(patch, "Requested `BANK()` of invalid symbol ID #%" PRIu32, symID);
|
fatalAt(patch, "Requested `BANK()` of invalid symbol ID #%" PRIu32, symID);
|
||||||
} else if (Symbol const *symbol = getSymbol(fileSymbols, symID); !symbol) {
|
} else if (Symbol const *symbol = getSymbol(fileSymbols, symID); !symbol) {
|
||||||
errorAt(
|
rpnErrorAt(
|
||||||
patch,
|
patch,
|
||||||
"Requested `BANK()` of undefined symbol `%s`",
|
"Requested `BANK()` of undefined symbol `%s`",
|
||||||
fileSymbols[symID].name.c_str()
|
fileSymbols[symID].name.c_str()
|
||||||
);
|
);
|
||||||
isError = true;
|
|
||||||
value = 1;
|
value = 1;
|
||||||
} else if (std::holds_alternative<Label>(symbol->data)) {
|
} else if (std::holds_alternative<Label>(symbol->data)) {
|
||||||
if (Label const &label = std::get<Label>(symbol->data); !label.section) {
|
if (Label const &label = std::get<Label>(symbol->data); !label.section) {
|
||||||
errorAt(
|
rpnErrorAt(
|
||||||
patch,
|
patch,
|
||||||
"Requested `BANK()` of label `%s` outside of a section",
|
"Requested `BANK()` of label `%s` outside of a section",
|
||||||
fileSymbols[symID].name.c_str()
|
fileSymbols[symID].name.c_str()
|
||||||
@@ -302,12 +306,11 @@ static int32_t computeRPNExpr(Patch const &patch, std::vector<Symbol> const &fil
|
|||||||
value = label.section->bank;
|
value = label.section->bank;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
errorAt(
|
rpnErrorAt(
|
||||||
patch,
|
patch,
|
||||||
"Requested `BANK()` of non-label symbol `%s`",
|
"Requested `BANK()` of non-label symbol `%s`",
|
||||||
fileSymbols[symID].name.c_str()
|
fileSymbols[symID].name.c_str()
|
||||||
);
|
);
|
||||||
isError = true;
|
|
||||||
value = 1;
|
value = 1;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
@@ -320,8 +323,7 @@ static int32_t computeRPNExpr(Patch const &patch, std::vector<Symbol> const &fil
|
|||||||
while (getRPNByte(expression, size, patch)) {}
|
while (getRPNByte(expression, size, patch)) {}
|
||||||
|
|
||||||
if (Section const *sect = sect_GetSection(name); !sect) {
|
if (Section const *sect = sect_GetSection(name); !sect) {
|
||||||
errorAt(patch, "Requested `BANK()` of undefined section \"%s\"", name);
|
rpnErrorAt(patch, "Requested `BANK()` of undefined section \"%s\"", name);
|
||||||
isError = true;
|
|
||||||
value = 1;
|
value = 1;
|
||||||
} else {
|
} else {
|
||||||
value = sect->bank;
|
value = sect->bank;
|
||||||
@@ -331,8 +333,7 @@ static int32_t computeRPNExpr(Patch const &patch, std::vector<Symbol> const &fil
|
|||||||
|
|
||||||
case RPN_BANK_SELF:
|
case RPN_BANK_SELF:
|
||||||
if (!patch.pcSection) {
|
if (!patch.pcSection) {
|
||||||
errorAt(patch, "PC has no bank outside of a section");
|
rpnErrorAt(patch, "PC has no bank outside of a section");
|
||||||
isError = true;
|
|
||||||
value = 1;
|
value = 1;
|
||||||
} else {
|
} else {
|
||||||
value = patch.pcSection->bank;
|
value = patch.pcSection->bank;
|
||||||
@@ -345,8 +346,7 @@ static int32_t computeRPNExpr(Patch const &patch, std::vector<Symbol> const &fil
|
|||||||
while (getRPNByte(expression, size, patch)) {}
|
while (getRPNByte(expression, size, patch)) {}
|
||||||
|
|
||||||
if (Section const *sect = sect_GetSection(name); !sect) {
|
if (Section const *sect = sect_GetSection(name); !sect) {
|
||||||
errorAt(patch, "Requested `SIZEOF()` of undefined section \"%s\"", name);
|
rpnErrorAt(patch, "Requested `SIZEOF()` of undefined section \"%s\"", name);
|
||||||
isError = true;
|
|
||||||
value = 1;
|
value = 1;
|
||||||
} else {
|
} else {
|
||||||
value = sect->size;
|
value = sect->size;
|
||||||
@@ -360,8 +360,7 @@ static int32_t computeRPNExpr(Patch const &patch, std::vector<Symbol> const &fil
|
|||||||
while (getRPNByte(expression, size, patch)) {}
|
while (getRPNByte(expression, size, patch)) {}
|
||||||
|
|
||||||
if (Section const *sect = sect_GetSection(name); !sect) {
|
if (Section const *sect = sect_GetSection(name); !sect) {
|
||||||
errorAt(patch, "Requested `STARTOF()` of undefined section \"%s\"", name);
|
rpnErrorAt(patch, "Requested `STARTOF()` of undefined section \"%s\"", name);
|
||||||
isError = true;
|
|
||||||
value = 1;
|
value = 1;
|
||||||
} else {
|
} else {
|
||||||
assume(sect->offset == 0);
|
assume(sect->offset == 0);
|
||||||
@@ -373,8 +372,7 @@ static int32_t computeRPNExpr(Patch const &patch, std::vector<Symbol> const &fil
|
|||||||
case RPN_SIZEOF_SECTTYPE:
|
case RPN_SIZEOF_SECTTYPE:
|
||||||
value = getRPNByte(expression, size, patch);
|
value = getRPNByte(expression, size, patch);
|
||||||
if (value < 0 || value >= SECTTYPE_INVALID) {
|
if (value < 0 || value >= SECTTYPE_INVALID) {
|
||||||
errorAt(patch, "Requested `SIZEOF()` of an invalid section type");
|
rpnErrorAt(patch, "Requested `SIZEOF()` of an invalid section type");
|
||||||
isError = true;
|
|
||||||
value = 0;
|
value = 0;
|
||||||
} else {
|
} else {
|
||||||
value = sectionTypeInfo[value].size;
|
value = sectionTypeInfo[value].size;
|
||||||
@@ -384,8 +382,7 @@ static int32_t computeRPNExpr(Patch const &patch, std::vector<Symbol> const &fil
|
|||||||
case RPN_STARTOF_SECTTYPE:
|
case RPN_STARTOF_SECTTYPE:
|
||||||
value = getRPNByte(expression, size, patch);
|
value = getRPNByte(expression, size, patch);
|
||||||
if (value < 0 || value >= SECTTYPE_INVALID) {
|
if (value < 0 || value >= SECTTYPE_INVALID) {
|
||||||
errorAt(patch, "Requested `STARTOF()` of an invalid section type");
|
rpnErrorAt(patch, "Requested `STARTOF()` of an invalid section type");
|
||||||
isError = true;
|
|
||||||
value = 0;
|
value = 0;
|
||||||
} else {
|
} else {
|
||||||
value = sectionTypeInfo[value].startAddr;
|
value = sectionTypeInfo[value].startAddr;
|
||||||
@@ -446,20 +443,18 @@ static int32_t computeRPNExpr(Patch const &patch, std::vector<Symbol> const &fil
|
|||||||
if (patch.pcSection) {
|
if (patch.pcSection) {
|
||||||
value = patch.pcOffset + patch.pcSection->org;
|
value = patch.pcOffset + patch.pcSection->org;
|
||||||
} else {
|
} else {
|
||||||
errorAt(patch, "PC has no value outside of a section");
|
rpnErrorAt(patch, "PC has no value outside of a section");
|
||||||
value = 0;
|
value = 0;
|
||||||
isError = true;
|
|
||||||
}
|
}
|
||||||
} else if (symID >= fileSymbols.size()) {
|
} else if (symID >= fileSymbols.size()) {
|
||||||
fatalAt(patch, "Invalid symbol ID #%" PRIu32, symID);
|
fatalAt(patch, "Invalid symbol ID #%" PRIu32, symID);
|
||||||
} else if (Symbol const *symbol = getSymbol(fileSymbols, symID); !symbol) {
|
} else if (Symbol const *symbol = getSymbol(fileSymbols, symID); !symbol) {
|
||||||
errorAt(patch, "Undefined symbol `%s`", fileSymbols[symID].name.c_str());
|
rpnErrorAt(patch, "Undefined symbol `%s`", fileSymbols[symID].name.c_str());
|
||||||
sym_TraceLocalAliasedSymbols(fileSymbols[symID].name);
|
sym_TraceLocalAliasedSymbols(fileSymbols[symID].name);
|
||||||
value = 0;
|
value = 0;
|
||||||
isError = true;
|
|
||||||
} else if (std::holds_alternative<Label>(symbol->data)) {
|
} else if (std::holds_alternative<Label>(symbol->data)) {
|
||||||
if (Label const &label = std::get<Label>(symbol->data); !label.section) {
|
if (Label const &label = std::get<Label>(symbol->data); !label.section) {
|
||||||
errorAt(
|
rpnErrorAt(
|
||||||
patch,
|
patch,
|
||||||
"Requested value of label `%s` outside of a section",
|
"Requested value of label `%s` outside of a section",
|
||||||
fileSymbols[symID].name.c_str()
|
fileSymbols[symID].name.c_str()
|
||||||
@@ -484,7 +479,7 @@ static int32_t computeRPNExpr(Patch const &patch, std::vector<Symbol> const &fil
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (rpnStack.size() > 1) {
|
if (rpnStack.size() > 1) {
|
||||||
errorAt(patch, "RPN stack has %zu entries on exit, not 1", rpnStack.size());
|
rpnErrorAt(patch, "RPN stack has %zu entries on exit, not 1", rpnStack.size());
|
||||||
}
|
}
|
||||||
|
|
||||||
isError = false;
|
isError = false;
|
||||||
@@ -511,7 +506,7 @@ void patch_CheckAssertions() {
|
|||||||
!assert.message.empty() ? assert.message.c_str() : "assert failure"
|
!assert.message.empty() ? assert.message.c_str() : "assert failure"
|
||||||
);
|
);
|
||||||
case ASSERT_ERROR:
|
case ASSERT_ERROR:
|
||||||
errorAt(
|
rpnErrorAt(
|
||||||
assert.patch,
|
assert.patch,
|
||||||
"%s",
|
"%s",
|
||||||
!assert.message.empty() ? assert.message.c_str() : "assert failure"
|
!assert.message.empty() ? assert.message.c_str() : "assert failure"
|
||||||
@@ -578,7 +573,7 @@ static void applyFilePatches(Section §ion, Section &dataSection) {
|
|||||||
uint8_t typeSize = typeSizes[patch.type];
|
uint8_t typeSize = typeSizes[patch.type];
|
||||||
|
|
||||||
if (dataSection.data.size() < offset + typeSize) {
|
if (dataSection.data.size() < offset + typeSize) {
|
||||||
errorAt(
|
rpnErrorAt(
|
||||||
patch,
|
patch,
|
||||||
"Patch would write %zu bytes past the end of section \"%s\" (%zu bytes long)",
|
"Patch would write %zu bytes past the end of section \"%s\" (%zu bytes long)",
|
||||||
offset + typeSize - dataSection.data.size(),
|
offset + typeSize - dataSection.data.size(),
|
||||||
@@ -587,9 +582,8 @@ static void applyFilePatches(Section §ion, Section &dataSection) {
|
|||||||
);
|
);
|
||||||
} else if (patch.type == PATCHTYPE_JR) {
|
} else if (patch.type == PATCHTYPE_JR) {
|
||||||
if (!patch.pcSection) {
|
if (!patch.pcSection) {
|
||||||
errorAt(patch, "PC has no value outside of a section");
|
rpnErrorAt(patch, "PC has no value outside of a section");
|
||||||
dataSection.data[offset] = 0;
|
dataSection.data[offset] = 0;
|
||||||
isError = true;
|
|
||||||
} else {
|
} else {
|
||||||
// Offset is relative to the byte *after* the operand
|
// Offset is relative to the byte *after* the operand
|
||||||
// PC as operand to `jr` is lower than reference PC by 2
|
// PC as operand to `jr` is lower than reference PC by 2
|
||||||
|
|||||||
Reference in New Issue
Block a user