[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PATCH 07/14] hw/usb: avoid format truncation warning when
From: |
Daniel P . Berrangé |
Subject: |
[Qemu-devel] [PATCH 07/14] hw/usb: avoid format truncation warning when formatting port name |
Date: |
Fri, 29 Mar 2019 11:10:57 +0000 |
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>
---
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 ec28bee319..7222f9b1af 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.20.1
- [Qemu-devel] [PATCH 00/14] misc set of fixes for warnings under GCC 9, Daniel P . Berrangé, 2019/03/29
- [Qemu-devel] [PATCH 01/14] target/xtensa: fix break_dependency for repeated resources, Daniel P . Berrangé, 2019/03/29
- [Qemu-devel] [PATCH 02/14] target/xtensa: don't announce exit simcall, Daniel P . Berrangé, 2019/03/29
- [Qemu-devel] [PATCH 03/14] tests/tcg/xtensa: clean up test set, Daniel P . Berrangé, 2019/03/29
- [Qemu-devel] [PATCH 04/14] linux-user: avoid string truncation warnings in uname field copying, Daniel P . Berrangé, 2019/03/29
- [Qemu-devel] [PATCH 05/14] linux-user: avoid string truncation warnings in elf field copying, Daniel P . Berrangé, 2019/03/29
- [Qemu-devel] [PATCH 06/14] sockets: avoid string truncation warnings when copying UNIX path, Daniel P . Berrangé, 2019/03/29
- [Qemu-devel] [PATCH 07/14] hw/usb: avoid format truncation warning when formatting port name,
Daniel P . Berrangé <=
- [Qemu-devel] [PATCH 09/14] usb-mtp: fix string length for filename when writing metadata, Daniel P . Berrangé, 2019/03/29
- [Qemu-devel] [PATCH 08/14] qxl: avoid unaligned pointer reads/writes, Daniel P . Berrangé, 2019/03/29
- [Qemu-devel] [PATCH 10/14] usb-mtp: avoid warning about unaligned access to filename, Daniel P . Berrangé, 2019/03/29
- [Qemu-devel] [PATCH 11/14] hw/vfio/ccw: avoid taking address members in packed structs, Daniel P . Berrangé, 2019/03/29