mirror of
https://github.com/gbdev/rgbds.git
synced 2025-12-05 17:27:48 +00:00
Fix garbage characters at EOF causing an infinite loop
This commit is contained in:
@@ -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);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
1
test/asm/garbage-before-eof.asm
Normal file
1
test/asm/garbage-before-eof.asm
Normal file
@@ -0,0 +1 @@
|
|||||||
|
MACRO<EFBFBD>
|
||||||
5
test/asm/garbage-before-eof.err
Normal file
5
test/asm/garbage-before-eof.err
Normal 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!
|
||||||
Reference in New Issue
Block a user