even better strings

This commit is contained in:
Evan Burkey 2023-12-03 17:52:55 -08:00
parent 2c024d2667
commit 9eb12e40e2
2 changed files with 11 additions and 0 deletions

View File

@ -12,6 +12,9 @@ int find_substrings(const char* haystack, const char* needle, size_t *num_substr
size_t sz_h = strlen(haystack);
size_t sz_n = strlen(needle);
if ((int)sz_h - (int)sz_n < 0) {
return 0;
}
*num_substrings = 0;
for (size_t i = 0; i <= sz_h - sz_n; ++i) {

View File

@ -285,6 +285,14 @@ void test_string() {
subs = NULL;
find_substrings("test one two", "nope", &sub_sz, &subs);
assert(sub_sz == 0);
assert(subs == NULL);
free(subs);
subs = NULL;
find_substrings("123", "nopes", &sub_sz, &subs);
assert(sub_sz == 0);
assert(subs == NULL);
free(subs);
subs = NULL;