[qemu-xen staging] dump: Fix build with newer gcc

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

[qemu-xen staging] dump: Fix build with newer gcc

patchbot
commit c8540ad7ca942a347db8ff6556320e7f192ec657
Author:     Eric Blake <[hidden email]>
AuthorDate: Tue Mar 27 15:21:51 2018 -0500
Commit:     Anthony PERARD <[hidden email]>
CommitDate: Fri May 11 11:22:24 2018 +0100

    dump: Fix build with newer gcc
   
    gcc 8 on rawhide is picky enough to complain:
   
    /home/dummy/qemu/dump.c: In function 'create_header32':
    /home/dummy/qemu/dump.c:817:5: error: 'strncpy' output truncated before terminating nul copying 8 bytes from a string of the same length [-Werror=stringop-truncation]
         strncpy(dh->signature, KDUMP_SIGNATURE, strlen(KDUMP_SIGNATURE));
         ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   
    But we already have SIG_LEN defined as the right length without needing
    to do a strlen(), and memcpy() is better than strncpy() when we know
    we do not want a trailing NUL byte.
   
    Signed-off-by: Eric Blake <[hidden email]>
    Signed-off-by: Paolo Bonzini <[hidden email]>
    (cherry picked from commit 84c868f6b8f8c1be9d3d65df93cf00b30821401c)
---
 dump.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/dump.c b/dump.c
index d4a8c942eb..dd066c00e9 100644
--- a/dump.c
+++ b/dump.c
@@ -813,7 +813,7 @@ static void create_header32(DumpState *s, Error **errp)
     size = sizeof(DiskDumpHeader32);
     dh = g_malloc0(size);
 
-    strncpy(dh->signature, KDUMP_SIGNATURE, strlen(KDUMP_SIGNATURE));
+    memcpy(dh->signature, KDUMP_SIGNATURE, SIG_LEN);
     dh->header_version = cpu_to_dump32(s, 6);
     block_size = s->dump_info.page_size;
     dh->block_size = cpu_to_dump32(s, block_size);
@@ -925,7 +925,7 @@ static void create_header64(DumpState *s, Error **errp)
     size = sizeof(DiskDumpHeader64);
     dh = g_malloc0(size);
 
-    strncpy(dh->signature, KDUMP_SIGNATURE, strlen(KDUMP_SIGNATURE));
+    memcpy(dh->signature, KDUMP_SIGNATURE, SIG_LEN);
     dh->header_version = cpu_to_dump32(s, 6);
     block_size = s->dump_info.page_size;
     dh->block_size = cpu_to_dump32(s, block_size);
--
generated by git-patchbot for /home/xen/git/qemu-xen.git#staging

_______________________________________________
Xen-changelog mailing list
[hidden email]
https://lists.xenproject.org/xen-changelog