fzy
terminal fuzzy finder picker
git clone https://9o.is/git/fzy.git
commit 7d718ada1c7a356e59af210b7cc993308dd1546c parent 41e313b122b0663d8a7b385859ebe9677be94688 Author: John Hawthorn <john@hawthorn.email> Date: Sat, 8 Aug 2020 19:42:58 -0700 Check for too long haystack Fixes #145 Diffstat:
| M | src/match.c | | | 2 | +- |
| M | test/test_match.c | | | 13 | +++++++++++++ |
2 files changed, 14 insertions(+), 1 deletion(-)
diff --git a/src/match.c b/src/match.c @@ -56,7 +56,7 @@ static void setup_match_struct(struct match_struct *match, const char *needle, c match->needle_len = strlen(needle); match->haystack_len = strlen(haystack); - if (match->needle_len > MATCH_MAX_LEN || match->needle_len > match->haystack_len) { + if (match->haystack_len > MATCH_MAX_LEN || match->needle_len > match->haystack_len) { return; } diff --git a/test/test_match.c b/test/test_match.c @@ -131,6 +131,18 @@ TEST score_dot() { PASS(); } +TEST score_long_string() { + char string[4096]; + memset(string, 'a', sizeof(string) - 1); + string[sizeof(string) - 1] = '\0'; + + ASSERT_SCORE_EQ(SCORE_MIN, match("aa", string)); + ASSERT_SCORE_EQ(SCORE_MIN, match(string, "aa")); + ASSERT_SCORE_EQ(SCORE_MIN, match(string, string)); + + PASS(); +} + TEST positions_consecutive() { size_t positions[3]; match_positions("amo", "app/models/foo", positions); @@ -210,6 +222,7 @@ SUITE(match_suite) { RUN_TEST(score_slash); RUN_TEST(score_capital); RUN_TEST(score_dot); + RUN_TEST(score_long_string); RUN_TEST(positions_consecutive); RUN_TEST(positions_start_of_word);