From 721cce27ecd639f71cf48cdd2a9c3117e3ebf59a Mon Sep 17 00:00:00 2001 From: "gcp-cherry-pick-bot[bot]" <98988430+gcp-cherry-pick-bot[bot]@users.noreply.github.com> Date: Mon, 2 Dec 2024 21:31:23 +0100 Subject: [PATCH] workspace: Sanitize pinned tab count before usage (cherry-pick #21417) (#21422) Cherry-picked workspace: Sanitize pinned tab count before usage (#21417) Fixes all sorts of panics around usage of incorrect pinned tab count that has been fixed in app itself, yet persists in user db. Closes #ISSUE Release Notes: - N/A Co-authored-by: Piotr Osiewicz <24362066+osiewicz@users.noreply.github.com> --- crates/workspace/src/pane.rs | 2 +- crates/workspace/src/persistence/model.rs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/crates/workspace/src/pane.rs b/crates/workspace/src/pane.rs index e9b81d4554dd727728f6601996a819314997730a..4cc69aeb3ccdb0d72870feaa1fc3f224122321bd 100644 --- a/crates/workspace/src/pane.rs +++ b/crates/workspace/src/pane.rs @@ -1870,7 +1870,7 @@ impl Pane { fn unpin_tab_at(&mut self, ix: usize, cx: &mut ViewContext<'_, Self>) { maybe!({ let pane = cx.view().clone(); - self.pinned_tab_count = self.pinned_tab_count.checked_sub(1).unwrap(); + self.pinned_tab_count = self.pinned_tab_count.checked_sub(1)?; let destination_index = self.pinned_tab_count; let id = self.item_for_index(ix)?.item_id(); diff --git a/crates/workspace/src/persistence/model.rs b/crates/workspace/src/persistence/model.rs index a2510b8bec6bf52246f20234d61b645c12046659..7a368ee441180d7dc64bd68a1f6b5137d1dcc07d 100644 --- a/crates/workspace/src/persistence/model.rs +++ b/crates/workspace/src/persistence/model.rs @@ -473,7 +473,7 @@ impl SerializedPane { })?; } pane.update(cx, |pane, _| { - pane.set_pinned_count(self.pinned_count); + pane.set_pinned_count(self.pinned_count.min(items.len())); })?; anyhow::Ok(items)