From 48bd200acbf4b4d8f3fa241373477b3a21001d17 Mon Sep 17 00:00:00 2001 From: iphydf Date: Tue, 5 May 2020 22:28:59 +0100 Subject: refactor: Disallow multiple initialised declarators per decl. We no longer allow: ```c int a = 0, b = 0; int a[3], b[3]; int a, *b; ``` But we do still allow (for now): ```c int a, b; ``` --- .../bootstrap_daemon/docker/tox-bootstrapd.sha256 | 2 +- toxcore/DHT.c | 3 ++- toxcore/LAN_discovery.c | 6 +++-- toxcore/Messenger.c | 3 ++- toxcore/TCP_connection.c | 8 +++--- toxcore/group.c | 16 ++++++++---- toxcore/net_crypto.c | 15 ++++++----- toxcore/onion_client.c | 29 +++++++++++++--------- toxcore/tox.c | 3 ++- 9 files changed, 52 insertions(+), 33 deletions(-) diff --git a/other/bootstrap_daemon/docker/tox-bootstrapd.sha256 b/other/bootstrap_daemon/docker/tox-bootstrapd.sha256 index 6ccdea6a..55bf67f6 100644 --- a/other/bootstrap_daemon/docker/tox-bootstrapd.sha256 +++ b/other/bootstrap_daemon/docker/tox-bootstrapd.sha256 @@ -1 +1 @@ -6f719e76aedd7b386c40ef096412e0336dbc608e69112329932a2c7b60dd8652 /usr/local/bin/tox-bootstrapd +20306177ad19b1b6ad84469331a06d1c5c01f7918a95517105545f76d3c90d82 /usr/local/bin/tox-bootstrapd diff --git a/toxcore/DHT.c b/toxcore/DHT.c index 7c9263cd..40f477fd 100644 --- a/toxcore/DHT.c +++ b/toxcore/DHT.c @@ -583,7 +583,8 @@ int pack_nodes(uint8_t *data, uint16_t length, const Node_format *nodes, uint16_ int unpack_nodes(Node_format *nodes, uint16_t max_num_nodes, uint16_t *processed_data_len, const uint8_t *data, uint16_t length, bool tcp_enabled) { - uint32_t num = 0, len_processed = 0; + uint32_t num = 0; + uint32_t len_processed = 0; while (num < max_num_nodes && len_processed < length) { const int ipp_size = unpack_ip_port(&nodes[num].ip_port, data + len_processed, length - len_processed, tcp_enabled); diff --git a/toxcore/LAN_discovery.c b/toxcore/LAN_discovery.c index c3d06014..e23550df 100644 --- a/toxcore/LAN_discovery.c +++ b/toxcore/LAN_discovery.c @@ -70,14 +70,16 @@ static void fetch_broadcast_info(uint16_t port) IP_ADAPTER_INFO *pAdapter = pAdapterInfo; while (pAdapter) { - IP gateway = {0}, subnet_mask = {0}; + IP gateway = {0}; + IP subnet_mask = {0}; if (addr_parse_ip(pAdapter->IpAddressList.IpMask.String, &subnet_mask) && addr_parse_ip(pAdapter->GatewayList.IpAddress.String, &gateway)) { if (net_family_is_ipv4(gateway.family) && net_family_is_ipv4(subnet_mask.family)) { IP_Port *ip_port = &ip_ports[count]; ip_port->ip.family = net_family_ipv4; - uint32_t gateway_ip = net_ntohl(gateway.ip.v4.uint32), subnet_ip = net_ntohl(subnet_mask.ip.v4.uint32); + uint32_t gateway_ip = net_ntohl(gateway.ip.v4.uint32); + uint32_t subnet_ip = net_ntohl(subnet_mask.ip.v4.uint32); uint32_t broadcast_ip = gateway_ip + ~subnet_ip - 1; ip_port->ip.ip.v4.uint32 = net_htonl(broadcast_ip); ip_port->port = port; diff --git a/toxcore/Messenger.c b/toxcore/Messenger.c index 32c89867..573cd64a 100644 --- a/toxcore/Messenger.c +++ b/toxcore/Messenger.c @@ -239,7 +239,8 @@ int32_t m_addfriend(Messenger *m, const uint8_t *address, const uint8_t *data, u return FAERR_BADCHECKSUM; } - uint16_t check, checksum = address_checksum(address, FRIEND_ADDRESS_SIZE - sizeof(checksum)); + uint16_t check; + uint16_t checksum = address_checksum(address, FRIEND_ADDRESS_SIZE - sizeof(checksum)); memcpy(&check, address + CRYPTO_PUBLIC_KEY_SIZE + sizeof(uint32_t), sizeof(check)); if (check != checksum) { diff --git a/toxcore/TCP_connection.c b/toxcore/TCP_connection.c index 4256f786..ac933cc3 100644 --- a/toxcore/TCP_connection.c +++ b/toxcore/TCP_connection.c @@ -692,9 +692,9 @@ static int rm_tcp_connection_from_conn(TCP_Connection_to *con_to, unsigned int t */ static unsigned int online_tcp_connection_from_conn(TCP_Connection_to *con_to) { - unsigned int i, count = 0; + unsigned int count = 0; - for (i = 0; i < MAX_FRIEND_TCP_CONNECTIONS; ++i) { + for (unsigned int i = 0; i < MAX_FRIEND_TCP_CONNECTIONS; ++i) { if (con_to->connections[i].tcp_connection) { if (con_to->connections[i].status == TCP_CONNECTIONS_STATUS_ONLINE) { ++count; @@ -1086,9 +1086,9 @@ static int tcp_relay_on_online(TCP_Connections *tcp_c, int tcp_connections_numbe return -1; } - unsigned int i, sent = 0; + unsigned int sent = 0; - for (i = 0; i < tcp_c->connections_length; ++i) { + for (unsigned int i = 0; i < tcp_c->connections_length; ++i) { TCP_Connection_to *con_to = get_connection(tcp_c, i); if (con_to) { diff --git a/toxcore/group.c b/toxcore/group.c index a946e7b8..02ca3cfe 100644 --- a/toxcore/group.c +++ b/toxcore/group.c @@ -242,7 +242,8 @@ static int get_peer_index(const Group_c *g, uint16_t peer_number) static uint64_t calculate_comp_value(const uint8_t *pk1, const uint8_t *pk2) { - uint64_t cmp1 = 0, cmp2 = 0; + uint64_t cmp1 = 0; + uint64_t cmp2 = 0; for (size_t i = 0; i < sizeof(uint64_t); ++i) { cmp1 = (cmp1 << 8) + (uint64_t)pk1[i]; @@ -1979,7 +1980,8 @@ static void handle_friend_invite_packet(Messenger *m, uint32_t friendnumber, con return; } - uint8_t real_pk[CRYPTO_PUBLIC_KEY_SIZE], temp_pk[CRYPTO_PUBLIC_KEY_SIZE]; + uint8_t real_pk[CRYPTO_PUBLIC_KEY_SIZE]; + uint8_t temp_pk[CRYPTO_PUBLIC_KEY_SIZE]; get_friendcon_public_keys(real_pk, temp_pk, g_c->fr_c, friendcon_id); addpeer(g_c, groupnum, real_pk, temp_pk, peer_number, userdata, true, true); @@ -2097,7 +2099,8 @@ static int handle_packet_online(Group_Chats *g_c, int friendcon_id, const uint8_ send_packet_online(g_c->fr_c, friendcon_id, groupnumber, g->type, g->id); if (g->connections[index].reasons & GROUPCHAT_CONNECTION_REASON_INTRODUCING) { - uint8_t real_pk[CRYPTO_PUBLIC_KEY_SIZE], temp_pk[CRYPTO_PUBLIC_KEY_SIZE]; + uint8_t real_pk[CRYPTO_PUBLIC_KEY_SIZE]; + uint8_t temp_pk[CRYPTO_PUBLIC_KEY_SIZE]; get_friendcon_public_keys(real_pk, temp_pk, g_c->fr_c, friendcon_id); const int peer_index = peer_in_group(g, real_pk); @@ -2129,7 +2132,8 @@ static int handle_packet_rejoin(Group_Chats *g_c, int friendcon_id, const uint8_ return -1; } - uint8_t real_pk[CRYPTO_PUBLIC_KEY_SIZE], temp_pk[CRYPTO_PUBLIC_KEY_SIZE]; + uint8_t real_pk[CRYPTO_PUBLIC_KEY_SIZE]; + uint8_t temp_pk[CRYPTO_PUBLIC_KEY_SIZE]; get_friendcon_public_keys(real_pk, temp_pk, g_c->fr_c, friendcon_id); uint16_t peer_number; @@ -2366,7 +2370,9 @@ static unsigned int send_lossy_all_connections(const Group_Chats *g_c, const Gro uint16_t length, int receiver) { - unsigned int sent = 0, num_connected_closest = 0, connected_closest[DESIRED_CLOSEST]; + unsigned int sent = 0; + unsigned int num_connected_closest = 0; + unsigned int connected_closest[DESIRED_CLOSEST]; for (unsigned int i = 0; i < MAX_GROUP_CONNECTIONS; ++i) { if (g->connections[i].type != GROUPCHAT_CONNECTION_ONLINE) { diff --git a/toxcore/net_crypto.c b/toxcore/net_crypto.c index f57886a8..3ed46a99 100644 --- a/toxcore/net_crypto.c +++ b/toxcore/net_crypto.c @@ -617,7 +617,8 @@ static IP_Port return_ip_port_connection(Net_Crypto *c, int crypt_connection_id) } const uint64_t current_time = mono_time_get(c->mono_time); - bool v6 = 0, v4 = 0; + bool v6 = 0; + bool v4 = 0; if ((UDP_DIRECT_TIMEOUT + conn->direct_lastrecv_timev4) > current_time) { v4 = 1; @@ -932,9 +933,9 @@ static int generate_request_packet(const Logger *log, uint8_t *data, uint16_t le return cur_len; } - uint32_t i, n = 1; + uint32_t n = 1; - for (i = recv_array->buffer_start; i != recv_array->buffer_end; ++i) { + for (uint32_t i = recv_array->buffer_start; i != recv_array->buffer_end; ++i) { uint32_t num = i % CRYPTO_PACKET_BUFFER_SIZE; if (!recv_array->buffer[num]) { @@ -1290,9 +1291,10 @@ static int send_requested_packets(Net_Crypto *c, int crypt_connection_id, uint32 } const uint64_t temp_time = current_time_monotonic(c->mono_time); - uint32_t i, num_sent = 0, array_size = num_packets_array(&conn->send_array); + const uint32_t array_size = num_packets_array(&conn->send_array); + uint32_t num_sent = 0; - for (i = 0; i < array_size; ++i) { + for (uint32_t i = 0; i < array_size; ++i) { Packet_Data *dt; const uint32_t packet_num = i + conn->send_array.buffer_start; const int ret = get_data_pointer(c->log, &conn->send_array, &dt, packet_num); @@ -2586,7 +2588,8 @@ static void send_crypto_packets(Net_Crypto *c) /* When switching from TCP to UDP, don't change the packet send rate for CONGESTION_EVENT_TIMEOUT ms. */ if (!(direct_connected && conn->last_tcp_sent + CONGESTION_EVENT_TIMEOUT > temp_time)) { - long signed int total_sent = 0, total_resent = 0; + long signed int total_sent = 0; + long signed int total_resent = 0; // TODO(irungentoo): use real delay unsigned int delay = (unsigned int)((conn->rtt_time / PACKET_COUNTER_AVERAGE_INTERVAL) + 0.5); diff --git a/toxcore/onion_client.c b/toxcore/onion_client.c index 60a80bc6..7494ea94 100644 --- a/toxcore/onion_client.c +++ b/toxcore/onion_client.c @@ -701,7 +701,8 @@ static int client_add_to_list(Onion_Client *onion_c, uint32_t num, const uint8_t sort_onion_node_list(list_nodes, list_length, onion_c->mono_time, reference_id); - int index = -1, stored = 0; + int index = -1; + int stored = 0; unsigned int i; if (onion_node_timed_out(&list_nodes[0], onion_c->mono_time) @@ -1046,10 +1047,12 @@ int send_onion_data(Onion_Client *onion_c, int friend_num, const uint8_t *data, return -1; } - unsigned int i, good_nodes[MAX_ONION_CLIENTS], num_good = 0, num_nodes = 0; + unsigned int good_nodes[MAX_ONION_CLIENTS]; + unsigned int num_good = 0; + unsigned int num_nodes = 0; Onion_Node *list_nodes = onion_c->friends_list[friend_num].clients_list; - for (i = 0; i < MAX_ONION_CLIENTS; ++i) { + for (unsigned int i = 0; i < MAX_ONION_CLIENTS; ++i) { if (onion_node_timed_out(&list_nodes[i], onion_c->mono_time)) { continue; } @@ -1081,7 +1084,7 @@ int send_onion_data(Onion_Client *onion_c, int friend_num, const uint8_t *data, unsigned int good = 0; - for (i = 0; i < num_good; ++i) { + for (unsigned int i = 0; i < num_good; ++i) { Onion_Path path; if (random_path(onion_c, &onion_c->onion_paths_friends, -1, &path) == -1) { @@ -1210,7 +1213,8 @@ static int send_dhtpk_announce(Onion_Client *onion_c, uint16_t friend_num, uint8 } } - int num1 = -1, num2 = -1; + int num1 = -1; + int num2 = -1; if (onion_dht_both != 1) { num1 = send_onion_data(onion_c, friend_num, data, DHTPK_DATA_MIN_LENGTH + nodes_len); @@ -1289,9 +1293,9 @@ int onion_addfriend(Onion_Client *onion_c, const uint8_t *public_key) return num; } - unsigned int i, index = -1; + unsigned int index = -1; - for (i = 0; i < onion_c->num_friends; ++i) { + for (unsigned int i = 0; i < onion_c->num_friends; ++i) { if (onion_c->friends_list[i].status == 0) { index = i; break; @@ -1659,10 +1663,10 @@ void oniondata_registerhandler(Onion_Client *onion_c, uint8_t byte, oniondata_ha static void do_announce(Onion_Client *onion_c) { - unsigned int i, count = 0; + unsigned int count = 0; Onion_Node *list_nodes = onion_c->clients_announce_list; - for (i = 0; i < MAX_ONION_CLIENTS_ANNOUNCE; ++i) { + for (unsigned int i = 0; i < MAX_ONION_CLIENTS_ANNOUNCE; ++i) { if (onion_node_timed_out(&list_nodes[i], onion_c->mono_time)) { continue; } @@ -1735,7 +1739,7 @@ static void do_announce(Onion_Client *onion_c) if (count <= random_u32() % MAX_ONION_CLIENTS_ANNOUNCE) { if (num_nodes != 0) { - for (i = 0; i < (MAX_ONION_CLIENTS_ANNOUNCE / 2); ++i) { + for (unsigned int i = 0; i < (MAX_ONION_CLIENTS_ANNOUNCE / 2); ++i) { const uint32_t num = random_u32() % num_nodes; client_send_announce_request(onion_c, 0, path_nodes[num].ip_port, path_nodes[num].public_key, nullptr, -1); } @@ -1749,7 +1753,8 @@ static void do_announce(Onion_Client *onion_c) */ static int onion_isconnected(const Onion_Client *onion_c) { - unsigned int i, num = 0, announced = 0; + unsigned int num = 0; + unsigned int announced = 0; if (mono_time_is_timeout(onion_c->mono_time, onion_c->last_packet_recv, ONION_OFFLINE_TIMEOUT)) { return 0; @@ -1759,7 +1764,7 @@ static int onion_isconnected(const Onion_Client *onion_c) return 0; } - for (i = 0; i < MAX_ONION_CLIENTS_ANNOUNCE; ++i) { + for (unsigned int i = 0; i < MAX_ONION_CLIENTS_ANNOUNCE; ++i) { if (!onion_node_timed_out(&onion_c->clients_announce_list[i], onion_c->mono_time)) { ++num; diff --git a/toxcore/tox.c b/toxcore/tox.c index d2d3ed34..780d9136 100644 --- a/toxcore/tox.c +++ b/toxcore/tox.c @@ -400,7 +400,8 @@ Tox *tox_new(const struct Tox_Options *options, Tox_Err_New *error) Messenger_Options m_options = {0}; - bool load_savedata_sk = false, load_savedata_tox = false; + bool load_savedata_sk = false; + bool load_savedata_tox = false; struct Tox_Options *default_options = nullptr; -- cgit v1.2.3