qethqoat: Use util_strlcpy() to copy strings

Use the more robust util_strlcpy() to copy strings instead of strncpy().

This fixes the following GCC8 compile warnings:

qethqoat.c: In function ‘main’:
qethqoat.c:616:2: warning: ‘strncpy’ specified bound 16 equals
destination size [-Wstringop-truncation]
  strncpy(ifr.ifr_name, opts.ifname, IFNAMSIZ);
  ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Signed-off-by: Jan Höppner <hoeppner@linux.ibm.com>
This commit is contained in:
Jan Höppner
2018-11-08 15:56:46 +01:00
parent 773c8672ac
commit 2962248e7b
2 changed files with 6 additions and 2 deletions

View File

@@ -2,7 +2,9 @@ include ../common.mak
all: qethqoat
qethqoat: qethqoat.o
libs = $(rootdir)/libutil/libutil.a
qethqoat: qethqoat.o $(libs)
install: all
$(INSTALL) -d -m 755 $(DESTDIR)$(BINDIR) $(DESTDIR)$(MANDIR)/man8

View File

@@ -24,6 +24,7 @@
#include <sys/types.h>
#include <unistd.h>
#include "lib/util_libc.h"
#include "lib/zt_common.h"
#include "qethqoat.h"
@@ -541,6 +542,7 @@ int main(int argc, char **argv)
opts.raw = 0;
opts.scope = 1;
opts.file = NULL;
opts.ifname = NULL;
while ((c = getopt_long(argc, argv, qethqoat_opts_str, qethqoat_opts,
&index)) != -1) {
@@ -613,7 +615,7 @@ int main(int argc, char **argv)
return 1;
}
strncpy(ifr.ifr_name, opts.ifname, IFNAMSIZ);
util_strlcpy(ifr.ifr_name, opts.ifname, IFNAMSIZ);
oat_data.command = opts.scope;
ifr.ifr_ifru.ifru_data = (void *)&oat_data;