All of lore.kernel.org
 help / color / mirror / Atom feed
* [Qemu-devel] bug with io/channel-socket.c - variable-sized object may not be initialized
@ 2016-01-13 21:19 Programmingkid
  2016-01-15 23:56 ` Eric Blake
  0 siblings, 1 reply; 4+ messages in thread
From: Programmingkid @ 2016-01-13 21:19 UTC (permalink / raw)
  To: qemu-devel qemu-devel

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. 

A quick fix to this problem is to replace everything in the parentheses with 1000. 

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [Qemu-devel] bug with io/channel-socket.c - variable-sized object may not be initialized
  2016-01-13 21:19 [Qemu-devel] bug with io/channel-socket.c - variable-sized object may not be initialized Programmingkid
@ 2016-01-15 23:56 ` Eric Blake
  2016-01-16 18:54   ` Programmingkid
  2016-01-18  9:54   ` Daniel P. Berrange
  0 siblings, 2 replies; 4+ messages in thread
From: Eric Blake @ 2016-01-15 23:56 UTC (permalink / raw)
  To: Programmingkid, qemu-devel qemu-devel

[-- Attachment #1: Type: text/plain, Size: 1300 bytes --]

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.

Can you capture what that line expands to after pre-processing, to see
if my guess is right?

> 
> A quick fix to this problem is to replace everything in the parentheses with 1000. 

Yeah, but that's probably wrong, unless we know for sure that
sizeof(int)*SOCKET_MAX_FDS will never exceed 1000; in that case, it's
probably over-allocating.

-- 
Eric Blake   eblake redhat com    +1-919-301-3266
Libvirt virtualization library http://libvirt.org


[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 604 bytes --]

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [Qemu-devel] bug with io/channel-socket.c - variable-sized object may not be initialized
  2016-01-15 23:56 ` Eric Blake
@ 2016-01-16 18:54   ` Programmingkid
  2016-01-18  9:54   ` Daniel P. Berrange
  1 sibling, 0 replies; 4+ messages in thread
From: Programmingkid @ 2016-01-16 18:54 UTC (permalink / raw)
  To: Eric Blake; +Cc: qemu-devel qemu-devel


On Jan 15, 2016, at 6:56 PM, 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.
> Can you capture what that line expands to after pre-processing, to see
> if my guess is right?

It expands to 76. 

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [Qemu-devel] bug with io/channel-socket.c - variable-sized object may not be initialized
  2016-01-15 23:56 ` Eric Blake
  2016-01-16 18:54   ` Programmingkid
@ 2016-01-18  9:54   ` Daniel P. Berrange
  1 sibling, 0 replies; 4+ messages in thread
From: Daniel P. Berrange @ 2016-01-18  9:54 UTC (permalink / raw)
  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 :|

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2016-01-18  9:54 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-01-13 21:19 [Qemu-devel] bug with io/channel-socket.c - variable-sized object may not be initialized Programmingkid
2016-01-15 23:56 ` Eric Blake
2016-01-16 18:54   ` Programmingkid
2016-01-18  9:54   ` Daniel P. Berrange

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.