From 9cce9ff81be0a229569456b9a824663291cfad08 Mon Sep 17 00:00:00 2001 From: Wez Furlong Date: Wed, 3 Aug 2022 21:34:12 -0700 Subject: [PATCH] fix potential panic when computing hyperlink rules refs: https://github.com/wez/wezterm/issues/2355 --- termwiz/src/surface/line/line.rs | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/termwiz/src/surface/line/line.rs b/termwiz/src/surface/line/line.rs index 87c929aa0..9959a4cda 100644 --- a/termwiz/src/surface/line/line.rs +++ b/termwiz/src/surface/line/line.rs @@ -499,6 +499,10 @@ impl Line { pub fn split_off(&mut self, idx: usize, seqno: SequenceNo) -> Self { let my_cells = self.coerce_vec_storage(); + // Clamp to avoid out of bounds panic if the line is shorter + // than the requested split point + // + let idx = idx.min(my_cells.len()); let cells = my_cells.split_off(idx); Self { bits: self.bits,