diff --git a/lib/line-index/src/lib.rs b/lib/line-index/src/lib.rs index 6318cbde50bc..622738ce8fb4 100644 --- a/lib/line-index/src/lib.rs +++ b/lib/line-index/src/lib.rs @@ -184,7 +184,7 @@ impl LineIndex { if let Some(wide_chars) = self.line_wide_chars.get(&line_col.line) { for c in wide_chars.iter() { if u32::from(c.end) <= line_col.col { - col -= u32::from(c.len()) - c.wide_len(enc); + col = col.checked_sub(u32::from(c.len()) - c.wide_len(enc))?; } else { // From here on, all utf16 characters come *after* the character we are mapping, // so we don't need to take them into account @@ -201,7 +201,7 @@ impl LineIndex { if let Some(wide_chars) = self.line_wide_chars.get(&line_col.line) { for c in wide_chars.iter() { if col > u32::from(c.start) { - col += u32::from(c.len()) - c.wide_len(enc) as u32; + col = col.checked_add(u32::from(c.len()) - c.wide_len(enc))?; } else { // From here on, all utf16 characters come *after* the character we are mapping, // so we don't need to take them into account