summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorQuentin Young <qlyoung@qlyoung.net>2023-07-24 19:01:51 -0400
committerQuentin Young <qlyoung@qlyoung.net>2023-07-24 19:03:24 -0400
commit64c549e68ce0ffbf92ab5965d6f66c13bcd33566 (patch)
tree44f044959afd542d5912750fbb2ecec124e88e8e
parent90f1e4e01781ffdba13a65577329e6380d96cee5 (diff)
tests: fix strncpy warning
GCC/clang warns about using strncpy in such a way that it does not copy the null byte of a string; as implemented it was fine, but to fix the warning, just use strlcat which was purpose made for the task being accomplished here. Signed-off-by: Quentin Young <qlyoung@qlyoung.net>
-rw-r--r--tests/lib/test_nexthop_iter.c5
1 files changed, 3 insertions, 2 deletions
diff --git a/tests/lib/test_nexthop_iter.c b/tests/lib/test_nexthop_iter.c
index 91380f1111..33ff116890 100644
--- a/tests/lib/test_nexthop_iter.c
+++ b/tests/lib/test_nexthop_iter.c
@@ -19,9 +19,10 @@ static int verbose;
static void str_append(char **buf, const char *repr)
{
if (*buf) {
- *buf = realloc(*buf, strlen(*buf) + strlen(repr) + 1);
+ size_t new_size = strlen(*buf) + strlen(repr) + 1;
+ *buf = realloc(*buf, new_size);
assert(*buf);
- strncpy((*buf) + strlen(*buf), repr, strlen(repr) + 1);
+ (void)strlcat(*buf, repr, new_size);
} else {
*buf = strdup(repr);
assert(*buf);