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).
This commit is contained in:
iphydf 2020-05-05 22:56:03 +01:00
parent fd2bb77923
commit 8c0fd40356
No known key found for this signature in database
GPG Key ID: 3855DBA2D74403C9
8 changed files with 31 additions and 21 deletions

View File

@ -1 +1 @@
20306177ad19b1b6ad84469331a06d1c5c01f7918a95517105545f76d3c90d82 /usr/local/bin/tox-bootstrapd 087432ee876325273dcb4015083adb88c46a55085a6d00741c6d7a2a385ea40c /usr/local/bin/tox-bootstrapd

View File

@ -900,7 +900,8 @@ static bool incorrect_hardening(const IPPTsPng *assoc)
static int cmp_dht_entry(const void *a, const void *b) 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(&cmp1, a, sizeof(DHT_Cmp_data));
memcpy(&cmp2, b, sizeof(DHT_Cmp_data)); memcpy(&cmp2, b, sizeof(DHT_Cmp_data));
const Client_data entry1 = cmp1.entry; 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; return 1;
} }
Node_format node, tocheck_node; Node_format node;
Node_format tocheck_node;
node.ip_port = source; node.ip_port = source;
memcpy(node.public_key, source_pubkey, CRYPTO_PUBLIC_KEY_SIZE); memcpy(node.public_key, source_pubkey, CRYPTO_PUBLIC_KEY_SIZE);
memcpy(&tocheck_node, packet + 1, sizeof(Node_format)); memcpy(&tocheck_node, packet + 1, sizeof(Node_format));

View File

@ -1047,7 +1047,8 @@ int file_get_id(const Messenger *m, int32_t friendnumber, uint32_t filenumber, u
} }
uint32_t temp_filenum; uint32_t temp_filenum;
uint8_t send_receive, file_number; uint8_t send_receive;
uint8_t file_number;
if (filenumber >= (1 << 16)) { if (filenumber >= (1 << 16)) {
send_receive = 1; send_receive = 1;
@ -1209,7 +1210,8 @@ int file_control(const Messenger *m, int32_t friendnumber, uint32_t filenumber,
} }
uint32_t temp_filenum; uint32_t temp_filenum;
uint8_t send_receive, file_number; uint8_t send_receive;
uint8_t file_number;
if (filenumber >= (1 << 16)) { if (filenumber >= (1 << 16)) {
send_receive = 1; 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) { if (mono_time_get(m->mono_time) > m->lastdump + DUMPING_CLIENTS_FRIENDS_EVERY_N_SECONDS) {
m->lastdump = mono_time_get(m->mono_time); 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 Client_data *cptr = dht_get_close_client(m->dht, client);
const IPPTsPng *const assocs[] = { &cptr->assoc4, &cptr->assoc6, nullptr }; 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) */ /* dht contains additional "friends" (requests) */
uint32_t num_dhtfriends = dht_get_num_friends(m->dht); uint32_t num_dhtfriends = dht_get_num_friends(m->dht);
VLA(int32_t, m2dht, num_dhtfriends); VLA(int32_t, m2dht, num_dhtfriends);
VLA(int32_t, dht2m, 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; m2dht[friend_idx] = -1;
dht2m[friend_idx] = -1; dht2m[friend_idx] = -1;
@ -2610,7 +2610,7 @@ void do_messenger(Messenger *m, void *userdata)
continue; 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))) { if (id_equal(m->friendlist[friend_idx].real_pk, dht_get_friend_public_key(m->dht, dhtfriend))) {
m2dht[friend_idx] = dhtfriend; m2dht[friend_idx] = dhtfriend;
break; 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) { if (m2dht[friend_idx] >= 0) {
dht2m[m2dht[friend_idx]] = friend_idx; dht2m[m2dht[friend_idx]] = friend_idx;
} }
@ -2631,7 +2631,7 @@ void do_messenger(Messenger *m, void *userdata)
Friend *msgfptr; Friend *msgfptr;
DHT_Friend *dhtfptr; 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) { if (dht2m[friend_idx] >= 0) {
msgfptr = &m->friendlist[dht2m[friend_idx]]; msgfptr = &m->friendlist[dht2m[friend_idx]];
} else { } 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))); 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 Client_data *cptr = dht_friend_client(dhtfptr, client);
const IPPTsPng *const assocs[] = {&cptr->assoc4, &cptr->assoc6}; const IPPTsPng *const assocs[] = {&cptr->assoc4, &cptr->assoc6};

View File

@ -1933,7 +1933,8 @@ static void handle_friend_invite_packet(Messenger *m, uint32_t friendnumber, con
return; 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, &other_groupnum);
net_unpack_u16(data + 1 + sizeof(uint16_t), &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; 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(&groupnumber, data + 1, sizeof(uint16_t));
memcpy(&peer_number, data + 1 + sizeof(uint16_t), 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)); memcpy(&message_number, data + 1 + sizeof(uint16_t) * 2, sizeof(uint16_t));

View File

@ -1512,7 +1512,8 @@ static int handle_data_packet_core(Net_Crypto *c, int crypt_connection_id, const
return -1; return -1;
} }
uint32_t buffer_start, num; uint32_t buffer_start;
uint32_t num;
memcpy(&buffer_start, data, sizeof(uint32_t)); memcpy(&buffer_start, data, sizeof(uint32_t));
memcpy(&num, data + sizeof(uint32_t), sizeof(uint32_t)); memcpy(&num, data + sizeof(uint32_t), sizeof(uint32_t));
buffer_start = net_ntohl(buffer_start); buffer_start = net_ntohl(buffer_start);

View File

@ -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) size_t net_unpack_u32(const uint8_t *bytes, uint32_t *v)
{ {
const uint8_t *p = bytes; 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, &hi);
p += net_unpack_u16(p, &lo); p += net_unpack_u16(p, &lo);
*v = ((uint32_t)hi << 16) | 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) size_t net_unpack_u64(const uint8_t *bytes, uint64_t *v)
{ {
const uint8_t *p = bytes; 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, &hi);
p += net_unpack_u32(p, &lo); p += net_unpack_u32(p, &lo);
*v = ((uint64_t)hi << 32) | lo; *v = ((uint64_t)hi << 32) | lo;

View File

@ -259,7 +259,8 @@ typedef struct Cmp_data {
static int cmp_entry(const void *a, const void *b) 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(&cmp1, a, sizeof(Cmp_data));
memcpy(&cmp2, b, sizeof(Cmp_data)); memcpy(&cmp2, b, sizeof(Cmp_data));
Onion_Announce_Entry entry1 = cmp1.entry; Onion_Announce_Entry entry1 = cmp1.entry;

View File

@ -611,7 +611,8 @@ typedef struct Onion_Client_Cmp_data {
static int onion_client_cmp_entry(const void *a, const void *b) 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(&cmp1, a, sizeof(Onion_Client_Cmp_data));
memcpy(&cmp2, b, sizeof(Onion_Client_Cmp_data)); memcpy(&cmp2, b, sizeof(Onion_Client_Cmp_data));
Onion_Node entry1 = cmp1.entry; Onion_Node entry1 = cmp1.entry;