[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PULL 7/7] hw/usb: avoid format truncation warning when for
From: |
Gerd Hoffmann |
Subject: |
[Qemu-devel] [PULL 7/7] hw/usb: avoid format truncation warning when formatting port name |
Date: |
Thu, 2 May 2019 09:35:43 +0200 |
From: Daniel P. Berrangé <address@hidden>
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é <address@hidden>
Message-Id: <address@hidden>
Signed-off-by: Gerd Hoffmann <address@hidden>
---
hw/usb/hcd-xhci.c | 2 ++
1 file changed, 2 insertions(+)
diff --git a/hw/usb/hcd-xhci.c b/hw/usb/hcd-xhci.c
index d8472b4fea7f..9f8f9e45eceb 100644
--- a/hw/usb/hcd-xhci.c
+++ b/hw/usb/hcd-xhci.c
@@ -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;
}
--
2.18.1
- [Qemu-devel] [PULL 0/7] Usb 20190502 patches, Gerd Hoffmann, 2019/05/02
- [Qemu-devel] [PULL 1/7] usb-mtp: fix string length for filename when writing metadata, Gerd Hoffmann, 2019/05/02
- [Qemu-devel] [PULL 2/7] usb-mtp: fix alignment of access of ObjectInfo filename field, Gerd Hoffmann, 2019/05/02
- [Qemu-devel] [PULL 5/7] hw/usb/hcd-ohci: Do not use PCI functions with sysbus devices in ohci_die(), Gerd Hoffmann, 2019/05/02
- [Qemu-devel] [PULL 4/7] usb/xhci: avoid trigger assertion if guest write wrong epid, Gerd Hoffmann, 2019/05/02
- [Qemu-devel] [PULL 7/7] hw/usb: avoid format truncation warning when formatting port name,
Gerd Hoffmann <=
- [Qemu-devel] [PULL 6/7] hw/usb/hcd-ohci: Move PCI-related code into a separate file, Gerd Hoffmann, 2019/05/02
- [Qemu-devel] [PULL 3/7] usb-mtp: change default to success for usb_mtp_update_object, Gerd Hoffmann, 2019/05/02
- Re: [Qemu-devel] [PULL 0/7] Usb 20190502 patches, Peter Maydell, 2019/05/02