aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlex Gulyás <gulyas.alex@gmail.com>2015-08-14 14:54:32 +0200
committerAlex Gulyás <gulyas.alex@gmail.com>2015-08-14 14:54:32 +0200
commit64ae43a386155b905fd4938ec40a61f3edff1856 (patch)
tree099d63db31bfd6c3697203f32bc933c2d162a27e
parent0f0746396a67028d4a58071e7b1a6ae26c9f6954 (diff)
downloadmilf-rs-64ae43a386155b905fd4938ec40a61f3edff1856.tar.gz
milf-rs-64ae43a386155b905fd4938ec40a61f3edff1856.zip
Fix the arithmetic overflow in Parser::to_linecol
This also changes the calculated line and column numbers. Without this patch, if an error occurs at the end of a line, the returned line and column numbers will point at the start of the next line. After this patch, the line and column numbers will correctly point at the end of the line where the actual parse error happened.
-rw-r--r--src/parser.rs2
1 files changed, 1 insertions, 1 deletions
diff --git a/src/parser.rs b/src/parser.rs
index b7a810f..ab63e63 100644
--- a/src/parser.rs
+++ b/src/parser.rs
@@ -148,7 +148,7 @@ impl<'a> Parser<'a> {
pub fn to_linecol(&self, offset: usize) -> (usize, usize) {
let mut cur = 0;
for (i, line) in self.input.lines().enumerate() {
- if cur + line.len() > offset {
+ if cur + line.len() + 1 > offset {
return (i, offset - cur)
}
cur += line.len() + 1;