]> xenbits.xensource.com Git - qemu-xen.git/commit
usb: Fix build with newer gcc
authorEric Blake <eblake@redhat.com>
Mon, 17 Jul 2017 15:13:34 +0000 (10:13 -0500)
committerAnthony PERARD <anthony.perard@citrix.com>
Mon, 9 Jul 2018 11:37:56 +0000 (12:37 +0100)
commitc089583e504df752f98008319a6a48aee16b2059
tree9b548f8f29e37b2809a67817fd24470a28cf0dea
parente05274ac9a75e58ffe75cf083ac821bb6079ccee
usb: Fix build with newer gcc

gcc 7 is pickier about our sources:

hw/usb/bus.c: In function ‘usb_port_location’:
hw/usb/bus.c:410:66: error: ‘%d’ directive output may be truncated writing between 1 and 11 bytes into a region of size between 0 and 15 [-Werror=format-truncation=]
         snprintf(downstream->path, sizeof(downstream->path), "%s.%d",
                                                                  ^~
hw/usb/bus.c:410:9: note: ‘snprintf’ output between 3 and 28 bytes into a destination of size 16
         snprintf(downstream->path, sizeof(downstream->path), "%s.%d",
         ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
                  upstream->path, portnr);
                  ~~~~~~~~~~~~~~~~~~~~~~~

But we know that there are at most 5 levels of USB hubs, with at
most two digits per level; that plus the separating dots means we
use at most 15 bytes (including trailing NUL) of our 16-byte field.
Adding an assertion to show gcc that we checked for truncation is
enough to shut up the false-positive warning.

Inspired by an idea by Dr. David Alan Gilbert <dgilbert@redhat.com>.

Signed-off-by: Eric Blake <eblake@redhat.com>
Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
Message-id: 20170717151334.17954-1-eblake@redhat.com
Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
(cherry picked from commit 121829cb2160e9cd82482c1542699fa589688106)
hw/usb/bus.c