diff --git a/.github/settings.yml b/.github/settings.yml index c2e5af16ba..7953182b0e 100644 --- a/.github/settings.yml +++ b/.github/settings.yml @@ -12,23 +12,23 @@ branches: protection: required_status_checks: contexts: - - build-bootstrapd-docker - - build-compcert - - build-macos - - build-nacl - - build-tcc - - build-win32 - - build-win64 - - CodeFactor + - "bazel-release" + - "build-bootstrapd-docker" + - "build-compcert" + - "build-macos" + - "build-nacl" + - "build-tcc" + - "build-win32" + - "build-win64" + - "CodeFactor" - "ci/circleci: asan" - "ci/circleci: clang-tidy" - "ci/circleci: infer" - "ci/circleci: static-analysis" - "ci/circleci: tsan" - - cimple - - cirrus-ci - - code-review/reviewable - - continuous-integration/appveyor/pr + - "cimple" + - "code-review/reviewable" + - "continuous-integration/appveyor/pr" # Labels specific to c-toxcore. labels: diff --git a/other/bootstrap_daemon/docker/tox-bootstrapd.sha256 b/other/bootstrap_daemon/docker/tox-bootstrapd.sha256 index 765960a1f7..49a5f537b6 100644 --- a/other/bootstrap_daemon/docker/tox-bootstrapd.sha256 +++ b/other/bootstrap_daemon/docker/tox-bootstrapd.sha256 @@ -1 +1 @@ -f0f315faebe7fc88b15ba656c5866c3932b5495c23ee99bdac539ba986688c92 /usr/local/bin/tox-bootstrapd +2b75296c24edbefa40809eeef66fa74791e28da407ee9364fb8e516c2ee882aa /usr/local/bin/tox-bootstrapd diff --git a/toxcore/Messenger.c b/toxcore/Messenger.c index bf1a3c4016..2c201aabac 100644 --- a/toxcore/Messenger.c +++ b/toxcore/Messenger.c @@ -66,9 +66,7 @@ static int realloc_friendlist(Messenger *m, uint32_t num) */ int32_t getfriend_id(const Messenger *m, const uint8_t *real_pk) { - uint32_t i; - - for (i = 0; i < m->numfriends; ++i) { + for (uint32_t i = 0; i < m->numfriends; ++i) { if (m->friendlist[i].status > 0) { if (id_equal(real_pk, m->friendlist[i].real_pk)) { return i; @@ -114,9 +112,8 @@ static uint16_t address_checksum(const uint8_t *address, uint32_t len) { uint8_t checksum[2] = {0}; uint16_t check; - uint32_t i; - for (i = 0; i < len; ++i) { + for (uint32_t i = 0; i < len; ++i) { checksum[i % 2] ^= address[i]; } @@ -181,9 +178,7 @@ static int32_t init_new_friend(Messenger *m, const uint8_t *real_pk, uint8_t sta return FAERR_NOMEM; } - uint32_t i; - - for (i = 0; i <= m->numfriends; ++i) { + for (uint32_t i = 0; i <= m->numfriends; ++i) { if (m->friendlist[i].status == NOFRIEND) { m->friendlist[i].status = status; m->friendlist[i].friendcon_id = friendcon_id; @@ -422,6 +417,7 @@ int m_delfriend(Messenger *m, int32_t friendnumber) kill_friend_connection(m->fr_c, m->friendlist[friendnumber].friendcon_id); memset(&m->friendlist[friendnumber], 0, sizeof(Friend)); + uint32_t i; for (i = m->numfriends; i != 0; --i) { @@ -595,9 +591,8 @@ int setname(Messenger *m, const uint8_t *name, uint16_t length) } m->name_length = length; - uint32_t i; - for (i = 0; i < m->numfriends; ++i) { + for (uint32_t i = 0; i < m->numfriends; ++i) { m->friendlist[i].name_sent = 0; } @@ -666,9 +661,7 @@ int m_set_statusmessage(Messenger *m, const uint8_t *status, uint16_t length) m->statusmessage_length = length; - uint32_t i; - - for (i = 0; i < m->numfriends; ++i) { + for (uint32_t i = 0; i < m->numfriends; ++i) { m->friendlist[i].statusmessage_sent = 0; } @@ -686,9 +679,8 @@ int m_set_userstatus(Messenger *m, uint8_t status) } m->userstatus = (Userstatus)status; - uint32_t i; - for (i = 0; i < m->numfriends; ++i) { + for (uint32_t i = 0; i < m->numfriends; ++i) { m->friendlist[i].userstatus_sent = 0; } @@ -2026,8 +2018,6 @@ void kill_messenger(Messenger *m) return; } - uint32_t i; - if (m->tcp_server) { kill_TCP_server(m->tcp_server); } @@ -2040,7 +2030,7 @@ void kill_messenger(Messenger *m) kill_dht(m->dht); kill_networking(m->net); - for (i = 0; i < m->numfriends; ++i) { + for (uint32_t i = 0; i < m->numfriends; ++i) { clear_receipts(m, i); } @@ -2399,10 +2389,9 @@ static int m_handle_packet(void *object, int i, const uint8_t *temp, uint16_t le static void do_friends(Messenger *m, void *userdata) { - uint32_t i; uint64_t temp_time = mono_time_get(m->mono_time); - for (i = 0; i < m->numfriends; ++i) { + for (uint32_t i = 0; i < m->numfriends; ++i) { if (m->friendlist[i].status == FRIEND_ADDED) { int fr = send_friend_request_packet(m->fr_c, m->friendlist[i].friendcon_id, m->friendlist[i].friendrequest_nospam, m->friendlist[i].info, @@ -2969,10 +2958,9 @@ static State_Load_Status friends_list_load(Messenger *m, const uint8_t *data, ui } uint32_t num = length / l_friend_size; - uint32_t i; const uint8_t *cur_data = data; - for (i = 0; i < num; ++i) { + for (uint32_t i = 0; i < num; ++i) { struct Saved_Friend temp = { 0 }; const uint8_t *next_data = friend_load(&temp, cur_data); assert(next_data - cur_data == l_friend_size); @@ -3200,9 +3188,8 @@ bool messenger_load_state_section(Messenger *m, const uint8_t *data, uint32_t le uint32_t count_friendlist(const Messenger *m) { uint32_t ret = 0; - uint32_t i; - for (i = 0; i < m->numfriends; ++i) { + for (uint32_t i = 0; i < m->numfriends; ++i) { if (m->friendlist[i].status > 0) { ++ret; } @@ -3226,10 +3213,9 @@ uint32_t copy_friendlist(Messenger const *m, uint32_t *out_list, uint32_t list_s return 0; } - uint32_t i; uint32_t ret = 0; - for (i = 0; i < m->numfriends; ++i) { + for (uint32_t i = 0; i < m->numfriends; ++i) { if (ret >= list_size) { break; /* Abandon ship */ } diff --git a/toxcore/TCP_connection.c b/toxcore/TCP_connection.c index e128ca0fbf..b4915822df 100644 --- a/toxcore/TCP_connection.c +++ b/toxcore/TCP_connection.c @@ -299,12 +299,11 @@ int send_packet_tcp_connection(TCP_Connections *tcp_c, int connections_number, c // TODO(irungentoo): detect and kill bad relays. // TODO(irungentoo): thread safety? - unsigned int i; int ret = -1; bool limit_reached = 0; - for (i = 0; i < MAX_FRIEND_TCP_CONNECTIONS; ++i) { + for (unsigned int i = 0; i < MAX_FRIEND_TCP_CONNECTIONS; ++i) { uint32_t tcp_con_num = con_to->connections[i].tcp_connection; uint8_t status = con_to->connections[i].status; uint8_t connection_id = con_to->connections[i].connection_id; @@ -337,7 +336,7 @@ int send_packet_tcp_connection(TCP_Connections *tcp_c, int connections_number, c ret = 0; /* Send oob packets to all relays tied to the connection. */ - for (i = 0; i < MAX_FRIEND_TCP_CONNECTIONS; ++i) { + for (unsigned int i = 0; i < MAX_FRIEND_TCP_CONNECTIONS; ++i) { uint32_t tcp_con_num = con_to->connections[i].tcp_connection; uint8_t status = con_to->connections[i].status; @@ -488,9 +487,7 @@ void set_onion_packet_tcp_connection_callback(TCP_Connections *tcp_c, tcp_onion_ */ static int find_tcp_connection_to(TCP_Connections *tcp_c, const uint8_t *public_key) { - unsigned int i; - - 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) { @@ -570,9 +567,7 @@ int kill_tcp_connection_to(TCP_Connections *tcp_c, int connections_number) return -1; } - unsigned int i; - - 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) { unsigned int tcp_connections_number = con_to->connections[i].tcp_connection - 1; TCP_con *tcp_con = get_tcp_connection(tcp_c, tcp_connections_number); @@ -622,9 +617,7 @@ int set_tcp_connection_to_status(TCP_Connections *tcp_c, int connections_number, return -1; } - unsigned int i; - - 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) { unsigned int tcp_connections_number = con_to->connections[i].tcp_connection - 1; TCP_con *tcp_con = get_tcp_connection(tcp_c, tcp_connections_number); @@ -648,9 +641,7 @@ int set_tcp_connection_to_status(TCP_Connections *tcp_c, int connections_number, return -1; } - unsigned int i; - - 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) { unsigned int tcp_connections_number = con_to->connections[i].tcp_connection - 1; TCP_con *tcp_con = get_tcp_connection(tcp_c, tcp_connections_number); @@ -671,9 +662,7 @@ int set_tcp_connection_to_status(TCP_Connections *tcp_c, int connections_number, static bool tcp_connection_in_conn(TCP_Connection_to *con_to, unsigned int tcp_connections_number) { - unsigned int i; - - 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 == (tcp_connections_number + 1)) { return 1; } @@ -687,13 +676,11 @@ static bool tcp_connection_in_conn(TCP_Connection_to *con_to, unsigned int tcp_c */ static int add_tcp_connection_to_conn(TCP_Connection_to *con_to, unsigned int tcp_connections_number) { - unsigned int i; - if (tcp_connection_in_conn(con_to, tcp_connections_number)) { return -1; } - 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 == 0) { con_to->connections[i].tcp_connection = tcp_connections_number + 1; con_to->connections[i].status = TCP_CONNECTIONS_STATUS_NONE; @@ -710,9 +697,7 @@ static int add_tcp_connection_to_conn(TCP_Connection_to *con_to, unsigned int tc */ static int rm_tcp_connection_from_conn(TCP_Connection_to *con_to, unsigned int tcp_connections_number) { - unsigned int i; - - 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 == (tcp_connections_number + 1)) { con_to->connections[i].tcp_connection = 0; con_to->connections[i].status = TCP_CONNECTIONS_STATUS_NONE; @@ -778,9 +763,7 @@ int kill_tcp_relay_connection(TCP_Connections *tcp_c, int tcp_connections_number return -1; } - unsigned int i; - - 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) { @@ -821,9 +804,7 @@ static int reconnect_tcp_relay_connection(TCP_Connections *tcp_c, int tcp_connec return -1; } - unsigned int i; - - 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) { @@ -867,9 +848,7 @@ static int sleep_tcp_relay_connection(TCP_Connections *tcp_c, int tcp_connection kill_TCP_connection(tcp_con->connection); tcp_con->connection = nullptr; - unsigned int i; - - 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/TCP_server.c b/toxcore/TCP_server.c index e978cdc6cd..252bcb0375 100644 --- a/toxcore/TCP_server.c +++ b/toxcore/TCP_server.c @@ -542,9 +542,7 @@ static int kill_accepted(TCP_Server *tcp_server, int index) return -1; } - uint32_t i; - - for (i = 0; i < NUM_CLIENT_CONNECTIONS; ++i) { + for (uint32_t i = 0; i < NUM_CLIENT_CONNECTIONS; ++i) { rm_connection_index(tcp_server, &tcp_server->accepted_connection_array[index], i); } @@ -670,7 +668,6 @@ static int send_disconnect_notification(TCP_Secure_Connection *con, uint8_t id) */ static int handle_TCP_routing_req(TCP_Server *tcp_server, uint32_t con_id, const uint8_t *public_key) { - uint32_t i; uint32_t index = -1; TCP_Secure_Connection *con = &tcp_server->accepted_connection_array[con_id]; @@ -683,7 +680,7 @@ static int handle_TCP_routing_req(TCP_Server *tcp_server, uint32_t con_id, const return 0; } - for (i = 0; i < NUM_CLIENT_CONNECTIONS; ++i) { + for (uint32_t i = 0; i < NUM_CLIENT_CONNECTIONS; ++i) { if (con->connections[i].status != 0) { if (public_key_cmp(public_key, con->connections[i].public_key) == 0) { if (send_routing_response(con, i + NUM_RESERVED_PORTS, public_key) == -1) { @@ -723,7 +720,7 @@ static int handle_TCP_routing_req(TCP_Server *tcp_server, uint32_t con_id, const uint32_t other_id = -1; TCP_Secure_Connection *other_conn = &tcp_server->accepted_connection_array[other_index]; - for (i = 0; i < NUM_CLIENT_CONNECTIONS; ++i) { + for (uint32_t i = 0; i < NUM_CLIENT_CONNECTIONS; ++i) { if (other_conn->connections[i].status == 1 && public_key_cmp(other_conn->connections[i].public_key, con->public_key) == 0) { other_id = i; @@ -785,10 +782,9 @@ static int rm_connection_index(TCP_Server *tcp_server, TCP_Secure_Connection *co } if (con->connections[con_number].status) { - uint32_t index = con->connections[con_number].index; - uint8_t other_id = con->connections[con_number].other_id; - if (con->connections[con_number].status == 2) { + const uint32_t index = con->connections[con_number].index; + const uint8_t other_id = con->connections[con_number].other_id; if (index >= tcp_server->size_accepted_connections) { return -1; @@ -1096,16 +1092,13 @@ TCP_Server *new_TCP_server(const Logger *logger, uint8_t ipv6_enabled, uint16_t const Family family = ipv6_enabled ? net_family_ipv6 : net_family_ipv4; - uint32_t i; -#ifdef TCP_SERVER_USE_EPOLL - struct epoll_event ev; -#endif - - for (i = 0; i < num_sockets; ++i) { + for (uint32_t i = 0; i < num_sockets; ++i) { Socket sock = new_listening_TCP_socket(family, ports[i]); if (sock_valid(sock)) { #ifdef TCP_SERVER_USE_EPOLL + struct epoll_event ev; + ev.events = EPOLLIN | EPOLLET; ev.data.u64 = sock.socket | ((uint64_t)TCP_SOCKET_LISTENING << 32); @@ -1142,9 +1135,7 @@ TCP_Server *new_TCP_server(const Logger *logger, uint8_t ipv6_enabled, uint16_t #ifndef TCP_SERVER_USE_EPOLL static void do_TCP_accept_new(TCP_Server *tcp_server) { - uint32_t i; - - for (i = 0; i < tcp_server->num_listening_socks; ++i) { + for (uint32_t i = 0; i < tcp_server->num_listening_socks; ++i) { Socket sock; do { @@ -1266,9 +1257,8 @@ static void do_TCP_confirmed(TCP_Server *tcp_server, const Mono_Time *mono_time) tcp_server->last_run_pinged = mono_time_get(mono_time); #endif - uint32_t i; - for (i = 0; i < tcp_server->size_accepted_connections; ++i) { + for (uint32_t i = 0; i < tcp_server->size_accepted_connections; ++i) { TCP_Secure_Connection *conn = &tcp_server->accepted_connection_array[i]; if (conn->status != TCP_STATUS_CONFIRMED) { diff --git a/toxcore/net_crypto.c b/toxcore/net_crypto.c index 072721c762..505425a472 100644 --- a/toxcore/net_crypto.c +++ b/toxcore/net_crypto.c @@ -3051,9 +3051,7 @@ void do_net_crypto(Net_Crypto *c, void *userdata) void kill_net_crypto(Net_Crypto *c) { - uint32_t i; - - for (i = 0; i < c->crypto_connections_length; ++i) { + for (uint32_t i = 0; i < c->crypto_connections_length; ++i) { crypto_kill(c, i); } diff --git a/toxcore/onion_announce.c b/toxcore/onion_announce.c index 8fb75a178e..03e77e856c 100644 --- a/toxcore/onion_announce.c +++ b/toxcore/onion_announce.c @@ -246,9 +246,7 @@ static void generate_ping_id(const Onion_Announce *onion_a, uint64_t time, const */ static int in_entries(const Onion_Announce *onion_a, const uint8_t *public_key) { - unsigned int i; - - for (i = 0; i < ONION_ANNOUNCE_MAX_ENTRIES; ++i) { + for (unsigned int i = 0; i < ONION_ANNOUNCE_MAX_ENTRIES; ++i) { if (!mono_time_is_timeout(onion_a->mono_time, onion_a->entries[i].time, ONION_ANNOUNCE_TIMEOUT) && public_key_cmp(onion_a->entries[i].public_key, public_key) == 0) { return i; diff --git a/toxcore/onion_client.c b/toxcore/onion_client.c index c9f1dd3e5e..83bf748896 100644 --- a/toxcore/onion_client.c +++ b/toxcore/onion_client.c @@ -153,9 +153,7 @@ int onion_add_bs_path_node(Onion_Client *onion_c, IP_Port ip_port, const uint8_t return -1; } - unsigned int i; - - for (i = 0; i < MAX_PATH_NODES; ++i) { + for (unsigned int i = 0; i < MAX_PATH_NODES; ++i) { if (public_key_cmp(public_key, onion_c->path_nodes_bs[i].public_key) == 0) { return -1; } @@ -186,9 +184,7 @@ static int onion_add_path_node(Onion_Client *onion_c, IP_Port ip_port, const uin return -1; } - unsigned int i; - - for (i = 0; i < MAX_PATH_NODES; ++i) { + for (unsigned int i = 0; i < MAX_PATH_NODES; ++i) { if (public_key_cmp(public_key, onion_c->path_nodes[i].public_key) == 0) { return -1; } @@ -251,8 +247,6 @@ uint16_t onion_backup_nodes(const Onion_Client *onion_c, Node_format *nodes, uin */ static uint16_t random_nodes_path_onion(const Onion_Client *onion_c, Node_format *nodes, uint16_t max_num) { - unsigned int i; - if (!max_num) { return 0; } @@ -265,7 +259,7 @@ static uint16_t random_nodes_path_onion(const Onion_Client *onion_c, Node_format return 0; } - for (i = 0; i < max_num; ++i) { + for (unsigned int i = 0; i < max_num; ++i) { nodes[i] = onion_c->path_nodes[random_u32() % num_nodes]; } } else { @@ -279,7 +273,7 @@ static uint16_t random_nodes_path_onion(const Onion_Client *onion_c, Node_format nodes[0].ip_port.ip.family = net_family_tcp_family; nodes[0].ip_port.ip.ip.v4.uint32 = random_tcp; - for (i = 1; i < max_num; ++i) { + for (unsigned int i = 1; i < max_num; ++i) { nodes[i] = onion_c->path_nodes[random_u32() % num_nodes]; } } else { @@ -292,7 +286,7 @@ static uint16_t random_nodes_path_onion(const Onion_Client *onion_c, Node_format nodes[0].ip_port.ip.family = net_family_tcp_family; nodes[0].ip_port.ip.ip.v4.uint32 = random_tcp; - for (i = 1; i < max_num; ++i) { + for (unsigned int i = 1; i < max_num; ++i) { nodes[i] = onion_c->path_nodes_bs[random_u32() % num_nodes_bs]; } } @@ -307,9 +301,7 @@ static uint16_t random_nodes_path_onion(const Onion_Client *onion_c, Node_format */ static int is_path_used(const Mono_Time *mono_time, const Onion_Client_Paths *onion_paths, const Node_format *nodes) { - unsigned int i; - - for (i = 0; i < NUMBER_ONION_PATHS; ++i) { + for (unsigned int i = 0; i < NUMBER_ONION_PATHS; ++i) { if (mono_time_is_timeout(mono_time, onion_paths->last_path_success[i], ONION_PATH_TIMEOUT)) { continue; } @@ -437,9 +429,7 @@ static uint32_t set_path_timeouts(Onion_Client *onion_c, uint32_t num, uint32_t Node_format nodes[ONION_PATH_LENGTH]; if (onion_path_to_nodes(nodes, ONION_PATH_LENGTH, &onion_paths->paths[path_num % NUMBER_ONION_PATHS]) == 0) { - unsigned int i; - - for (i = 0; i < ONION_PATH_LENGTH; ++i) { + for (unsigned int i = 0; i < ONION_PATH_LENGTH; ++i) { onion_add_path_node(onion_c, nodes[i].ip_port, nodes[i].public_key); } } @@ -700,14 +690,13 @@ static int client_add_to_list(Onion_Client *onion_c, uint32_t num, const uint8_t int index = -1; int stored = 0; - unsigned int i; if (onion_node_timed_out(&list_nodes[0], onion_c->mono_time) || id_closest(reference_id, list_nodes[0].public_key, public_key) == 2) { index = 0; } - for (i = 0; i < list_length; ++i) { + for (unsigned int i = 0; i < list_length; ++i) { if (public_key_cmp(list_nodes[i].public_key, public_key) == 0) { index = i; stored = 1; @@ -747,9 +736,7 @@ static int client_add_to_list(Onion_Client *onion_c, uint32_t num, const uint8_t static int good_to_ping(Mono_Time *mono_time, Last_Pinged *last_pinged, uint8_t *last_pinged_index, const uint8_t *public_key) { - unsigned int i; - - for (i = 0; i < MAX_STORED_PINGED_NODES; ++i) { + for (unsigned int i = 0; i < MAX_STORED_PINGED_NODES; ++i) { if (!mono_time_is_timeout(mono_time, last_pinged[i].timestamp, MIN_NODE_PING_TIME)) { if (public_key_cmp(last_pinged[i].public_key, public_key) == 0) { return 0; @@ -982,9 +969,7 @@ static int handle_dhtpk_announce(void *object, const uint8_t *source_pubkey, con return 1; } - int i; - - for (i = 0; i < num_nodes; ++i) { + for (int i = 0; i < num_nodes; ++i) { const Family family = nodes[i].ip_port.ip.family; if (net_family_is_ipv4(family) || net_family_is_ipv6(family)) { @@ -1240,9 +1225,7 @@ static int send_dhtpk_announce(Onion_Client *onion_c, uint16_t friend_num, uint8 */ int onion_friend_num(const Onion_Client *onion_c, const uint8_t *public_key) { - unsigned int i; - - 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) { continue; } @@ -1500,9 +1483,7 @@ static void populate_path_nodes(Onion_Client *onion_c) unsigned int num_nodes = randfriends_nodes(onion_c->dht, nodes_list, MAX_FRIEND_CLIENTS); - unsigned int i; - - for (i = 0; i < num_nodes; ++i) { + for (unsigned int i = 0; i < num_nodes; ++i) { onion_add_path_node(onion_c, nodes_list[i].ip_port, nodes_list[i].public_key); } } @@ -1512,9 +1493,8 @@ static void populate_path_nodes_tcp(Onion_Client *onion_c) Node_format nodes_list[MAX_SENT_NODES]; unsigned int num_nodes = copy_connected_tcp_relays(onion_c->c, nodes_list, MAX_SENT_NODES); - unsigned int i; - for (i = 0; i < num_nodes; ++i) { + for (unsigned int i = 0; i < num_nodes; ++i) { onion_add_bs_path_node(onion_c, nodes_list[i].ip_port, nodes_list[i].public_key); } } @@ -1613,9 +1593,7 @@ static void do_friend(Onion_Client *onion_c, uint16_t friendnum) if (count <= random_u32() % MAX_ONION_CLIENTS) { if (num_nodes != 0) { - unsigned int j; - - for (j = 0; j < n; ++j) { + for (unsigned int j = 0; j < n; ++j) { const uint32_t num = random_u32() % num_nodes; client_send_announce_request(onion_c, friendnum + 1, onion_c->path_nodes[num].ip_port, onion_c->path_nodes[num].public_key, nullptr, -1); diff --git a/toxcore/ping.c b/toxcore/ping.c index d8952ddb0e..ea90428ea4 100644 --- a/toxcore/ping.c +++ b/toxcore/ping.c @@ -237,9 +237,7 @@ static int handle_ping_response(void *object, IP_Port source, const uint8_t *pac static int in_list(const Client_data *list, uint16_t length, const Mono_Time *mono_time, const uint8_t *public_key, IP_Port ip_port) { - unsigned int i; - - for (i = 0; i < length; ++i) { + for (unsigned int i = 0; i < length; ++i) { if (id_equal(list[i].public_key, public_key)) { const IPPTsPng *ipptp; @@ -289,9 +287,7 @@ int32_t ping_add(Ping *ping, const uint8_t *public_key, IP_Port ip_port) return -1; } - unsigned int i; - - for (i = 0; i < MAX_TO_PING; ++i) { + for (unsigned int i = 0; i < MAX_TO_PING; ++i) { if (!ip_isset(&ping->to_ping[i].ip_port.ip)) { memcpy(ping->to_ping[i].public_key, public_key, CRYPTO_PUBLIC_KEY_SIZE); ipport_copy(&ping->to_ping[i].ip_port, &ip_port);