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

[Xen-changelog] [qemu-xen master] hw/usb: avoid format truncation warning when formatting port name



commit dbf360567a7da50db4d2f9bde4649aba21aa8106
Author:     Daniel P. Berrangé <berrange@xxxxxxxxxx>
AuthorDate: Fri Apr 12 13:16:25 2019 +0100
Commit:     Anthony PERARD <anthony.perard@xxxxxxxxxx>
CommitDate: Tue Aug 6 10:56:54 2019 +0100

    hw/usb: avoid format truncation warning when formatting port name
    
    hw/usb/hcd-xhci.c: In function â??usb_xhci_realizeâ??:
    hw/usb/hcd-xhci.c:3339:66: warning: â??%dâ?? directive output may be 
truncated writing between 1 and 10 bytes into a region of size 5 
[-Wformat-trunca\
    tion=]
     3339 |             snprintf(port->name, sizeof(port->name), "usb2 port 
#%d", i+1);
          |                                                                  ^~
    hw/usb/hcd-xhci.c:3339:54: note: directive argument in the range [1, 
2147483647]
     3339 |             snprintf(port->name, sizeof(port->name), "usb2 port 
#%d", i+1);
          |                                                      ^~~~~~~~~~~~~~~
    
    The xhci code formats the port name into a fixed length
    buffer which is only large enough to hold port numbers
    upto 5 digits in decimal representation. We're never
    going to have a port number that large, so aserting the
    port number is sensible is sufficient to tell GCC the
    formatted string won't be truncated.
    
    Signed-off-by: Daniel P. Berrangé <berrange@xxxxxxxxxx>
    Message-Id: <20190412121626.19829-5-berrange@xxxxxxxxxx>
    
    [ kraxel: also s/int/unsigned int/ to tell gcc they can't
              go negative. ]
    
    Signed-off-by: Gerd Hoffmann <kraxel@xxxxxxxxxx>
    (cherry picked from commit ccb799313a5926a6aa49018bbc67fe6165fad7f3)
---
 hw/usb/hcd-xhci.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/hw/usb/hcd-xhci.c b/hw/usb/hcd-xhci.c
index ec28bee319..a2d55b19df 100644
--- a/hw/usb/hcd-xhci.c
+++ b/hw/usb/hcd-xhci.c
@@ -3306,7 +3306,7 @@ static void usb_xhci_init(XHCIState *xhci)
 {
     DeviceState *dev = DEVICE(xhci);
     XHCIPort *port;
-    int i, usbports, speedmask;
+    unsigned int i, usbports, speedmask;
 
     xhci->usbsts = USBSTS_HCH;
 
@@ -3336,6 +3336,7 @@ static void usb_xhci_init(XHCIState *xhci)
                 USB_SPEED_MASK_LOW  |
                 USB_SPEED_MASK_FULL |
                 USB_SPEED_MASK_HIGH;
+            assert(i < MAXPORTS);
             snprintf(port->name, sizeof(port->name), "usb2 port #%d", i+1);
             speedmask |= port->speedmask;
         }
@@ -3349,6 +3350,7 @@ static void usb_xhci_init(XHCIState *xhci)
             }
             port->uport = &xhci->uports[i];
             port->speedmask = USB_SPEED_MASK_SUPER;
+            assert(i < MAXPORTS);
             snprintf(port->name, sizeof(port->name), "usb3 port #%d", i+1);
             speedmask |= port->speedmask;
         }
--
generated by git-patchbot for /home/xen/git/qemu-xen.git#master

_______________________________________________
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®.