From: Bruce Rogers <brogers@suse.com>
Date: Thu, 3 Dec 2020 16:48:13 -0700
Subject: usb: Help compiler out to avoid a warning on x86 compilation
Git-commit: 0000000000000000000000000000000000000000
Include-If: %ifarch %arm %ix86 ppc
There is an assert present which already should give the compiler
enough information about the value of i as used in the snprintf,
but if I remember right, for x86, because memory is tighter some of
the compiler smarts are turned off, so we get the uninformed warning
there and not on other archs. So on x86 only we'll add some code to
help the compiler out, so we can again compile qemu with
--enable-werror.
Signed-off-by: Bruce Rogers <brogers@suse.com>
---
hw/usb/hcd-xhci.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/hw/usb/hcd-xhci.c b/hw/usb/hcd-xhci.c
index 0cd0a5e540272a4183176ce8426d..2af21f0af68da3cd9d10f0e41f84 100644
--- a/hw/usb/hcd-xhci.c
+++ b/hw/usb/hcd-xhci.c
@@ -3314,7 +3314,7 @@ static void usb_xhci_init(XHCIState *xhci)
USB_SPEED_MASK_FULL |
USB_SPEED_MASK_HIGH;
assert(i < XHCI_MAXPORTS);
- snprintf(port->name, sizeof(port->name), "usb2 port #%d", i+1);
+ snprintf(port->name, sizeof(port->name), "usb2 port #%d", i+1 < XHCI_MAXPORTS ? i+1 : 0);
speedmask |= port->speedmask;
}
if (i < xhci->numports_3) {
@@ -3328,7 +3328,7 @@ static void usb_xhci_init(XHCIState *xhci)
port->uport = &xhci->uports[i];
port->speedmask = USB_SPEED_MASK_SUPER;
- snprintf(port->name, sizeof(port->name), "usb3 port #%d", i+1);
+ snprintf(port->name, sizeof(port->name), "usb3 port #%d", i+1 < XHCI_MAXPORTS ? i+1 : 0);
usb_register_port(&xhci->bus, &xhci->uports[i], xhci, i,