From 5f07c9840ecaebd07b9685dc55539166a697eb6e Mon Sep 17 00:00:00 2001 From: Miquel Sabaté Solà Date: Fri, 13 Dec 2024 14:24:55 +0100 Subject: parser: Fix crash on non-ASCII char literals MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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à --- lib/xixanta/src/parser.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'lib') 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, -- cgit v1.2.3