From 5a6e8bc0ef8af2eedbbc4dc1973cb7fe18afa939 Mon Sep 17 00:00:00 2001 From: Oliver Kurth Date: Fri, 7 Sep 2018 15:53:27 -0700 Subject: [PATCH] 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. --- open-vm-tools/lib/misc/vthreadBase.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) 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; -- 2.47.3