From 64ae43a386155b905fd4938ec40a61f3edff1856 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alex=20Guly=C3=A1s?= Date: Fri, 14 Aug 2015 14:54:32 +0200 Subject: 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. --- src/parser.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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; -- cgit v1.2.3