Skip to content

Commit 1bc6bca

Browse files
committed
Use checked
1 parent 343976f commit 1bc6bca

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

lib/line-index/src/lib.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,7 @@ impl LineIndex {
184184
if let Some(wide_chars) = self.line_wide_chars.get(&line_col.line) {
185185
for c in wide_chars.iter() {
186186
if u32::from(c.end) <= line_col.col {
187-
col -= u32::from(c.len()) - c.wide_len(enc);
187+
col = col.checked_sub(u32::from(c.len()) - c.wide_len(enc))?;
188188
} else {
189189
// From here on, all utf16 characters come *after* the character we are mapping,
190190
// so we don't need to take them into account
@@ -201,7 +201,7 @@ impl LineIndex {
201201
if let Some(wide_chars) = self.line_wide_chars.get(&line_col.line) {
202202
for c in wide_chars.iter() {
203203
if col > u32::from(c.start) {
204-
col += u32::from(c.len()) - c.wide_len(enc) as u32;
204+
col = col.checked_add(u32::from(c.len()) - c.wide_len(enc))?;
205205
} else {
206206
// From here on, all utf16 characters come *after* the character we are mapping,
207207
// so we don't need to take them into account

0 commit comments

Comments
 (0)