From 8c0fd40356e4a7724b556e17b15b0d14f7d25b4d Mon Sep 17 00:00:00 2001 From: iphydf Date: Tue, 5 May 2020 22:56:03 +0100 Subject: refactor: Remove multi-declarators entirely. We no longer allow `int a, b;`. In the few cases where we used it, we instead better * limit the scope of the identifier (e.g. in a for-init-decl) * split the line and have 2 separate declarators, because the identifiers designate different types of things (e.g. friend numbers and group numbers). --- .../bootstrap_daemon/docker/tox-bootstrapd.sha256 | 2 +- toxcore/DHT.c | 6 ++++-- toxcore/Messenger.c | 22 +++++++++++----------- toxcore/group.c | 7 +++++-- toxcore/net_crypto.c | 3 ++- toxcore/network.c | 6 ++++-- toxcore/onion_announce.c | 3 ++- toxcore/onion_client.c | 3 ++- 8 files changed, 31 insertions(+), 21 deletions(-) diff --git a/other/bootstrap_daemon/docker/tox-bootstrapd.sha256 b/other/bootstrap_daemon/docker/tox-bootstrapd.sha256 index 55bf67f6..20c33cbb 100644 --- a/other/bootstrap_daemon/docker/tox-bootstrapd.sha256 +++ b/other/bootstrap_daemon/docker/tox-bootstrapd.sha256 @@ -1 +1 @@ -20306177ad19b1b6ad84469331a06d1c5c01f7918a95517105545f76d3c90d82 /usr/local/bin/tox-bootstrapd +087432ee876325273dcb4015083adb88c46a55085a6d00741c6d7a2a385ea40c /usr/local/bin/tox-bootstrapd diff --git a/toxcore/DHT.c b/toxcore/DHT.c index 40f477fd..15f554e2 100644 --- a/toxcore/DHT.c +++ b/toxcore/DHT.c @@ -900,7 +900,8 @@ static bool incorrect_hardening(const IPPTsPng *assoc) static int cmp_dht_entry(const void *a, const void *b) { - DHT_Cmp_data cmp1, cmp2; + DHT_Cmp_data cmp1; + DHT_Cmp_data cmp2; memcpy(&cmp1, a, sizeof(DHT_Cmp_data)); memcpy(&cmp2, b, sizeof(DHT_Cmp_data)); const Client_data entry1 = cmp1.entry; @@ -2418,7 +2419,8 @@ static int handle_hardening(void *object, IP_Port source, const uint8_t *source_ return 1; } - Node_format node, tocheck_node; + Node_format node; + Node_format tocheck_node; node.ip_port = source; memcpy(node.public_key, source_pubkey, CRYPTO_PUBLIC_KEY_SIZE); memcpy(&tocheck_node, packet + 1, sizeof(Node_format)); diff --git a/toxcore/Messenger.c b/toxcore/Messenger.c index 573cd64a..9984d7f0 100644 --- a/toxcore/Messenger.c +++ b/toxcore/Messenger.c @@ -1047,7 +1047,8 @@ int file_get_id(const Messenger *m, int32_t friendnumber, uint32_t filenumber, u } uint32_t temp_filenum; - uint8_t send_receive, file_number; + uint8_t send_receive; + uint8_t file_number; if (filenumber >= (1 << 16)) { send_receive = 1; @@ -1209,7 +1210,8 @@ int file_control(const Messenger *m, int32_t friendnumber, uint32_t filenumber, } uint32_t temp_filenum; - uint8_t send_receive, file_number; + uint8_t send_receive; + uint8_t file_number; if (filenumber >= (1 << 16)) { send_receive = 1; @@ -2568,9 +2570,9 @@ void do_messenger(Messenger *m, void *userdata) if (mono_time_get(m->mono_time) > m->lastdump + DUMPING_CLIENTS_FRIENDS_EVERY_N_SECONDS) { m->lastdump = mono_time_get(m->mono_time); - uint32_t client, last_pinged; + uint32_t last_pinged; - for (client = 0; client < LCLIENT_LIST; ++client) { + for (uint32_t client = 0; client < LCLIENT_LIST; ++client) { const Client_data *cptr = dht_get_close_client(m->dht, client); const IPPTsPng *const assocs[] = { &cptr->assoc4, &cptr->assoc6, nullptr }; @@ -2595,14 +2597,12 @@ void do_messenger(Messenger *m, void *userdata) } - uint32_t friend_idx, dhtfriend; - /* dht contains additional "friends" (requests) */ uint32_t num_dhtfriends = dht_get_num_friends(m->dht); VLA(int32_t, m2dht, num_dhtfriends); VLA(int32_t, dht2m, num_dhtfriends); - for (friend_idx = 0; friend_idx < num_dhtfriends; ++friend_idx) { + for (uint32_t friend_idx = 0; friend_idx < num_dhtfriends; ++friend_idx) { m2dht[friend_idx] = -1; dht2m[friend_idx] = -1; @@ -2610,7 +2610,7 @@ void do_messenger(Messenger *m, void *userdata) continue; } - for (dhtfriend = 0; dhtfriend < dht_get_num_friends(m->dht); ++dhtfriend) { + for (uint32_t dhtfriend = 0; dhtfriend < dht_get_num_friends(m->dht); ++dhtfriend) { if (id_equal(m->friendlist[friend_idx].real_pk, dht_get_friend_public_key(m->dht, dhtfriend))) { m2dht[friend_idx] = dhtfriend; break; @@ -2618,7 +2618,7 @@ void do_messenger(Messenger *m, void *userdata) } } - for (friend_idx = 0; friend_idx < num_dhtfriends; ++friend_idx) { + for (uint32_t friend_idx = 0; friend_idx < num_dhtfriends; ++friend_idx) { if (m2dht[friend_idx] >= 0) { dht2m[m2dht[friend_idx]] = friend_idx; } @@ -2631,7 +2631,7 @@ void do_messenger(Messenger *m, void *userdata) Friend *msgfptr; DHT_Friend *dhtfptr; - for (friend_idx = 0; friend_idx < num_dhtfriends; ++friend_idx) { + for (uint32_t friend_idx = 0; friend_idx < num_dhtfriends; ++friend_idx) { if (dht2m[friend_idx] >= 0) { msgfptr = &m->friendlist[dht2m[friend_idx]]; } else { @@ -2651,7 +2651,7 @@ void do_messenger(Messenger *m, void *userdata) id_to_string(dht_friend_public_key(dhtfptr), id_str, sizeof(id_str))); } - for (client = 0; client < MAX_FRIEND_CLIENTS; ++client) { + for (uint32_t client = 0; client < MAX_FRIEND_CLIENTS; ++client) { const Client_data *cptr = dht_friend_client(dhtfptr, client); const IPPTsPng *const assocs[] = {&cptr->assoc4, &cptr->assoc6}; diff --git a/toxcore/group.c b/toxcore/group.c index 02ca3cfe..e0be6ac0 100644 --- a/toxcore/group.c +++ b/toxcore/group.c @@ -1933,7 +1933,8 @@ static void handle_friend_invite_packet(Messenger *m, uint32_t friendnumber, con return; } - uint16_t other_groupnum, groupnum; + uint16_t other_groupnum; + uint16_t groupnum; net_unpack_u16(data + 1, &other_groupnum); net_unpack_u16(data + 1 + sizeof(uint16_t), &groupnum); @@ -2883,7 +2884,9 @@ static int handle_lossy(void *object, int friendcon_id, const uint8_t *data, uin return -1; } - uint16_t groupnumber, peer_number, message_number; + uint16_t groupnumber; + uint16_t peer_number; + uint16_t message_number; memcpy(&groupnumber, data + 1, sizeof(uint16_t)); memcpy(&peer_number, data + 1 + sizeof(uint16_t), sizeof(uint16_t)); memcpy(&message_number, data + 1 + sizeof(uint16_t) * 2, sizeof(uint16_t)); diff --git a/toxcore/net_crypto.c b/toxcore/net_crypto.c index 3ed46a99..43cc8ab1 100644 --- a/toxcore/net_crypto.c +++ b/toxcore/net_crypto.c @@ -1512,7 +1512,8 @@ static int handle_data_packet_core(Net_Crypto *c, int crypt_connection_id, const return -1; } - uint32_t buffer_start, num; + uint32_t buffer_start; + uint32_t num; memcpy(&buffer_start, data, sizeof(uint32_t)); memcpy(&num, data + sizeof(uint32_t), sizeof(uint32_t)); buffer_start = net_ntohl(buffer_start); diff --git a/toxcore/network.c b/toxcore/network.c index e5a58331..c448cb7e 100644 --- a/toxcore/network.c +++ b/toxcore/network.c @@ -1532,7 +1532,8 @@ size_t net_unpack_u16(const uint8_t *bytes, uint16_t *v) size_t net_unpack_u32(const uint8_t *bytes, uint32_t *v) { const uint8_t *p = bytes; - uint16_t lo, hi; + uint16_t hi; + uint16_t lo; p += net_unpack_u16(p, &hi); p += net_unpack_u16(p, &lo); *v = ((uint32_t)hi << 16) | lo; @@ -1542,7 +1543,8 @@ size_t net_unpack_u32(const uint8_t *bytes, uint32_t *v) size_t net_unpack_u64(const uint8_t *bytes, uint64_t *v) { const uint8_t *p = bytes; - uint32_t lo, hi; + uint32_t hi; + uint32_t lo; p += net_unpack_u32(p, &hi); p += net_unpack_u32(p, &lo); *v = ((uint64_t)hi << 32) | lo; diff --git a/toxcore/onion_announce.c b/toxcore/onion_announce.c index 6d38012a..0a04a4b8 100644 --- a/toxcore/onion_announce.c +++ b/toxcore/onion_announce.c @@ -259,7 +259,8 @@ typedef struct Cmp_data { static int cmp_entry(const void *a, const void *b) { - Cmp_data cmp1, cmp2; + Cmp_data cmp1; + Cmp_data cmp2; memcpy(&cmp1, a, sizeof(Cmp_data)); memcpy(&cmp2, b, sizeof(Cmp_data)); Onion_Announce_Entry entry1 = cmp1.entry; diff --git a/toxcore/onion_client.c b/toxcore/onion_client.c index 7494ea94..c1b2dcf7 100644 --- a/toxcore/onion_client.c +++ b/toxcore/onion_client.c @@ -611,7 +611,8 @@ typedef struct Onion_Client_Cmp_data { static int onion_client_cmp_entry(const void *a, const void *b) { - Onion_Client_Cmp_data cmp1, cmp2; + Onion_Client_Cmp_data cmp1; + Onion_Client_Cmp_data cmp2; memcpy(&cmp1, a, sizeof(Onion_Client_Cmp_data)); memcpy(&cmp2, b, sizeof(Onion_Client_Cmp_data)); Onion_Node entry1 = cmp1.entry; -- cgit v1.2.3