about summary refs log tree commit diff
diff options
context:
space:
mode:
authorAriel Davis <ariel.z.davis@icloud.com>2023-05-06 15:05:03 -0700
committerAriel Davis <ariel.z.davis@icloud.com>2023-05-06 15:05:03 -0700
commit1bc6bca478872347faa32371663b3aff7b00624f (patch)
treeb881dad95f2d30c43acd280ea3afa4bd6e85bdb4
parent343976fe56d65aae4d4c6c4ac9d0ceb25b07c036 (diff)
downloadrust-1bc6bca478872347faa32371663b3aff7b00624f.tar.gz
rust-1bc6bca478872347faa32371663b3aff7b00624f.zip
Use checked
-rw-r--r--lib/line-index/src/lib.rs4
1 files changed, 2 insertions, 2 deletions
diff --git a/lib/line-index/src/lib.rs b/lib/line-index/src/lib.rs
index 6318cbde50b..622738ce8fb 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