[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Xen-changelog] [qemu-xen stable-4.9] usb: Fix build with newer gcc



commit c089583e504df752f98008319a6a48aee16b2059
Author:     Eric Blake <eblake@xxxxxxxxxx>
AuthorDate: Mon Jul 17 10:13:34 2017 -0500
Commit:     Anthony PERARD <anthony.perard@xxxxxxxxxx>
CommitDate: Mon Jul 9 12:37:56 2018 +0100

    usb: Fix build with newer gcc
    
    gcc 7 is pickier about our sources:
    
    hw/usb/bus.c: In function â??usb_port_locationâ??:
    hw/usb/bus.c:410:66: error: â??%dâ?? directive output may be truncated 
writing between 1 and 11 bytes into a region of size between 0 and 15 
[-Werror=format-truncation=]
             snprintf(downstream->path, sizeof(downstream->path), "%s.%d",
                                                                      ^~
    hw/usb/bus.c:410:9: note: â??snprintfâ?? output between 3 and 28 bytes into 
a destination of size 16
             snprintf(downstream->path, sizeof(downstream->path), "%s.%d",
             ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
                      upstream->path, portnr);
                      ~~~~~~~~~~~~~~~~~~~~~~~
    
    But we know that there are at most 5 levels of USB hubs, with at
    most two digits per level; that plus the separating dots means we
    use at most 15 bytes (including trailing NUL) of our 16-byte field.
    Adding an assertion to show gcc that we checked for truncation is
    enough to shut up the false-positive warning.
    
    Inspired by an idea by Dr. David Alan Gilbert <dgilbert@xxxxxxxxxx>.
    
    Signed-off-by: Eric Blake <eblake@xxxxxxxxxx>
    Reviewed-by: Philippe Mathieu-Daudé <f4bug@xxxxxxxxx>
    Message-id: 20170717151334.17954-1-eblake@xxxxxxxxxx
    Signed-off-by: Gerd Hoffmann <kraxel@xxxxxxxxxx>
    (cherry picked from commit 121829cb2160e9cd82482c1542699fa589688106)
---
 hw/usb/bus.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/hw/usb/bus.c b/hw/usb/bus.c
index 25913ad488..9c4e5cbcf8 100644
--- a/hw/usb/bus.c
+++ b/hw/usb/bus.c
@@ -406,8 +406,10 @@ void usb_register_companion(const char *masterbus, USBPort 
*ports[],
 void usb_port_location(USBPort *downstream, USBPort *upstream, int portnr)
 {
     if (upstream) {
-        snprintf(downstream->path, sizeof(downstream->path), "%s.%d",
-                 upstream->path, portnr);
+        int l = snprintf(downstream->path, sizeof(downstream->path), "%s.%d",
+                         upstream->path, portnr);
+        /* Max string is nn.nn.nn.nn.nn, which fits in 16 bytes */
+        assert(l < sizeof(downstream->path));
         downstream->hubcount = upstream->hubcount + 1;
     } else {
         snprintf(downstream->path, sizeof(downstream->path), "%d", portnr);
--
generated by git-patchbot for /home/xen/git/qemu-xen.git#stable-4.9

_______________________________________________
Xen-changelog mailing list
Xen-changelog@xxxxxxxxxxxxxxxxxxxx
https://lists.xenproject.org/xen-changelog

 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.