From 942a64ea3b009a8230c5b0dd43fb81b8332c334c Mon Sep 17 00:00:00 2001 From: bunnie Date: Wed, 21 May 2025 18:22:30 +0800 Subject: [PATCH] fix saturation bug in index computation code --- services/bao-console/src/repl.rs | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/services/bao-console/src/repl.rs b/services/bao-console/src/repl.rs index 3af2a93bb..ece4d1496 100644 --- a/services/bao-console/src/repl.rs +++ b/services/bao-console/src/repl.rs @@ -56,8 +56,9 @@ impl Repl { // An index of -1 gives the most recent command. // -2 would give the second most recent command pub(crate) fn get_history(&mut self, index: isize) -> &str { - &self.history - [(self.history.len() as isize + index).max(0).min(self.history.len() as isize - 1) as usize] + &self.history[(self.history.len() as isize + index) + .max(0) + .min(self.history.len().saturating_sub(1) as isize) as usize] .text }