qemu-devel
[Top][All Lists]
Advanced

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

Re: [PATCH v2] hw/virtio/vhost-shadow-virtqueue: Silence GCC error "mayb


From: Richard Henderson
Subject: Re: [PATCH v2] hw/virtio/vhost-shadow-virtqueue: Silence GCC error "maybe-uninitialized"
Date: Sat, 10 Sep 2022 17:05:02 +0100
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.11.0

On 9/10/22 16:11, Bernhard Beschow wrote:
GCC issues a false positive warning, resulting in build failure with -Werror:

   In file included from /usr/include/glib-2.0/glib.h:114,
                    from src/include/glib-compat.h:32,
                    from src/include/qemu/osdep.h:144,
                    from ../src/hw/virtio/vhost-shadow-virtqueue.c:10:
   In function ‘g_autoptr_cleanup_generic_gfree’,
       inlined from ‘vhost_handle_guest_kick’ at 
../src/hw/virtio/vhost-shadow-virtqueue.c:292:42:
   /usr/include/glib-2.0/glib/glib-autocleanups.h:28:3: error: ‘elem’ may be 
used uninitialized [-Werror=maybe-uninitialized]
      28 |   g_free (*pp);
         |   ^~~~~~~~~~~~
   ../src/hw/virtio/vhost-shadow-virtqueue.c: In function 
‘vhost_handle_guest_kick’:
   ../src/hw/virtio/vhost-shadow-virtqueue.c:292:42: note: ‘elem’ was declared 
here
     292 |             g_autofree VirtQueueElement *elem;
         |                                          ^~~~
   cc1: all warnings being treated as errors

There is actually no problem since "elem" is initialized in both branches.
Silence the warning by initializig it with "NULL".

$ gcc --version
gcc (GCC) 12.2.0

Fixes: 9c2ab2f1ec333be8614cc12272d4b91960704dbe ("vhost: stop transfer elem 
ownership in vhost_handle_guest_kick")
Signed-off-by: Bernhard Beschow<shentey@gmail.com>
---
  hw/virtio/vhost-shadow-virtqueue.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)

It's not a false positive, but the fix is correct.

Reviewed-by: Richard Henderson <richard.henderson@linaro.org>


r~



reply via email to

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