On Mon, Aug 22, 2022 at 9:42 AM Min Zhou <zhou...@loongson.cn> wrote: > > This patch fixes the following build failure seen on CentOS 8 > with gcc 12.1 because of uninitialized struct variable: > > [..] > ../lib/vhost/virtio_net.c:1159:18: warning: 'buf_vec[0].buf_addr' may be used > uninitialized [-Wmaybe-uninitialized] > 1159 | buf_addr = buf_vec[vec_idx].buf_addr; > | ~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~ > [..]
I don't like setting the whole variable to 0 just to silence a warning, like pushing something under the rug. This is all the more suspicious as there is other code in this file that does almost the same. I had seen a similar warning during 22.07 when cross compiling but did not investigate much. The patch that I had written at the time was: diff --git a/lib/vhost/virtio_net.c b/lib/vhost/virtio_net.c index 35fa4670fd..9446e33aa7 100644 --- a/lib/vhost/virtio_net.c +++ b/lib/vhost/virtio_net.c @@ -1153,7 +1153,7 @@ mbuf_to_desc(struct virtio_net *dev, struct vhost_virtqueue *vq, struct virtio_net_hdr_mrg_rxbuf tmp_hdr, *hdr = NULL; struct vhost_async *async = vq->async; - if (unlikely(m == NULL)) + if (unlikely(m == NULL || nr_vec == 0)) return -1; buf_addr = buf_vec[vec_idx].buf_addr; Could you see if this fixes your issue? If it is the case, it may be worth better understanding what bothers the compiler in the current code. -- David Marchand