diff options
| author | Joseph Hunkeler <jhunkeler@gmail.com> | 2026-04-16 12:54:34 -0400 |
|---|---|---|
| committer | Joseph Hunkeler <jhunkeler@gmail.com> | 2026-04-16 12:54:34 -0400 |
| commit | fdad37bc1854a973424459026cc32698ff5fe532 (patch) | |
| tree | 7a4e7301d4ecb5c8ef4f5a81e6d20aed13638394 /tests | |
| parent | dc6b871b419159097c272fe21cdef6acece40a99 (diff) | |
| download | stasis-fdad37bc1854a973424459026cc32698ff5fe532.tar.gz | |
Convert more strcpy to strn variant
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/test_relocation.c | 2 | ||||
| -rw-r--r-- | tests/test_str.c | 9 | ||||
| -rw-r--r-- | tests/test_utils.c | 4 |
3 files changed, 7 insertions, 8 deletions
diff --git a/tests/test_relocation.c b/tests/test_relocation.c index 8a9beb6..69142dc 100644 --- a/tests/test_relocation.c +++ b/tests/test_relocation.c @@ -14,7 +14,7 @@ void test_replace_text() { const char *target = targets[i]; const char *expected = targets[i + 1]; char input[BUFSIZ] = {0}; - strcpy(input, test_string); + strncpy(input, test_string, sizeof(input) - 1); printf("input: %s\n", input); printf("target: %s\n", target); diff --git a/tests/test_str.c b/tests/test_str.c index a98a34d..5679078 100644 --- a/tests/test_str.c +++ b/tests/test_str.c @@ -37,7 +37,7 @@ void test_tolower_s() { for (size_t i = 0; i < sizeof(tc) / sizeof(*tc); i++) { char input[100] = {0}; - strcpy(input, tc[i].data); + strncpy(input, tc[i].data, sizeof(input) - 1); tolower_s(input); STASIS_ASSERT(strcmp(input, tc[i].expected) == 0, "unexpected result"); } @@ -318,7 +318,7 @@ void test_lstrip() { for (size_t i = 0; i < sizeof(tc) / sizeof(*tc); i++) { char *buf = calloc(255, sizeof(*buf)); char *result; - strcpy(buf, tc[i].data); + strncpy(buf, tc[i].data, sizeof(buf) - 1); result = lstrip(buf); STASIS_ASSERT(strcmp(result ? result : "", tc[i].expected) == 0, "incorrect strip-from-left"); guard_free(buf); @@ -342,9 +342,8 @@ void test_strip() { STASIS_ASSERT(strip(NULL) == NULL, "incorrect return type"); for (size_t i = 0; i < sizeof(tc) / sizeof(*tc); i++) { char *buf = calloc(255, sizeof(*buf)); - char *result; - strcpy(buf, tc[i].data); - result = strip(buf); + strncpy(buf, tc[i].data, sizeof(buf) - 1); + char *result = strip(buf); STASIS_ASSERT(strcmp(result ? result : "", tc[i].expected) == 0, "incorrect strip-from-right"); guard_free(buf); } diff --git a/tests/test_utils.c b/tests/test_utils.c index 1ad2335..79bca43 100644 --- a/tests/test_utils.c +++ b/tests/test_utils.c @@ -65,7 +65,7 @@ void test_fix_tox_conf() { if (fp) { fprintf(fp, "%s", data); fclose(fp); - STASIS_ASSERT(fix_tox_conf(filename, &result) == 0, "fix_tox_conf failed"); + STASIS_ASSERT(fix_tox_conf(filename, &result, PATH_MAX) == 0, "fix_tox_conf failed"); } else { STASIS_ASSERT(false, "writing mock tox.ini failed"); } @@ -308,7 +308,7 @@ void test_path_dirname() { const char *input = data[i]; const char *expected = data[i + 1]; char tmp[PATH_MAX] = {0}; - strcpy(tmp, input); + strncpy(tmp, input, sizeof(tmp) - 1); char *result = path_dirname(tmp); STASIS_ASSERT(strcmp(expected, result) == 0, NULL); |
