]> git.ipfire.org Git - thirdparty/haproxy.git/commit
BUILD: sockpair: fix build issue on macOS related to variable-length arrays
authorWilly Tarreau <w@1wt.eu>
Thu, 8 Jan 2026 08:18:43 +0000 (09:18 +0100)
committerWilly Tarreau <w@1wt.eu>
Thu, 8 Jan 2026 08:26:22 +0000 (09:26 +0100)
commitdbba442740235e9c5f4a513e7b3b29ea05d3d2f9
tree047433e7e54ac192e8c878389c13bd6c757ae22c
parentc17ed69bf34ebd40a679fc514a4f3d94ae40dbeb
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.
src/proto_sockpair.c