about summary refs log tree commit diff stats
path: root/tests/unittests
diff options
context:
space:
mode:
authorSteffen Jaeckel <jaeckel-floss@eyet-services.de>2023-03-10 14:51:43 +0100
committerSteffen Jaeckel <jaeckel-floss@eyet-services.de>2023-03-11 15:05:03 +0100
commit2925e85cd6e6c63ce5ba716e5de9d24066e9aebc (patch)
tree735f9d7daca57d706f2f826a2ff00de8a7e1554a /tests/unittests
parente99c4b7128f5c95cf8665ef969848defa0d3bbd7 (diff)
downloadprofani-tty-2925e85cd6e6c63ce5ba716e5de9d24066e9aebc.tar.gz
add test-case for #1761
Signed-off-by: Steffen Jaeckel <jaeckel-floss@eyet-services.de>
Diffstat (limited to 'tests/unittests')
-rw-r--r--tests/unittests/test_common.c22
-rw-r--r--tests/unittests/test_common.h1
-rw-r--r--tests/unittests/unittests.c1
3 files changed, 24 insertions, 0 deletions
diff --git a/tests/unittests/test_common.c b/tests/unittests/test_common.c
index fa5dd59e..3812cccb 100644
--- a/tests/unittests/test_common.c
+++ b/tests/unittests/test_common.c
@@ -536,6 +536,28 @@ _lists_equal(GSList* a, GSList* b)
 }
 
 void
+prof_occurrences_of_large_message_tests(void** state)
+{
+    GSList* actual = NULL;
+    GSList* expected = NULL;
+    /* use this with the old implementation to create a segfault
+     *     const size_t haystack_sz = 1024 * 1024;
+     */
+    const size_t haystack_sz = 1024;
+    size_t haystack_cur = 0;
+    char* haystack = malloc(haystack_sz);
+    const char needle[] = "needle ";
+    while (haystack_sz - haystack_cur > sizeof(needle)) {
+        memcpy(&haystack[haystack_cur], needle, sizeof(needle) - 1);
+        expected = g_slist_append(expected, GINT_TO_POINTER(haystack_cur));
+        haystack_cur += sizeof(needle) - 1;
+    }
+    assert_true(_lists_equal(prof_occurrences("needle", haystack, 0, FALSE, &actual), expected));
+    g_slist_free(actual);
+    g_slist_free(expected);
+}
+
+void
 prof_partial_occurrences_tests(void** state)
 {
     GSList* actual = NULL;
diff --git a/tests/unittests/test_common.h b/tests/unittests/test_common.h
index 46d990d9..ffcc6c9d 100644
--- a/tests/unittests/test_common.h
+++ b/tests/unittests/test_common.h
@@ -31,5 +31,6 @@ void strip_quotes_strips_last(void** state);
 void strip_quotes_strips_both(void** state);
 void prof_partial_occurrences_tests(void** state);
 void prof_whole_occurrences_tests(void** state);
+void prof_occurrences_of_large_message_tests(void** state);
 void unique_filename_from_url_td(void** state);
 void format_call_external_argv_td(void** state);
diff --git a/tests/unittests/unittests.c b/tests/unittests/unittests.c
index e2293004..2724aaa2 100644
--- a/tests/unittests/unittests.c
+++ b/tests/unittests/unittests.c
@@ -620,6 +620,7 @@ main(int argc, char* argv[])
 
         unit_test(prof_partial_occurrences_tests),
         unit_test(prof_whole_occurrences_tests),
+        unit_test(prof_occurrences_of_large_message_tests),
 
         unit_test(returns_no_commands),
         unit_test(returns_commands),