What changed, and why it matters
This commit is a portability fix for compiler warnings about missing braces when initializing IPv6 address constants. It introduces platform-specific macros so the code compiles cleanly on illumos and Microsoft Visual C++ without changing behavior. There is no security issue here.
No security action needed. Treat as normal build-system portability improvement.
Security signals we found
No strong security signals were identified.
Evidence from the diff
The patch adds COMPAT_IN6ADDR_ANY_INIT and COMPAT_IN6ADDR_LOOPBACK_INIT wrappers in src/compat/compat.h. On illumos, IN6ADDR_ANY_INIT requires double braces; on illumos and MSVC, IN6ADDR_LOOPBACK_INIT requires double braces. The change replaces direct uses of IN6ADDR_*_INIT with the compatibility macros in src/net.cpp and several test files. This is purely a build/portability fix to suppress -Wmissing-braces warnings and ensure correct aggregate initialization across platforms.
Changed components
src/compat/compat.hsrc/net.cppsrc/test/fuzz/i2p.cppsrc/test/i2p_tests.cppsrc/test/netbase_tests.cppInspect captured patch +22 / −7
diff --git a/src/compat/compat.h b/src/compat/compat.h
index acb57b26..dbc5efa5 100644
--- a/src/compat/compat.h
+++ b/src/compat/compat.h
@@ -38,6 +38,18 @@
typedef u_short sa_family_t;
#endif
+// Brace style in the IN6ADDR_*_INIT macros differs across platforms.
+#if defined(__illumos__)
+#define COMPAT_IN6ADDR_ANY_INIT {{IN6ADDR_ANY_INIT}}
+#else
+#define COMPAT_IN6ADDR_ANY_INIT IN6ADDR_ANY_INIT
+#endif
+#if defined(__illumos__) || defined(_MSC_VER)
+#define COMPAT_IN6ADDR_LOOPBACK_INIT {{IN6ADDR_LOOPBACK_INIT}}
+#else
+#define COMPAT_IN6ADDR_LOOPBACK_INIT IN6ADDR_LOOPBACK_INIT
+#endif
+
// We map Linux / BSD error functions and codes, to the equivalent
// Windows definitions, and use the WSA* names throughout our code.
// Note that glibc defines EWOULDBLOCK as EAGAIN (see errno.h).
diff --git a/src/net.cpp b/src/net.cpp
index 4abcf20d..4ee68687 100644
--- a/src/net.cpp
+++ b/src/net.cpp
@@ -3306,7 +3306,7 @@ bool CConnman::InitBinds(const Options& options)
// Don't consider errors to bind on IPv6 "::" fatal because the host OS
// may not have IPv6 support and the user did not explicitly ask us to
// bind on that.
- const CService ipv6_any{in6_addr(IN6ADDR_ANY_INIT), GetListenPort()}; // ::
+ const CService ipv6_any{in6_addr(COMPAT_IN6ADDR_ANY_INIT), GetListenPort()}; // ::
Bind(ipv6_any, BF_NONE, NetPermissionFlags::None);
struct in_addr inaddr_any;
diff --git a/src/test/fuzz/i2p.cpp b/src/test/fuzz/i2p.cpp
index 64f30719..9888e7a0 100644
--- a/src/test/fuzz/i2p.cpp
+++ b/src/test/fuzz/i2p.cpp
@@ -3,6 +3,7 @@
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
#include <common/args.h>
+#include <compat/compat.h>
#include <i2p.h>
#include <netaddress.h>
#include <netbase.h>
@@ -34,7 +35,7 @@ FUZZ_TARGET(i2p, .init = initialize_i2p)
};
const fs::path private_key_path = gArgs.GetDataDirNet() / "fuzzed_i2p_private_key";
- const CService addr{in6_addr(IN6ADDR_LOOPBACK_INIT), 7656};
+ const CService addr{in6_addr(COMPAT_IN6ADDR_LOOPBACK_INIT), 7656};
const Proxy sam_proxy{addr, /*tor_stream_isolation=*/false};
auto interrupt{ConsumeThreadInterrupt(fuzzed_data_provider)};
diff --git a/src/test/i2p_tests.cpp b/src/test/i2p_tests.cpp
index 6d6b99f3..d77f4f02 100644
--- a/src/test/i2p_tests.cpp
+++ b/src/test/i2p_tests.cpp
@@ -3,6 +3,7 @@
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
#include <common/args.h>
+#include <compat/compat.h>
#include <i2p.h>
#include <logging.h>
#include <netaddress.h>
@@ -113,7 +114,7 @@ BOOST_AUTO_TEST_CASE(listen_ok_accept_fail)
};
auto interrupt{std::make_shared<CThreadInterrupt>()};
- const CService addr{in6_addr(IN6ADDR_LOOPBACK_INIT), /*port=*/7656};
+ const CService addr{in6_addr(COMPAT_IN6ADDR_LOOPBACK_INIT), /*port=*/7656};
const Proxy sam_proxy(addr, /*tor_stream_isolation=*/false);
i2p::sam::Session session(gArgs.GetDataDirNet() / "test_i2p_private_key",
sam_proxy,
@@ -156,7 +157,7 @@ BOOST_AUTO_TEST_CASE(damaged_private_key)
BOOST_REQUIRE(WriteBinaryFile(i2p_private_key_file, file_contents));
auto interrupt{std::make_shared<CThreadInterrupt>()};
- const CService addr{in6_addr(IN6ADDR_LOOPBACK_INIT), /*port=*/7656};
+ const CService addr{in6_addr(COMPAT_IN6ADDR_LOOPBACK_INIT), /*port=*/7656};
const Proxy sam_proxy{addr, /*tor_stream_isolation=*/false};
i2p::sam::Session session(i2p_private_key_file, sam_proxy, interrupt);
diff --git a/src/test/netbase_tests.cpp b/src/test/netbase_tests.cpp
index 266d952f..722ba2eb 100644
--- a/src/test/netbase_tests.cpp
+++ b/src/test/netbase_tests.cpp
@@ -2,6 +2,7 @@
// Distributed under the MIT software license, see the accompanying
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
+#include <compat/compat.h>
#include <net_permissions.h>
#include <netaddress.h>
#include <netbase.h>
@@ -502,17 +503,17 @@ BOOST_AUTO_TEST_CASE(netbase_dont_resolve_strings_with_embedded_nul_characters)
static const std::vector<CAddress> fixture_addresses({
CAddress{
- CService(CNetAddr(in6_addr(IN6ADDR_LOOPBACK_INIT)), 0 /* port */),
+ CService(CNetAddr(in6_addr(COMPAT_IN6ADDR_LOOPBACK_INIT)), 0 /* port */),
NODE_NONE,
NodeSeconds{0x4966bc61s}, /* Fri Jan 9 02:54:25 UTC 2009 */
},
CAddress{
- CService(CNetAddr(in6_addr(IN6ADDR_LOOPBACK_INIT)), 0x00f1 /* port */),
+ CService(CNetAddr(in6_addr(COMPAT_IN6ADDR_LOOPBACK_INIT)), 0x00f1 /* port */),
NODE_NETWORK,
NodeSeconds{0x83766279s}, /* Tue Nov 22 11:22:33 UTC 2039 */
},
CAddress{
- CService(CNetAddr(in6_addr(IN6ADDR_LOOPBACK_INIT)), 0xf1f2 /* port */),
+ CService(CNetAddr(in6_addr(COMPAT_IN6ADDR_LOOPBACK_INIT)), 0xf1f2 /* port */),
static_cast<ServiceFlags>(NODE_WITNESS | NODE_COMPACT_FILTERS | NODE_NETWORK_LIMITED),
NodeSeconds{0xffffffffs}, /* Sun Feb 7 06:28:15 UTC 2106 */
},
Why this scored 15/100
Community notes
Notes can correct, qualify, or add evidence to the AI analysis. Every note shown here has been validated by a human moderator.
The AI analysis stands alone for now. Submit a note if you can add evidence or important context.