libratbox/src/commio.c: misc cleanups for compiler warnings

commio.c:2244:11: warning: variable length array used [-Wvla]
commio.c:2253:29: warning: comparison of integers of different signs:
                  'unsigned int' and 'int' [-Wsign-compare]

This use of alloca(3) is okay-ish considering the corresponding function
`rb_recv_fd_buf()` already uses it too, for much the same purpose. Also
remove a redundant return statement.
This commit is contained in:
Aaron Jones 2017-08-01 11:48:30 +00:00
parent c41d0c0f5f
commit a6485efda0
No known key found for this signature in database
GPG key ID: 8AF0737488AB3012

View file

@ -2241,7 +2241,7 @@ rb_send_fd_buf(rb_fde_t *xF, rb_fde_t **F, int count, void *data, size_t datasiz
if(count > 0) if(count > 0)
{ {
int len = CMSG_SPACE(sizeof(int) * count); int len = CMSG_SPACE(sizeof(int) * count);
char buf[len]; char *buf = alloca(len);
msg.msg_control = buf; msg.msg_control = buf;
msg.msg_controllen = len; msg.msg_controllen = len;
@ -2250,13 +2250,14 @@ rb_send_fd_buf(rb_fde_t *xF, rb_fde_t **F, int count, void *data, size_t datasiz
cmsg->cmsg_type = SCM_RIGHTS; cmsg->cmsg_type = SCM_RIGHTS;
cmsg->cmsg_len = CMSG_LEN(sizeof(int) * count); cmsg->cmsg_len = CMSG_LEN(sizeof(int) * count);
for(unsigned int i = 0; i < count; i++) for(int i = 0; i < count; i++)
{ {
((int *)CMSG_DATA(cmsg))[i] = rb_get_fd(F[i]); ((int *)CMSG_DATA(cmsg))[i] = rb_get_fd(F[i]);
} }
msg.msg_controllen = cmsg->cmsg_len; msg.msg_controllen = cmsg->cmsg_len;
return sendmsg(rb_get_fd(xF), &msg, MSG_NOSIGNAL);
} }
return sendmsg(rb_get_fd(xF), &msg, MSG_NOSIGNAL); return sendmsg(rb_get_fd(xF), &msg, MSG_NOSIGNAL);
} }
#else #else