From b99005747308d8f8af0da5c427f414b15d5e919e Mon Sep 17 00:00:00 2001 From: Kitsu Date: Sun, 27 Dec 2020 09:03:35 +0300 Subject: [PATCH] Fix indexing on non-matching tail substring --- src/draw/list_view.rs | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) diff --git a/src/draw/list_view.rs b/src/draw/list_view.rs index 60e6285..ffbaa86 100644 --- a/src/draw/list_view.rs +++ b/src/draw/list_view.rs @@ -139,7 +139,7 @@ where let match_ranges = item.match_mask.unwrap_or(&empty); fn substr<'a, 'b: 'a>(x: &'b str, r: &Range) -> &'a str { - assert!(r.end <= x.chars().count()); + debug_assert!(r.end <= x.chars().count()); let start = x .char_indices() .nth(r.start) @@ -202,14 +202,9 @@ where (draw_substr!(&range, pos, color), range.end) }); - dt.draw_text( - &self.params.font, - font_size, - substr(item.name, &(idx..item.name.len())), - pos, - &Source::Solid(color), - &draw_opts, - ); + let tail_str = substr(item.name, &(idx..item.name.chars().count())); + let color = Source::Solid(color); + dt.draw_text(&font, font_size, tail_str, pos, &color, &draw_opts); } else { dt.draw_text( &self.params.font,