From: Oliver Kurth Date: Fri, 7 Sep 2018 22:53:27 +0000 (-0700) Subject: Fix a gcc-8 compiler warning in lib/misc/vthreadBase.c X-Git-Tag: stable-10.3.5~17 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=5a6e8bc0ef8af2eedbbc4dc1973cb7fe18afa939;p=thirdparty%2Fopen-vm-tools.git Fix a gcc-8 compiler warning in lib/misc/vthreadBase.c gcc-8 generates a stringop-truncation warning when it's possible for strncpy to exclude the trailing nul. The code was fine, we never touch the last byte in the buffer and it's a static, but explicitly set a nul at the end of the buffer so gcc sees it. This is needed for open-vm-tools to build on Suse Tumbleweed. --- diff --git a/open-vm-tools/lib/misc/vthreadBase.c b/open-vm-tools/lib/misc/vthreadBase.c index 328a37c22..350d4e32f 100644 --- a/open-vm-tools/lib/misc/vthreadBase.c +++ b/open-vm-tools/lib/misc/vthreadBase.c @@ -481,8 +481,15 @@ VThreadBase_SetName(const char *name) // IN: new name } #if defined VMW_HAVE_TLS - /* Never copy last byte; this ensures NUL-term is always present */ + /* + * Never copy last byte; this ensures NUL-term is always present. + * The NUL-term is always present because vthreadName is static, + * but gcc-8 generates a warning if it doesn't see it being explicilty + * set. + */ + strncpy(vthreadName, name, sizeof vthreadName - 1); + vthreadName[sizeof vthreadName - 1] = '\0'; #else do { char *buf;