io: use memset instead of { 0 } for initializing array

Some versions of GCC on OS-X complain about CMSG_SPACE
not being constant size, which prevents use of { 0 }

io/channel-socket.c: In function 'qio_channel_socket_writev':
io/channel-socket.c:497:18: error: variable-sized object may not be initialized
     char control[CMSG_SPACE(sizeof(int) * SOCKET_MAX_FDS)] = { 0 };

The compiler is at fault here, but it is nicer to avoid
tickling this compiler bug by using memset instead.

Reviewed-By: John Arbuckle <programmingkidx@gmail.com>
Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
This commit is contained in:
Daniel P. Berrange 2016-01-18 10:37:21 +00:00
parent 821791b505
commit ccf1e2dcd6

View File

@ -449,6 +449,8 @@ static ssize_t qio_channel_socket_readv(QIOChannel *ioc,
char control[CMSG_SPACE(sizeof(int) * SOCKET_MAX_FDS)]; char control[CMSG_SPACE(sizeof(int) * SOCKET_MAX_FDS)];
int sflags = 0; int sflags = 0;
memset(control, 0, CMSG_SPACE(sizeof(int) * SOCKET_MAX_FDS));
#ifdef MSG_CMSG_CLOEXEC #ifdef MSG_CMSG_CLOEXEC
sflags |= MSG_CMSG_CLOEXEC; sflags |= MSG_CMSG_CLOEXEC;
#endif #endif
@ -493,10 +495,12 @@ static ssize_t qio_channel_socket_writev(QIOChannel *ioc,
QIOChannelSocket *sioc = QIO_CHANNEL_SOCKET(ioc); QIOChannelSocket *sioc = QIO_CHANNEL_SOCKET(ioc);
ssize_t ret; ssize_t ret;
struct msghdr msg = { NULL, }; struct msghdr msg = { NULL, };
char control[CMSG_SPACE(sizeof(int) * SOCKET_MAX_FDS)] = { 0 }; char control[CMSG_SPACE(sizeof(int) * SOCKET_MAX_FDS)];
size_t fdsize = sizeof(int) * nfds; size_t fdsize = sizeof(int) * nfds;
struct cmsghdr *cmsg; struct cmsghdr *cmsg;
memset(control, 0, CMSG_SPACE(sizeof(int) * SOCKET_MAX_FDS));
msg.msg_iov = (struct iovec *)iov; msg.msg_iov = (struct iovec *)iov;
msg.msg_iovlen = niov; msg.msg_iovlen = niov;