summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohn Hawthorn <john@hawthorn.email>2020-08-08 19:42:58 -0700
committerJohn Hawthorn <john@hawthorn.email>2020-08-08 19:42:58 -0700
commit4baf608fd636624504c6a9c9389294023073ba9f (patch)
tree005ff5ea664860177310866e42553e6c153a7fff
parent43caa3daa912844e342fc520b4e60eb48e75c3a7 (diff)
Check for too long haystack
Fixes #145
-rw-r--r--src/match.c2
-rw-r--r--test/test_match.c13
2 files changed, 14 insertions, 1 deletions
diff --git a/src/match.c b/src/match.c
index a0c0785..d618f0a 100644
--- 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
index 17edba4..b601a4d 100644
--- 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);