net: Fix -Wmissing-braces

This commit is contained in:
Hennadii Stepanov 2025-12-17 16:23:43 +00:00
parent 13891a8a68
commit f46e3ec0f9
No known key found for this signature in database
GPG Key ID: 410108112E7EA81F
5 changed files with 22 additions and 7 deletions

View File

@ -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).

View File

@ -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;

View File

@ -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)};

View File

@ -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);

View File

@ -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 */
},