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.
}
#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;