From dbb91e0c4b61b7c1106a9d3aefcab6f2598b93d4 Mon Sep 17 00:00:00 2001 From: nsfisis Date: Mon, 20 Jul 2026 18:08:58 +0900 Subject: fix(search-command): avoid usize overflow panic when truncating description The negated remaining-width subtraction was cast straight to usize, overflowing whenever it went negative (e.g. an abandoned-package warning ate the available width) and panicking on slice indexing. Route through the shim's substr(), which mirrors PHP's negative-length semantics and clamps instead of overflowing. --- crates/shirabe/src/command/search_command.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'crates/shirabe/src/command') diff --git a/crates/shirabe/src/command/search_command.rs b/crates/shirabe/src/command/search_command.rs index 1f77889e..156dd406 100644 --- a/crates/shirabe/src/command/search_command.rs +++ b/crates/shirabe/src/command/search_command.rs @@ -17,7 +17,7 @@ use shirabe_external_packages::symfony::console::command::command::Command; use shirabe_external_packages::symfony::console::formatter::OutputFormatter; use shirabe_external_packages::symfony::console::input::InputInterface; use shirabe_external_packages::symfony::console::output::OutputInterface; -use shirabe_php_shim::{InvalidArgumentException, PhpMixed, implode, in_array, preg_quote}; +use shirabe_php_shim::{InvalidArgumentException, PhpMixed, implode, in_array, preg_quote, substr}; #[derive(Debug)] pub struct SearchCommand { @@ -230,7 +230,7 @@ impl Command for SearchCommand { }; let remaining = width - name_length - warning.len() as i64 - 2; let description = if description.len() as i64 > remaining { - format!("{}...", &description[..(remaining - 3) as usize]) + format!("{}...", substr(&description, 0, Some(remaining - 3))) } else { description }; -- cgit v1.3.1