From: "Daniel P. Berrangé" <berrange@redhat.com>
To: "Philippe Mathieu-Daudé" <philmd@redhat.com>
Cc: Gerd Hoffmann <kraxel@redhat.com>,
Aurelien Jarno <aurelien@aurel32.net>,
qemu-devel@nongnu.org
Subject: Re: [Qemu-devel] [PULL 7/7] hw/usb: avoid format truncation warning when formatting port name
Date: Mon, 18 Jan 2021 11:35:38 +0000 [thread overview]
Message-ID: <20210118113538.GF1789637@redhat.com> (raw)
In-Reply-To: <227c9e6b-61e4-d9ec-1b4b-b33d6323bbd9@redhat.com>
On Mon, Jan 18, 2021 at 12:31:07PM +0100, Philippe Mathieu-Daudé wrote:
> Hello,
>
> On 5/3/19 8:59 AM, Gerd Hoffmann wrote:
> > From: Daniel P. Berrangé <berrange@redhat.com>
> >
> > 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@redhat.com>
> > Message-Id: <20190412121626.19829-5-berrange@redhat.com>
> >
> > [ kraxel: also s/int/unsigned int/ to tell gcc they can't
> > go negative. ]
> >
> > Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
> > ---
> > 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 d8472b4fea7f..2e9a839f2bf9 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;
> > }
> >
>
> I am confused, I upgraded Fedora 32 -> 33 and am now getting this
> error back, the assertion being apparently ignored:
I'm not seeing this on F33 myself, but our CI is still F32. We
should upgrade that.
What are your configure args ?
Regards,
Daniel
--
|: https://berrange.com -o- https://www.flickr.com/photos/dberrange :|
|: https://libvirt.org -o- https://fstop138.berrange.com :|
|: https://entangle-photo.org -o- https://www.instagram.com/dberrange :|
next prev parent reply other threads:[~2021-01-18 11:40 UTC|newest]
Thread overview: 23+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-05-03 6:59 [Qemu-devel] [PULL 0/7] Usb 20190503 v2 patches Gerd Hoffmann
2019-05-03 6:59 ` Gerd Hoffmann
2019-05-03 6:59 ` [Qemu-devel] [PULL 1/7] usb-mtp: fix string length for filename when writing metadata Gerd Hoffmann
2019-05-03 6:59 ` Gerd Hoffmann
2019-05-03 6:59 ` [Qemu-devel] [PULL 2/7] usb-mtp: fix alignment of access of ObjectInfo filename field Gerd Hoffmann
2019-05-03 6:59 ` Gerd Hoffmann
2019-05-03 6:59 ` [Qemu-devel] [PULL 3/7] usb-mtp: change default to success for usb_mtp_update_object Gerd Hoffmann
2019-05-03 6:59 ` Gerd Hoffmann
2019-05-03 6:59 ` [Qemu-devel] [PULL 4/7] usb/xhci: avoid trigger assertion if guest write wrong epid Gerd Hoffmann
2019-05-03 6:59 ` Gerd Hoffmann
2019-05-03 6:59 ` [Qemu-devel] [PULL 5/7] hw/usb/hcd-ohci: Do not use PCI functions with sysbus devices in ohci_die() Gerd Hoffmann
2019-05-03 6:59 ` Gerd Hoffmann
2019-05-03 6:59 ` [Qemu-devel] [PULL 6/7] hw/usb/hcd-ohci: Move PCI-related code into a separate file Gerd Hoffmann
2019-05-03 6:59 ` Gerd Hoffmann
2019-05-03 6:59 ` [Qemu-devel] [PULL 7/7] hw/usb: avoid format truncation warning when formatting port name Gerd Hoffmann
2019-05-03 6:59 ` Gerd Hoffmann
2021-01-18 11:31 ` Philippe Mathieu-Daudé
2021-01-18 11:35 ` Daniel P. Berrangé [this message]
2021-01-18 11:40 ` Philippe Mathieu-Daudé
2019-05-03 13:56 ` [Qemu-devel] [PULL 0/7] Usb 20190503 v2 patches Peter Maydell
2019-05-03 13:56 ` Peter Maydell
-- strict thread matches above, loose matches on Subject: below --
2019-05-02 7:35 [Qemu-devel] [PULL 0/7] Usb 20190502 patches Gerd Hoffmann
2019-05-02 7:35 ` [Qemu-devel] [PULL 7/7] hw/usb: avoid format truncation warning when formatting port name Gerd Hoffmann
2019-05-02 7:35 ` Gerd Hoffmann
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20210118113538.GF1789637@redhat.com \
--to=berrange@redhat.com \
--cc=aurelien@aurel32.net \
--cc=kraxel@redhat.com \
--cc=philmd@redhat.com \
--cc=qemu-devel@nongnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).