mirror of
https://git.haproxy.org/git/haproxy.git/
synced 2026-01-15 05:41:16 +01:00
BUILD: sockpair: fix build issue on macOS related to variable-length arrays
In GH issue #3226, Sergey Fedorov (@barracuda156) reported that since commit 10c14a1ed0 ("MINOR: proto_sockpair: send_fd_uxst: init iobuf, cmsghdr, cmsgbuf to zeros"), macOS 10.6.8 with gcc 14.3.0 doesn't build anymore: src/proto_sockpair.c: In function 'send_fd_uxst': src/proto_sockpair.c:246:49: error: variable-sized object may not be initialized except with an empty initializer 246 | char cmsgbuf[CMSG_SPACE(sizeof(int))] = {0}; | ^ src/proto_sockpair.c:247:45: error: variable-sized object may not be initialized except with an empty initializer 247 | char buf[CMSG_SPACE(sizeof(int))] = {0}; | ^ Upon investigation, it appears that the CMSG_SPACE() macro on this OS looks too complex for gcc to consider it as a constant, so it takes these buffers for variable-length arrays and cannot initialize them. Let's move to a simple memset() instead, which Sergey confirmed fixes the problem. This needs to be backported as far as 3.1. Thanks to Sergey for the report, the bisect and testing the fix.
This commit is contained in:
parent
c17ed69bf3
commit
dbba442740
@ -237,12 +237,15 @@ int send_fd_uxst(int fd, int send_fd)
|
||||
struct iovec iov;
|
||||
struct msghdr msghdr;
|
||||
|
||||
char cmsgbuf[CMSG_SPACE(sizeof(int))] = {0};
|
||||
char buf[CMSG_SPACE(sizeof(int))] = {0};
|
||||
char cmsgbuf[CMSG_SPACE(sizeof(int))];
|
||||
char buf[CMSG_SPACE(sizeof(int))];
|
||||
struct cmsghdr *cmsg = (void *)buf;
|
||||
|
||||
int *fdptr;
|
||||
|
||||
memset(cmsgbuf, 0, sizeof(cmsgbuf));
|
||||
memset(buf, 0, sizeof(buf));
|
||||
|
||||
iov.iov_base = iobuf;
|
||||
iov.iov_len = sizeof(iobuf);
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user