fix: out-of-bounds error with empty backstack (#2887)

This commit is contained in:
Mika Vilpas 2025-06-17 03:29:46 +03:00 committed by GitHub
parent a0ab614108
commit c8148d2d75
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -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);