From c8148d2d75cc502efffb323cc97ea1e1be6158e3 Mon Sep 17 00:00:00 2001 From: Mika Vilpas Date: Tue, 17 Jun 2025 03:29:46 +0300 Subject: [PATCH] fix: out-of-bounds error with empty backstack (#2887) --- yazi-core/src/tab/backstack.rs | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/yazi-core/src/tab/backstack.rs b/yazi-core/src/tab/backstack.rs index bb9ffd5e..4bd8afa6 100644 --- a/yazi-core/src/tab/backstack.rs +++ b/yazi-core/src/tab/backstack.rs @@ -41,7 +41,7 @@ impl Backstack { } pub fn shift_forward(&mut self) -> Option<&T> { - if self.cursor + 1 == self.stack.len() { + if self.cursor + 1 >= self.stack.len() { None } else { self.cursor += 1; @@ -56,7 +56,9 @@ mod tests { #[test] fn test_backstack() { - let mut bs = Backstack::default(); + let mut bs: Backstack = Backstack::default(); + assert_eq!(bs.shift_forward(), None); + bs.push(&1); assert_eq!(bs.stack[bs.cursor], 1);