From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:51371) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aL6Vn-0007MA-RZ for qemu-devel@nongnu.org; Mon, 18 Jan 2016 04:54:12 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1aL6Vk-0003Zs-K8 for qemu-devel@nongnu.org; Mon, 18 Jan 2016 04:54:11 -0500 Received: from mx1.redhat.com ([209.132.183.28]:39360) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aL6Vk-0003Zn-EF for qemu-devel@nongnu.org; Mon, 18 Jan 2016 04:54:08 -0500 Date: Mon, 18 Jan 2016 09:54:04 +0000 From: "Daniel P. Berrange" Message-ID: <20160118095404.GB13395@redhat.com> References: <56998731.8080307@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: <56998731.8080307@redhat.com> Subject: Re: [Qemu-devel] bug with io/channel-socket.c - variable-sized object may not be initialized Reply-To: "Daniel P. Berrange" List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Eric Blake Cc: Programmingkid , qemu-devel qemu-devel On Fri, Jan 15, 2016 at 04:56:33PM -0700, Eric Blake wrote: > On 01/13/2016 02:19 PM, Programmingkid wrote: > > This code causes an error to occur during compiling: > > > > char control[CMSG_SPACE(sizeof(int) * SOCKET_MAX_FDS)] = { 0 }; > > > > It is located at line 496 in io/channel-socket.c. > > > > Here is the full error message: > > io/channel-socket.c: In function 'qio_channel_socket_writev': > > io/channel-socket.c:496:18: error: variable-sized object may not be initialized > > char control[CMSG_SPACE(sizeof(int) * SOCKET_MAX_FDS)] = { 0 }; > > > > This is from gcc 4.9 running on Mac OS 10.6.8. > > Uggh. That sounds like a bug in the Mac OS headers, for making > CMSG_SPACE() not be a compile-time constant. We do NOT want to be using > variable-sized objects here, so we need a compile-time constant for the > array size, even if we have to work around your platform's borked headers. Note it only seems to be complaining about the initialization, not the actual declaration. We already have similar code in QEMU elsewhere eg qemu-char.c: char control[CMSG_SPACE(sizeof(int) * TCP_MAX_FDS)]; which presumably works on OS-X So the simple fix is to remove the '{ 0 }' initialization and just memset instead eg memset(control, 0, CMSG_SPACE(sizeof(int) * SOCKET_MAX_FDS)); Regards, Daniel -- |: http://berrange.com -o- http://www.flickr.com/photos/dberrange/ :| |: http://libvirt.org -o- http://virt-manager.org :| |: http://autobuild.org -o- http://search.cpan.org/~danberr/ :| |: http://entangle-photo.org -o- http://live.gnome.org/gtk-vnc :|