qemu-devel
[Top][All Lists]
Advanced

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

Re: [Qemu-devel] [PATCH v2 4/5] hw/usb: avoid format truncation warning


From: Gerd Hoffmann
Subject: Re: [Qemu-devel] [PATCH v2 4/5] hw/usb: avoid format truncation warning when formatting port name
Date: Thu, 2 May 2019 08:44:00 +0200
User-agent: NeoMutt/20180716

On Fri, Apr 12, 2019 at 01:16:25PM +0100, Daniel P. Berrangé wrote:
> 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.

Picked into the usb queue.

thanks,
  Gerd




reply via email to

[Prev in Thread] Current Thread [Next in Thread]