aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorMiquel Sabaté Solà <mikisabate@gmail.com>2024-12-13 14:24:55 +0100
committerMiquel Sabaté Solà <mikisabate@gmail.com>2024-12-13 14:28:10 +0100
commit5f07c9840ecaebd07b9685dc55539166a697eb6e (patch)
treeb83ccdcde54a64522a9ef231e9ffa147009961ab /lib
parentac8c477cf69a33bc3640437fd0287b53ca31b111 (diff)
downloadtools.nes-5f07c9840ecaebd07b9685dc55539166a697eb6e.tar.gz
tools.nes-5f07c9840ecaebd07b9685dc55539166a697eb6e.zip
parser: Fix crash on non-ASCII char literals
If the given char literal was not an ASCII one, there was the chance for the character iterator to mess things up. Hence, when checking the closing single quote, it might encounter a None value. This is simply mitigated my moving the check of ASCII alphanumeric before checking for the closing quote. Fixes: b1623996c76f ("Add support for character literals") Signed-off-by: Miquel Sabaté Solà <mikisabate@gmail.com>
Diffstat (limited to 'lib')
-rw-r--r--lib/xixanta/src/parser.rs6
1 files changed, 3 insertions, 3 deletions
diff --git a/lib/xixanta/src/parser.rs b/lib/xixanta/src/parser.rs
index 9c67587..19b4530 100644
--- a/lib/xixanta/src/parser.rs
+++ b/lib/xixanta/src/parser.rs
@@ -789,14 +789,14 @@ impl Parser {
let del = chars.next().unwrap();
let ch = chars.next().unwrap();
- if del != '\'' || chars.next().unwrap() != '\'' {
- return Err(self.parser_error("bad character literal"));
- }
if !ch.is_ascii_alphanumeric() {
return Err(self.parser_error(
"only alphanumeric ASCII characters are allowed on character literals",
));
}
+ if del != '\'' || chars.next().unwrap() != '\'' {
+ return Err(self.parser_error("bad character literal"));
+ }
Ok(PNode {
node_type: NodeType::Literal,