Skip to content

Commit 816565d

Browse files
committed
Ensure Pos.positionToOffset does not return negative offsets
1 parent 03deb09 commit 816565d

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

analysis/src/Pos.ml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@ let positionToOffset text (line, character) =
2222
match offsetOfLine text line with
2323
| None -> None
2424
| Some bol ->
25-
if bol + character <= String.length text then Some (bol + character)
26-
else None
25+
let offset = bol + character in
26+
if offset >= 0 && offset <= String.length text then Some offset else None
2727

2828
let posBeforeCursor pos = (fst pos, max 0 (snd pos - 1))
2929

0 commit comments

Comments
 (0)