]> git.ipfire.org Git - thirdparty/open-vm-tools.git/commitdiff
Fix a gcc-8 compiler warning in lib/misc/vthreadBase.c
authorOliver Kurth <okurth@vmware.com>
Fri, 7 Sep 2018 22:53:27 +0000 (15:53 -0700)
committerOliver Kurth <okurth@vmware.com>
Fri, 7 Sep 2018 22:53:27 +0000 (15:53 -0700)
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

index 328a37c2215b407572d8a61de5665e921ff5beeb..350d4e32f84effe07d5faffc7315f7de74913b37 100644 (file)
@@ -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;