From 4d73af56926f49bf11b9dac4012853f181a38232 Mon Sep 17 00:00:00 2001 From: jfreegman Date: Fri, 1 Apr 2022 17:59:28 -0400 Subject: [PATCH] Some minor fixes --- toxcore/Messenger.c | 2 +- toxcore/group_announce.c | 6 +++--- toxcore/group_chats.c | 34 +++++++++++++++++++++------------- toxcore/group_chats.h | 2 +- toxcore/group_pack.c | 2 +- toxcore/onion_client.c | 2 +- toxcore/tox.c | 2 +- 7 files changed, 29 insertions(+), 21 deletions(-) diff --git a/toxcore/Messenger.c b/toxcore/Messenger.c index 0df5d1b29b..f3fe2443ac 100644 --- a/toxcore/Messenger.c +++ b/toxcore/Messenger.c @@ -2484,7 +2484,7 @@ uint32_t messenger_run_interval(const Messenger *m) non_null() static bool self_announce_group(const Messenger *m, GC_Chat *chat, Onion_Friend *onion_friend) { - GC_Public_Announce announce = {{{0}}}; + GC_Public_Announce announce = {{0}}; const bool ip_port_is_set = chat->self_udp_status != SELF_UDP_STATUS_NONE; const int tcp_num = tcp_copy_connected_relays(chat->tcp_conn, announce.base_announce.tcp_relays, diff --git a/toxcore/group_announce.c b/toxcore/group_announce.c index 728b71d16e..50867fce74 100644 --- a/toxcore/group_announce.c +++ b/toxcore/group_announce.c @@ -191,7 +191,7 @@ static int gca_unpack_announce(const Logger *log, const uint8_t *data, uint16_t } if (announce->ip_port_is_set) { - const int ip_port_length = unpack_ip_port(&announce->ip_port, data + offset, length - offset, 0); + const int ip_port_length = unpack_ip_port(&announce->ip_port, data + offset, length - offset, false); if (ip_port_length == -1) { LOGGER_ERROR(log, "Failed to unpack ip_port"); @@ -203,7 +203,7 @@ static int gca_unpack_announce(const Logger *log, const uint8_t *data, uint16_t uint16_t nodes_length; const int nodes_count = unpack_nodes(announce->tcp_relays, announce->tcp_relays_count, &nodes_length, - data + offset, length - offset, 1); + data + offset, length - offset, true); if (nodes_count != announce->tcp_relays_count) { LOGGER_ERROR(log, "Failed to unpack TCP nodes"); @@ -396,7 +396,7 @@ void kill_gca(GC_Announces_List *announces_list) GC_Announces *root = announces_list->root_announces; - while (root) { + while (root != nullptr) { GC_Announces *next = root->next_announce; free(root); root = next; diff --git a/toxcore/group_chats.c b/toxcore/group_chats.c index 0f8811246f..77c49897f9 100644 --- a/toxcore/group_chats.c +++ b/toxcore/group_chats.c @@ -2014,7 +2014,7 @@ static int handle_gc_tcp_relays(GC_Chat *chat, GC_Connection *gconn, const uint8 } Node_format tcp_relays[GCC_MAX_TCP_SHARED_RELAYS]; - const int num_nodes = unpack_nodes(tcp_relays, GCC_MAX_TCP_SHARED_RELAYS, nullptr, data, length, 1); + const int num_nodes = unpack_nodes(tcp_relays, GCC_MAX_TCP_SHARED_RELAYS, nullptr, data, length, true); if (num_nodes <= 0) { return -2; @@ -5605,7 +5605,7 @@ static int handle_gc_handshake_request(GC_Chat *chat, const IP_Port *ipp, const const int processed = ENC_PUBLIC_KEY_SIZE + SIG_PUBLIC_KEY_SIZE + 1; const int nodes_count = unpack_nodes(node, GCA_MAX_ANNOUNCED_TCP_RELAYS, nullptr, - data + processed, length - processed, 1); + data + processed, length - processed, true); if (nodes_count <= 0 && ipp == nullptr) { if (is_new_peer) { @@ -6131,11 +6131,19 @@ static int handle_gc_tcp_packet(void *object, int id, const uint8_t *packet, uin switch (packet_type) { case NET_PACKET_GC_LOSSLESS: { - return handle_gc_lossless_packet(c, chat, sender_pk, payload, payload_len, false, userdata); + if (!handle_gc_lossless_packet(c, chat, sender_pk, payload, payload_len, false, userdata)) { + return -1; + } + + return 0; } case NET_PACKET_GC_LOSSY: { - return handle_gc_lossy_packet(c, chat, sender_pk, payload, payload_len, false, userdata); + if (!handle_gc_lossy_packet(c, chat, sender_pk, payload, payload_len, false, userdata)) { + return -1; + } + + return 0; } case NET_PACKET_GC_HANDSHAKE: { @@ -6287,7 +6295,7 @@ static int handle_gc_udp_packet(void *object, const IP_Port *ipp, const uint8_t } } - return ret; + return ret ? 0 : -1; } void gc_callback_message(const Messenger *m, gc_message_cb *function) @@ -6948,7 +6956,7 @@ static void do_timed_out_reconn(GC_Chat *chat) if (mono_time_is_timeout(chat->mono_time, timeout->last_seen, GC_TIMED_OUT_STALE_TIMEOUT) || get_peer_number_of_enc_pk(chat, timeout->addr.public_key, true) != -1) { *timeout = (GC_TimedOutPeer) { - 0 + {{0}} }; continue; } @@ -7729,7 +7737,7 @@ int handle_gc_invite_confirmed_packet(const GC_Session *c, int friend_number, co Node_format tcp_relays[GCC_MAX_TCP_SHARED_RELAYS]; const int num_nodes = unpack_nodes(tcp_relays, GCC_MAX_TCP_SHARED_RELAYS, nullptr, data + ENC_PUBLIC_KEY_SIZE + CHAT_ID_SIZE, - length - GC_JOIN_DATA_LENGTH, 1); + length - GC_JOIN_DATA_LENGTH, true); const bool copy_ip_port_result = copy_friend_ip_port_to_gconn(c->messenger, friend_number, gconn); @@ -7808,10 +7816,10 @@ int handle_gc_invite_accepted_packet(const GC_Session *c, int friend_number, con } uint16_t len = GC_JOIN_DATA_LENGTH; - uint8_t send_data[GC_JOIN_DATA_LENGTH + (GCC_MAX_TCP_SHARED_RELAYS * PACKED_NODE_SIZE_IP6)]; + uint8_t out_data[GC_JOIN_DATA_LENGTH + (GCC_MAX_TCP_SHARED_RELAYS * PACKED_NODE_SIZE_IP6)]; - memcpy(send_data, chat_id, CHAT_ID_SIZE); - memcpy(send_data + CHAT_ID_SIZE, chat->self_public_key, ENC_PUBLIC_KEY_SIZE); + memcpy(out_data, chat_id, CHAT_ID_SIZE); + memcpy(out_data + CHAT_ID_SIZE, chat->self_public_key, ENC_PUBLIC_KEY_SIZE); if (num_tcp_relays > 0) { const uint32_t tcp_relays_added = add_gc_tcp_relays(chat, gconn, tcp_relays, num_tcp_relays); @@ -7821,7 +7829,7 @@ int handle_gc_invite_accepted_packet(const GC_Session *c, int friend_number, con return -1; } - const int nodes_len = pack_nodes(chat->log, send_data + len, sizeof(send_data) - len, tcp_relays, + const int nodes_len = pack_nodes(chat->log, out_data + len, sizeof(out_data) - len, tcp_relays, (uint16_t)num_tcp_relays); if (nodes_len <= 0 && !copy_ip_port_result) { @@ -7831,7 +7839,7 @@ int handle_gc_invite_accepted_packet(const GC_Session *c, int friend_number, con len += nodes_len; } - if (send_gc_invite_confirmed_packet(m, chat, friend_number, send_data, len)) { + if (send_gc_invite_confirmed_packet(m, chat, friend_number, out_data, len)) { return 0; } @@ -7890,7 +7898,7 @@ int gc_accept_invite(GC_Session *c, int32_t friend_number, const uint8_t *data, return -2; } - if (send_gc_invite_accepted_packet(c->messenger, chat, friend_number)) { + if (send_gc_invite_accepted_packet(c->messenger, chat, friend_number) != 0) { return -7; } diff --git a/toxcore/group_chats.h b/toxcore/group_chats.h index c478d0dd7f..3e809a79be 100644 --- a/toxcore/group_chats.h +++ b/toxcore/group_chats.h @@ -137,7 +137,7 @@ int get_peer_number_of_enc_pk(const GC_Chat *chat, const uint8_t *public_enc_key * Return -2 if malloc fails. * Return -3 if encryption fails. */ -non_null(1, 2, 3, 4) nullable(6) +non_null(1, 2, 3, 4, 5) nullable(7) int group_packet_wrap( const Logger *log, const Random *rng, const uint8_t *self_pk, const uint8_t *shared_key, uint8_t *packet, uint16_t packet_size, const uint8_t *data, uint16_t length, uint64_t message_id, diff --git a/toxcore/group_pack.c b/toxcore/group_pack.c index dc51a1f7bc..d6d657d87c 100644 --- a/toxcore/group_pack.c +++ b/toxcore/group_pack.c @@ -27,7 +27,7 @@ static bool load_unpack_state_values(GC_Chat *chat, Bin_Unpack *bu) return false; } - bool manually_disconnected = 0; + bool manually_disconnected = false; uint8_t privacy_state = 0; uint8_t voice_state = 0; diff --git a/toxcore/onion_client.c b/toxcore/onion_client.c index ff03c6a9dc..a8ccd84df1 100644 --- a/toxcore/onion_client.c +++ b/toxcore/onion_client.c @@ -993,7 +993,7 @@ static int handle_announce_response(void *object, const IP_Port *source, const u Node_format nodes[MAX_SENT_NODES]; const int num_nodes = unpack_nodes(nodes, nodes_count, &len_nodes, plain + 2 + ONION_PING_ID_SIZE, - plain_size - 2 - ONION_PING_ID_SIZE, 0); + plain_size - 2 - ONION_PING_ID_SIZE, false); if (num_nodes < 0) { return 1; diff --git a/toxcore/tox.c b/toxcore/tox.c index 4efedc22d9..01cd315352 100644 --- a/toxcore/tox.c +++ b/toxcore/tox.c @@ -3310,7 +3310,7 @@ Tox_Group_Role tox_group_self_get_role(const Tox *tox, uint32_t group_number, To SET_ERROR_PARAMETER(error, TOX_ERR_GROUP_SELF_QUERY_OK); - const uint8_t role = gc_get_self_role(chat); + const Group_Role role = gc_get_self_role(chat); tox_unlock(tox); return (Tox_Group_Role)role;