Skip to content

Commit

Permalink
tests: fix strncpy warning
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
qlyoung committed Jul 24, 2023
1 parent 90f1e4e commit 64c549e
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions tests/lib/test_nexthop_iter.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 64c549e

Please sign in to comment.