Skip to content

Commit

Permalink
fix: check empty file to prevent underflow
Browse files Browse the repository at this point in the history
  • Loading branch information
dxrcy committed Dec 4, 2024
1 parent cb393d0 commit 1b7a447
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -143,11 +143,12 @@ pub fn parse_generic_unexpected(src: &'static str, expected: &str, found: Token)
}

pub fn parse_eof(src: &'static str) -> Report {
let offset = src.len().checked_sub(1).unwrap_or(0);
miette!(
severity = Severity::Error,
code = "parse::unexpected_eof",
help = "you may be missing operands in your last statement",
labels = vec![LabeledSpan::at_offset(src.len() - 1, "here")],
labels = vec![LabeledSpan::at_offset(offset, "here")],
"Unexpected end of file",
)
.with_source_code(src)
Expand Down

0 comments on commit 1b7a447

Please sign in to comment.