Fix garbage characters at EOF causing an infinite loop

This commit is contained in:
Rangi42
2025-12-04 11:21:06 -05:00
committed by Rangi
parent a6eb6457d8
commit ad3188f038
3 changed files with 11 additions and 1 deletions

View File

@@ -1636,6 +1636,10 @@ static Token yylex_SKIP_TO_ENDC(); // Forward declaration for `yylex_NORMAL`
// Must stay in sync with the `switch` in `yylex_NORMAL`! // Must stay in sync with the `switch` in `yylex_NORMAL`!
static bool isGarbageCharacter(int c) { static bool isGarbageCharacter(int c) {
// EOF is not garbage (it can't be reported anyway)
if (c == EOF) {
return false;
}
// Whitespace characters are not garbage, even the non-"printable" ones // Whitespace characters are not garbage, even the non-"printable" ones
if (isWhitespace(c)) { if (isWhitespace(c)) {
return false; return false;
@@ -1645,7 +1649,7 @@ static bool isGarbageCharacter(int c) {
return true; return true;
} }
// All other printable characters are not garbage (i.e. `yylex_NORMAL` handles them), and // All other printable characters are not garbage (i.e. `yylex_NORMAL` handles them), and
// all other nonprintable characters are garbage (including '\0' and EOF) // all other nonprintable characters are garbage (including '\0')
return !isPrintable(c); return !isPrintable(c);
} }

View File

@@ -0,0 +1 @@
MACRO<EFBFBD>

View File

@@ -0,0 +1,5 @@
error: Invalid character 0xEB (is the file UTF-8?)
at garbage-before-eof.asm(1)
error: syntax error, unexpected end of buffer, expecting ? or symbol
at garbage-before-eof.asm(1)
Assembly aborted with 2 errors!