[virt-tools-list] [virt-viewer PATCH v2 2/3] Fix warning about missing nul terminator with strncpy

Daniel P. Berrangé berrange at redhat.com
Tue Feb 19 15:00:10 UTC 2019


We're intentionally not copying the nul terminator, but gcc rightly
worries that this could be a coding mistake

windows-cmdline-wrapper.c: In function 'main':
windows-cmdline-wrapper.c:65:9: warning: 'strncpy' output truncated before terminating nul copying 3 bytes from a string of the same length [-Wstringop-truncation]
         strncpy(name + len - 3, "exe", 3);
         ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Use memcpy() to make it clear we don't care about the nul terminator in
the data we're copying.

Signed-off-by: Daniel P. Berrangé <berrange at redhat.com>
---
 src/windows-cmdline-wrapper.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/src/windows-cmdline-wrapper.c b/src/windows-cmdline-wrapper.c
index 704e2d7..7299ab2 100644
--- a/src/windows-cmdline-wrapper.c
+++ b/src/windows-cmdline-wrapper.c
@@ -62,7 +62,7 @@ int main(int argc, char *argv[])
         // We expect our helper to end with .com
         assert(strncmp(name + len - 3, "com", 4) == 0);
         // replace .com with .exe
-        strncpy(name + len - 3, "exe", 3);
+        memcpy(name + len - 3, "exe", 3);
     }
 
     si.cb = sizeof(si);
-- 
2.20.1




More information about the virt-tools-list mailing list