From 171f25e1233547cd4a625b2b6a4d2acf0715383a Mon Sep 17 00:00:00 2001 From: Olaf Bergmann Date: Tue, 5 Jun 2018 12:28:40 +0200 Subject: [PATCH] client.c: fix -Wstringop-overflow warning in cmdline_token() Calling strncpy() on the variable (and erroneous) calculated token length in cmdline_token() has caused stringop-overflow warning by GCC 8. This change fixes the error and replaces strncpy() by memcpy() to quieten the compiler. --- examples/client.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/examples/client.c b/examples/client.c index 6ac00638..da147b59 100644 --- a/examples/client.c +++ b/examples/client.c @@ -802,8 +802,10 @@ cmdline_proxy(char *arg) { static inline void cmdline_token(char *arg) { - strncpy((char *)the_token.s, arg, min(sizeof(_token_data), strlen(arg))); - the_token.length = strlen(arg); + the_token.length = min(sizeof(_token_data), strlen(arg)); + if (the_token.length > 0) { + memcpy((char *)the_token.s, arg, the_token.length); + } } static void