aboutsummaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/test_relocation.c1
-rw-r--r--tests/test_str.c3
-rw-r--r--tests/test_utils.c1
3 files changed, 5 insertions, 0 deletions
diff --git a/tests/test_relocation.c b/tests/test_relocation.c
index 69142dc..3454a69 100644
--- a/tests/test_relocation.c
+++ b/tests/test_relocation.c
@@ -15,6 +15,7 @@ void test_replace_text() {
const char *expected = targets[i + 1];
char input[BUFSIZ] = {0};
strncpy(input, test_string, sizeof(input) - 1);
+ input[sizeof(input) - 1] = '\0';
printf("input: %s\n", input);
printf("target: %s\n", target);
diff --git a/tests/test_str.c b/tests/test_str.c
index aac5d71..09d8809 100644
--- a/tests/test_str.c
+++ b/tests/test_str.c
@@ -38,6 +38,7 @@ void test_tolower_s() {
for (size_t i = 0; i < sizeof(tc) / sizeof(*tc); i++) {
char input[100] = {0};
strncpy(input, tc[i].data, sizeof(input) - 1);
+ input[sizeof(input) - 1] = '\0';
tolower_s(input);
STASIS_ASSERT(strcmp(input, tc[i].expected) == 0, "unexpected result");
}
@@ -318,6 +319,7 @@ void test_lstrip() {
for (size_t i = 0; i < sizeof(tc) / sizeof(*tc); i++) {
char *buf = calloc(255, sizeof(*buf));
strncpy(buf, tc[i].data, 254);
+ buf[254] = '\0';
char *result = lstrip(buf);
STASIS_ASSERT(strcmp(result ? result : "", tc[i].expected) == 0, "incorrect strip-from-left");
guard_free(buf);
@@ -342,6 +344,7 @@ void test_strip() {
for (size_t i = 0; i < sizeof(tc) / sizeof(*tc); i++) {
char *buf = calloc(255, sizeof(*buf));
strncpy(buf, tc[i].data, 254);
+ buf[254] = '\0';
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 a5faf5c..4f89509 100644
--- a/tests/test_utils.c
+++ b/tests/test_utils.c
@@ -312,6 +312,7 @@ void test_path_dirname() {
const char *expected = data[i + 1];
char tmp[PATH_MAX] = {0};
strncpy(tmp, input, sizeof(tmp) - 1);
+ tmp[sizeof(tmp) - 1] = '\0';
char *result = path_dirname(tmp);
STASIS_ASSERT(strcmp(expected, result) == 0, NULL);