From 74bf0fc2c864dda12a7552c8c6790a7d6400cf56 Mon Sep 17 00:00:00 2001 From: iphydf Date: Tue, 21 Dec 2021 11:53:15 +0000 Subject: [PATCH] chore: Disable `-Wmissing-braces`. This flag isn't helpful for the most common case of aggregate initialisation, namely `{0}`. We don't want to be writing `{{{0}}}` with some brittle number of braces. --- .travis/flags-clang.sh | 6 +++--- other/analysis/run-clang | 1 + toxcore/DHT.c | 4 +++- toxcore/TCP_client.c | 2 +- toxcore/net_crypto.c | 2 +- toxcore/onion_client.c | 2 +- 6 files changed, 10 insertions(+), 7 deletions(-) diff --git a/.travis/flags-clang.sh b/.travis/flags-clang.sh index f505698e..f362b357 100644 --- a/.travis/flags-clang.sh +++ b/.travis/flags-clang.sh @@ -9,8 +9,6 @@ add_flag -Weverything # Disable specific warning flags for both C and C++. -# TODO(iphydf): Clean these up. Probably all of these are actual bugs. -add_flag -Wno-cast-align # Very verbose, not very useful. This warns about things like int -> uint # conversions that change sign without a cast and narrowing conversions. add_flag -Wno-conversion @@ -24,7 +22,9 @@ add_flag -Wno-disabled-macro-expansion add_flag -Wno-documentation-deprecated-sync # Bootstrap daemon does this. add_flag -Wno-format-nonliteral -# struct Foo foo = {0}; is a common idiom. +# struct Foo foo = {0}; is a common idiom. Missing braces means we'd need to +# write {{{0}}} in some cases, which is ugly and a maintenance burden. +add_flag -Wno-missing-braces add_flag -Wno-missing-field-initializers # Useful sometimes, but we accept padding in structs for clarity. # Reordering fields to avoid padding will reduce readability. diff --git a/other/analysis/run-clang b/other/analysis/run-clang index 3ea775b9..f1430770 100755 --- a/other/analysis/run-clang +++ b/other/analysis/run-clang @@ -17,6 +17,7 @@ clang++ -o /dev/null amalgamation.cc \ -Wno-disabled-macro-expansion \ -Wno-documentation-deprecated-sync \ -Wno-global-constructors \ + -Wno-missing-braces \ -Wno-missing-field-initializers \ -Wno-old-style-cast \ -Wno-padded \ diff --git a/toxcore/DHT.c b/toxcore/DHT.c index 171022ef..f34fa735 100644 --- a/toxcore/DHT.c +++ b/toxcore/DHT.c @@ -749,7 +749,9 @@ static int client_or_ip_port_in_list(const Logger *log, const Mono_Time *mono_ti LOGGER_DEBUG(log, "coipil[%u]: switching public_key (ipv%d)", index, ip_version); /* kill the other address, if it was set */ - memset(assoc, 0, sizeof(IPPTsPng)); + *assoc = (IPPTsPng) { + 0 + }; return 1; } diff --git a/toxcore/TCP_client.c b/toxcore/TCP_client.c index c5194ec4..f95c59eb 100644 --- a/toxcore/TCP_client.c +++ b/toxcore/TCP_client.c @@ -670,7 +670,7 @@ TCP_Client_Connection *new_TCP_connection(const Mono_Time *mono_time, IP_Port ip return nullptr; } - const TCP_Proxy_Info default_proxyinfo = {{{{0}}}, TCP_PROXY_NONE}; + const TCP_Proxy_Info default_proxyinfo = {0}; if (proxy_info == nullptr) { proxy_info = &default_proxyinfo; diff --git a/toxcore/net_crypto.c b/toxcore/net_crypto.c index 2dfc6639..072721c7 100644 --- a/toxcore/net_crypto.c +++ b/toxcore/net_crypto.c @@ -603,7 +603,7 @@ static int add_ip_port_connection(Net_Crypto *c, int crypt_connection_id, IP_Por */ static IP_Port return_ip_port_connection(Net_Crypto *c, int crypt_connection_id) { - const IP_Port empty = {{{0}}}; + const IP_Port empty = {0}; Crypto_Connection *conn = get_crypto_connection(c, crypt_connection_id); diff --git a/toxcore/onion_client.c b/toxcore/onion_client.c index 67258337..686ec625 100644 --- a/toxcore/onion_client.c +++ b/toxcore/onion_client.c @@ -1008,7 +1008,7 @@ static int handle_tcp_onion(void *object, const uint8_t *data, uint16_t length, return 1; } - IP_Port ip_port = {{{0}}}; + IP_Port ip_port = {0}; ip_port.ip.family = net_family_tcp_family; if (data[0] == NET_PACKET_ANNOUNCE_RESPONSE) {