diff options
author | Joseph Hunkeler <jhunkeler@gmail.com> | 2024-06-10 07:55:52 -0400 |
---|---|---|
committer | Joseph Hunkeler <jhunkeler@gmail.com> | 2024-06-10 07:55:52 -0400 |
commit | 75aa8070cc66a1bd6d4d95ada02b87cf7c1bfa9e (patch) | |
tree | afe1bb67e62f2cf71652195cff272979c7065d1f | |
parent | a5144b9db2c8c77fbe7fa8e15e7d9e28920099d5 (diff) | |
download | ohmycal-75aa8070cc66a1bd6d4d95ada02b87cf7c1bfa9e.tar.gz |
strcmp_array expects NULL terminated array. Iterating by size in this case passes NULL to strcmp leading to an invalid read
-rw-r--r-- | tests/test_strlist.c | 6 |
1 files changed, 4 insertions, 2 deletions
diff --git a/tests/test_strlist.c b/tests/test_strlist.c index bdc0641..099ab3f 100644 --- a/tests/test_strlist.c +++ b/tests/test_strlist.c @@ -110,6 +110,7 @@ void test_strlist_append_file() { "Do not delete this file.\n", "Do not delete this file.\n", "Do not delete this file.\n", + NULL, }; const char *local_filename = "test_strlist_append_file.txt"; @@ -123,7 +124,7 @@ void test_strlist_append_file() { if (!fp) { OMC_ASSERT(false, "unable to open local file for writing"); } - for (size_t i = 0; i < sizeof(expected) / sizeof(*expected); i++) { + for (size_t i = 0; expected[i] != NULL; i++) { fprintf(fp, "%s", expected[i]); } fclose(fp); @@ -136,11 +137,12 @@ void test_strlist_append_file() { return; } strlist_append_file(list, (char *) tc[i].origin, NULL); - for (size_t z = 0; z < strlist_count(list) && expected[z] != NULL; z++) { + for (size_t z = 0; z < strlist_count(list); z++) { const char *left; const char *right; left = strlist_item(list, z); right = expected[z]; + printf("left = '%s', right = '%s'\n", left, right); OMC_ASSERT(strcmp(left, right) == 0, "file content is different than expected"); } OMC_ASSERT(strcmp_array(list->data, expected) == 0, "file contents does not match expected values"); |