commit 2fc399c5e592dc6c8114e790510d4b232f0d341a
parent 8038d63a4306f4124dc61ccffe677c2db4468a73
Author: Alexey Yerin <yyp@disroot.org>
Date: Sun, 19 Feb 2023 22:52:38 +0300
hare::lex: propagate syntax errors in nextw
Signed-off-by: Alexey Yerin <yyp@disroot.org>
Diffstat:
2 files changed, 14 insertions(+), 4 deletions(-)
diff --git a/hare/lex/+test.ha b/hare/lex/+test.ha
@@ -312,6 +312,16 @@ fn loc(line: uint, col: uint) location = location {
const s = lex(&lexer) as error as syntax;
assert(s.1 == "Source file is not valid UTF-8");
+
+ // Regression: invalid UTF-8 at the beginning of a token used to cause
+ // a crash in nextw
+ const in = [0x80: u8];
+
+ let buf = bufio::fixed(in, mode::READ);
+ let lexer = init(&buf, "<test>");
+
+ const s = lex(&lexer) as error as syntax;
+ assert(s.1 == "Source file is not valid UTF-8");
};
diff --git a/hare/lex/lex.ha b/hare/lex/lex.ha
@@ -751,10 +751,10 @@ fn next(lex: *lexer) ((rune, location) | syntax | io::EOF | io::error) = {
};
};
-fn nextw(lex: *lexer) ((rune, location) | io::EOF | io::error) = {
- for (true) match (next(lex)) {
- case let e: (io::error | io::EOF) =>
- return e;
+fn nextw(lex: *lexer) ((rune, location) | io::EOF | error) = {
+ for (true) match (next(lex)?) {
+ case io::EOF =>
+ return io::EOF;
case let r: (rune, location) =>
if (ascii::isspace(r.0)) {
if (r.0 == '\n') {