[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Qemu-devel] [PATCH] pci: Fix compiler warning (MinGW-w64 gcc 4.9)
From: |
Eric Blake |
Subject: |
Re: [Qemu-devel] [PATCH] pci: Fix compiler warning (MinGW-w64 gcc 4.9) |
Date: |
Thu, 14 May 2015 15:06:28 -0600 |
User-agent: |
Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Thunderbird/31.6.0 |
On 05/14/2015 02:38 PM, Stefan Weil wrote:
> i686-w64-mingw32-gcc 4.9.1 from Debian Jessie complains:
>
> hw/pci/pci.c:938:29: warning:
> array subscript is above array bounds [-Warray-bounds]
>
> Using g_assert instead of assert fixes this warning.
Is that because the mingw headers don't properly mark the expansion of
the failed branch of assert() as noreturn, whereas g_assert() does, and
therefore the compiler has more information about what variables must be
if the rest of the function is reached?
>
> Signed-off-by: Stefan Weil <address@hidden>
> ---
> hw/pci/pci.c | 4 ++--
> 1 file changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/hw/pci/pci.c b/hw/pci/pci.c
> index 48f19a3..34f71dc 100644
> --- a/hw/pci/pci.c
> +++ b/hw/pci/pci.c
> @@ -927,8 +927,8 @@ void pci_register_bar(PCIDevice *pci_dev, int region_num,
> uint64_t wmask;
> pcibus_t size = memory_region_size(memory);
>
> - assert(region_num >= 0);
> - assert(region_num < PCI_NUM_REGIONS);
> + g_assert(region_num >= 0);
> + g_assert(region_num < PCI_NUM_REGIONS);
I must say, this is the strangest way I've ever heard of silencing a
compiler warning. But if it works and my uneducated guess above about
why is correct,
Reviewed-by: Eric Blake <address@hidden>
Meanwhile, you may want to file a bug to the mingw maintainers that
their header is puny when compared to glibc assert() or to glib's
g_assert, when it comes to giving gcc decent hints.
--
Eric Blake eblake redhat com +1-919-301-3266
Libvirt virtualization library http://libvirt.org
signature.asc
Description: OpenPGP digital signature