mirror of
https://github.com/sxyazi/yazi.git
synced 2026-07-25 08:41:05 +00:00
fix: out-of-bounds error with empty Backstack and L (forward)
**Issue:** After starting yazi, and pressing `L` to go forward to the next visited directory, yazi crashes with the following message: ```rs ❯ RUST_BACKTRACE=full yazi Backtrace (most recent call first): File "<unknown>", line 0, in __mh_execute_header File "<unknown>", line 0, in __mh_execute_header File "<unknown>", line 0, in __mh_execute_header File "<unknown>", line 0, in __mh_execute_header File "<unknown>", line 0, in __mh_execute_header File "<unknown>", line 0, in __mh_execute_header File "<unknown>", line 0, in __mh_execute_header File "<unknown>", line 0, in __mh_execute_header File "<unknown>", line 0, in __mh_execute_header File "<unknown>", line 0, in __mh_execute_header File "<unknown>", line 0, in __mh_execute_header File "<unknown>", line 0, in __mh_execute_header File "<unknown>", line 0, in __mh_execute_header File "<unknown>", line 0, in __mh_execute_header File "<unknown>", line 0, in __mh_execute_header File "<unknown>", line 0, in __mh_execute_header The application panicked (crashed). index out of bounds: the len is 0 but the index is 1 in yazi-core/src/tab/backstack.rs, line 48 thread: main ``` **Solution:** Fix the out-of-bounds error by accounting for the case where the `Backstack` is empty.
This commit is contained in:
parent
a0ab614108
commit
6957b1aca4
1 changed files with 4 additions and 2 deletions
|
|
@ -41,7 +41,7 @@ impl<T: Eq + Clone> Backstack<T> {
|
|||
}
|
||||
|
||||
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<u32> = Backstack::default();
|
||||
assert_eq!(bs.shift_forward(), None);
|
||||
|
||||
bs.push(&1);
|
||||
assert_eq!(bs.stack[bs.cursor], 1);
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue