From c249c3a7bc41a84c1592cc220258268925d65a15 Mon Sep 17 00:00:00 2001 From: itycodes Date: Thu, 12 Feb 2026 12:28:17 +0100 Subject: [PATCH] Fix yet another missing history bounds check --- src/reader/mod.rs | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/reader/mod.rs b/src/reader/mod.rs index 0388a63..0b9af78 100644 --- a/src/reader/mod.rs +++ b/src/reader/mod.rs @@ -84,10 +84,10 @@ impl ReaderState { self.redraw(); } - fn current_hist(&mut self) -> String { + fn current_hist(&mut self) -> Option { let i: usize = self.history_inx.unwrap(); let line = self.history.get(self.history.len().saturating_sub(i+1)); - return line.unwrap().to_string(); + return line.map(|s| s.to_string()); } fn set_current_hist(&mut self, str: String) { @@ -97,7 +97,7 @@ impl ReaderState { } fn insert_at_cursor_hist(&mut self, txt: String) { - let mut line = self.current_hist(); + let mut line = self.current_hist().expect("Trying to modify a non-existent history entry"); line.insert_str(self.cursor, txt.as_str()); self.history_reset(); self.set_line(line.clone()); @@ -177,6 +177,7 @@ impl ReaderState { pub fn read_line(&mut self) -> Result { use EditCommand::*; loop { + self.set_prompt(format!("{:?}> ", self.history_inx)); let cmd = self.input_line(); if cmd.is_err() { return Err(cmd.err().unwrap()); @@ -232,7 +233,7 @@ impl ReaderState { pub fn history_back(&mut self) { let h = self.history.clone(); let mut i = self.history_inx; - if i.map_or(false, |v| v+1 == h.len()) { + if i.map_or(h.len() == 0, |v| v+1 == h.len()) { bell(); return; } @@ -320,7 +321,7 @@ impl ReaderState { pub fn backspace(&mut self) { if self.history_inx.is_some() { if self.cursor > 0 { - let mut line = self.current_hist(); + let mut line = self.current_hist().expect("Trying to modify a non-existent history entry"); line.remove(self.cursor-1); self.move_left(); self.history_reset();