From 1ca52793ff9ccca80046688111cacc3e8d3588d4 Mon Sep 17 00:00:00 2001 From: Marco Mihai Condrache <52580954+marcocondrache@users.noreply.github.com> Date: Tue, 20 Jan 2026 13:23:17 +0100 Subject: [PATCH] rope: Fix an unintentional panic (#47019) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Avoids the panic in #46974 But should be solved by using `saturating_sub` on the `start_overshoot` calculation, ref: https://github.com/zed-industries/zed/pull/47046#issuecomment-3762855786 https://github.com/zed-industries/zed/blob/37715d5a50666baaa824eafec2131ee6d80f8e0b/crates/rope/src/chunk.rs#L403C5-L415C6 This function gets called with PANIC = false from `slice`. But if the offset is outside the text, `log_err_char_boundary` will still panic, because the first `if` doesn’t bail out early. Release Notes: - N/A Signed-off-by: Marco Mihai Condrache <52580954+marcocondrache@users.noreply.github.com> --- crates/rope/src/chunk.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/rope/src/chunk.rs b/crates/rope/src/chunk.rs index 69553eafb1b852960fa794d1b00ab28eba14888a..49bc88462171c271e8adbdeb7d0976e51e2514c7 100644 --- a/crates/rope/src/chunk.rs +++ b/crates/rope/src/chunk.rs @@ -721,7 +721,7 @@ fn panic_char_boundary(text: &str, offset: usize) -> ! { #[inline(never)] #[track_caller] fn log_err_char_boundary(text: &str, offset: usize) { - if offset > text.len() { + if offset >= text.len() { log::error!( "byte index {} is out of bounds of `{:?}` (length: {})", offset,