diff --git a/toxav/msi.c b/toxav/msi.c index a16d6bf1..736f7acb 100644 --- a/toxav/msi.c +++ b/toxav/msi.c @@ -381,7 +381,7 @@ static int msg_parse_in(const Logger *log, MSIMessage *dest, const uint8_t *data assert(dest != nullptr); - if (length == 0 || data[length - 1]) { /* End byte must have value 0 */ + if (length == 0 || data[length - 1] != 0) { /* End byte must have value 0 */ LOGGER_ERROR(log, "Invalid end byte"); return -1; } diff --git a/toxav/toxav.c b/toxav/toxav.c index ea389178..19cd7213 100644 --- a/toxav/toxav.c +++ b/toxav/toxav.c @@ -492,7 +492,7 @@ static Toxav_Err_Call_Control call_control_handle_resume(const ToxAVCall *call) static Toxav_Err_Call_Control call_control_handle_pause(ToxAVCall *call) { /* Only act if not already paused */ - if (!call->msi_call->self_capabilities) { + if (call->msi_call->self_capabilities == 0) { return TOXAV_ERR_CALL_CONTROL_INVALID_TRANSITION; } diff --git a/toxcore/Messenger.c b/toxcore/Messenger.c index 9a40dda7..7ef95567 100644 --- a/toxcore/Messenger.c +++ b/toxcore/Messenger.c @@ -627,7 +627,7 @@ int setname(Messenger *m, const uint8_t *name, uint16_t length) return 0; } - if (length) { + if (length > 0) { memcpy(m->name, name, length); } @@ -699,7 +699,7 @@ int m_set_statusmessage(Messenger *m, const uint8_t *status, uint16_t length) return 0; } - if (length) { + if (length > 0) { memcpy(m->statusmessage, status, length); } @@ -870,7 +870,7 @@ static int set_friend_statusmessage(const Messenger *m, int32_t friendnumber, co return -1; } - if (length) { + if (length > 0) { memcpy(m->friendlist[friendnumber].statusmessage, status, length); } @@ -974,8 +974,8 @@ static void check_friend_connectionstatus(Messenger *m, int32_t friendnumber, ui return; } - const uint8_t was_online = m->friendlist[friendnumber].status == FRIEND_ONLINE; - const uint8_t is_online = status == FRIEND_ONLINE; + const bool was_online = m->friendlist[friendnumber].status == FRIEND_ONLINE; + const bool is_online = status == FRIEND_ONLINE; if (is_online != was_online) { if (was_online) { @@ -1077,14 +1077,14 @@ int file_get_id(const Messenger *m, int32_t friendnumber, uint32_t filenumber, u } uint32_t temp_filenum; - uint8_t send_receive; + bool send_receive; uint8_t file_number; if (filenumber >= (1 << 16)) { - send_receive = 1; + send_receive = true; temp_filenum = (filenumber >> 16) - 1; } else { - send_receive = 0; + send_receive = false; temp_filenum = filenumber; } @@ -1134,7 +1134,7 @@ static int file_sendrequest(const Messenger *m, int32_t friendnumber, uint8_t fi net_pack_u64(packet + 1 + sizeof(file_type), filesize); memcpy(packet + 1 + sizeof(file_type) + sizeof(filesize), file_id, FILE_ID_LENGTH); - if (filename_length) { + if (filename_length > 0) { memcpy(packet + 1 + sizeof(file_type) + sizeof(filesize) + FILE_ID_LENGTH, filename, filename_length); } @@ -1195,7 +1195,7 @@ long int new_filesender(const Messenger *m, int32_t friendnumber, uint32_t file_ } non_null(1) nullable(6) -static int send_file_control_packet(const Messenger *m, int32_t friendnumber, uint8_t send_receive, uint8_t filenumber, +static int send_file_control_packet(const Messenger *m, int32_t friendnumber, bool send_receive, uint8_t filenumber, uint8_t control_type, const uint8_t *data, uint16_t data_length) { assert(data_length == 0 || data != nullptr); @@ -1206,11 +1206,11 @@ static int send_file_control_packet(const Messenger *m, int32_t friendnumber, ui VLA(uint8_t, packet, 3 + data_length); - packet[0] = send_receive; + packet[0] = send_receive ? 1 : 0; packet[1] = filenumber; packet[2] = control_type; - if (data_length) { + if (data_length > 0) { memcpy(packet + 3, data, data_length); } @@ -1240,14 +1240,14 @@ int file_control(const Messenger *m, int32_t friendnumber, uint32_t filenumber, } uint32_t temp_filenum; - uint8_t send_receive; + bool send_receive; uint8_t file_number; if (filenumber >= (1 << 16)) { - send_receive = 1; + send_receive = true; temp_filenum = (filenumber >> 16) - 1; } else { - send_receive = 0; + send_receive = false; temp_filenum = filenumber; } diff --git a/toxcore/group.c b/toxcore/group.c index 5cdbc31a..130c9847 100644 --- a/toxcore/group.c +++ b/toxcore/group.c @@ -298,7 +298,7 @@ static bool add_to_closest(Group_c *g, const uint8_t *real_pk, const uint8_t *te } for (unsigned int i = 0; i < DESIRED_CLOSEST; ++i) { - if (g->closest_peers[i].entry == 0) { + if (!g->closest_peers[i].entry) { index = i; break; } @@ -335,15 +335,15 @@ static bool add_to_closest(Group_c *g, const uint8_t *real_pk, const uint8_t *te uint8_t old_real_pk[CRYPTO_PUBLIC_KEY_SIZE]; uint8_t old_temp_pk[CRYPTO_PUBLIC_KEY_SIZE]; - uint8_t old = 0; + bool old = false; if (g->closest_peers[index].entry) { memcpy(old_real_pk, g->closest_peers[index].real_pk, CRYPTO_PUBLIC_KEY_SIZE); memcpy(old_temp_pk, g->closest_peers[index].temp_pk, CRYPTO_PUBLIC_KEY_SIZE); - old = 1; + old = true; } - g->closest_peers[index].entry = 1; + g->closest_peers[index].entry = true; memcpy(g->closest_peers[index].real_pk, real_pk, CRYPTO_PUBLIC_KEY_SIZE); memcpy(g->closest_peers[index].temp_pk, temp_pk, CRYPTO_PUBLIC_KEY_SIZE); @@ -351,7 +351,7 @@ static bool add_to_closest(Group_c *g, const uint8_t *real_pk, const uint8_t *te add_to_closest(g, old_real_pk, old_temp_pk); } - if (!g->changed) { + if (g->changed == GROUPCHAT_CLOSEST_CHANGE_NONE) { g->changed = GROUPCHAT_CLOSEST_CHANGE_ADDED; } @@ -428,11 +428,11 @@ static void add_closest_connections(Group_Chats *g_c, uint32_t groupnumber, void int friendcon_id = getfriend_conn_id_pk(g_c->fr_c, g->closest_peers[i].real_pk); - uint8_t fresh = 0; + bool fresh = false; if (friendcon_id == -1) { friendcon_id = new_friend_connection(g_c->fr_c, g->closest_peers[i].real_pk); - fresh = 1; + fresh = true; if (friendcon_id == -1) { continue; @@ -468,7 +468,7 @@ static bool connect_to_closest(Group_Chats *g_c, uint32_t groupnumber, void *use return false; } - if (!g->changed) { + if (g->changed == GROUPCHAT_CLOSEST_CHANGE_NONE) { return true; } @@ -718,7 +718,7 @@ static void remove_from_closest(Group_c *g, int peer_index) for (uint32_t i = 0; i < DESIRED_CLOSEST; ++i) { if (g->closest_peers[i].entry && id_equal(g->closest_peers[i].real_pk, g->group[peer_index].real_pk)) { - g->closest_peers[i].entry = 0; + g->closest_peers[i].entry = false; g->changed = GROUPCHAT_CLOSEST_CHANGE_REMOVED; break; } @@ -905,7 +905,7 @@ static bool setnick(Group_Chats *g_c, uint32_t groupnumber, int peer_index, cons return true; } - if (nick_len) { + if (nick_len != 0) { memcpy(g->group[peer_index].nick, nick, nick_len); } @@ -1040,7 +1040,7 @@ static int g_handle_any_status(void *object, int friendcon_id, bool status, void { Group_Chats *g_c = (Group_Chats *)object; - if (status) { + if (status != 0) { rejoin_frozen_friend(g_c, friendcon_id); } @@ -1052,7 +1052,7 @@ static int g_handle_status(void *object, int friendcon_id, bool status, void *us { Group_Chats *g_c = (Group_Chats *)object; - if (status) { /* Went online */ + if (status != 0) { /* Went online */ set_conns_status_groups(g_c, friendcon_id, GROUPCHAT_CONNECTION_ONLINE, userdata); } else { /* Went offline */ set_conns_status_groups(g_c, friendcon_id, GROUPCHAT_CONNECTION_CONNECTING, userdata); @@ -1095,7 +1095,7 @@ static int add_conn_to_groupchat(Group_Chats *g_c, int friendcon_id, Group_c *g, return -1; } - if (lock) { + if (lock != 0) { friend_connection_lock(g_c->fr_c, friendcon_id); } @@ -2276,7 +2276,7 @@ static unsigned int send_peers(const Group_Chats *g_c, const Group_c *g, int fri p += g->group[i].nick_len; } - if (g->title_len) { + if (g->title_len > 0) { VLA(uint8_t, title_packet, 1 + g->title_len); title_packet[0] = PEER_TITLE_ID; memcpy(title_packet + 1, g->title, g->title_len); @@ -2467,7 +2467,7 @@ static unsigned int send_lossy_all_connections(const Group_Chats *g_c, const Gro const uint64_t comp_val = calculate_comp_value(g->real_pk, real_pk); for (uint8_t j = 0; j < 2; ++j) { - if (j ? (comp_val > comp_val_old[j]) : (comp_val < comp_val_old[j])) { + if (j > 0 ? (comp_val > comp_val_old[j]) : (comp_val < comp_val_old[j])) { to_send[j] = connected_closest[i]; comp_val_old[j] = comp_val; } @@ -2475,7 +2475,7 @@ static unsigned int send_lossy_all_connections(const Group_Chats *g_c, const Gro } for (uint8_t j = 0; j < 2; ++j) { - if (j && to_send[1] == to_send[0]) { + if (j > 0 && to_send[1] == to_send[0]) { break; } @@ -2902,7 +2902,7 @@ static int lossy_packet_not_received(const Group_c *g, int peer_index, uint16_t } if ((uint16_t)(message_number - g->group[peer_index].bottom_lossy_number) < MAX_LOSSY_COUNT) { - if (g->group[peer_index].recv_lossy[message_number % MAX_LOSSY_COUNT]) { + if (g->group[peer_index].recv_lossy[message_number % MAX_LOSSY_COUNT] != 0) { return 1; } diff --git a/toxcore/group.h b/toxcore/group.h index 743f95aa..a298cbe1 100644 --- a/toxcore/group.h +++ b/toxcore/group.h @@ -83,7 +83,7 @@ typedef struct Groupchat_Connection { } Groupchat_Connection; typedef struct Groupchat_Closest { - uint8_t entry; + bool entry; uint8_t real_pk[CRYPTO_PUBLIC_KEY_SIZE]; uint8_t temp_pk[CRYPTO_PUBLIC_KEY_SIZE]; } Groupchat_Closest; diff --git a/toxcore/onion_client.c b/toxcore/onion_client.c index 424f633e..6565bfc8 100644 --- a/toxcore/onion_client.c +++ b/toxcore/onion_client.c @@ -56,9 +56,9 @@ typedef struct Last_Pinged { typedef struct Onion_Friend { uint8_t status; /* 0 if friend is not valid, 1 if friend is valid.*/ - uint8_t is_online; /* Set by the onion_set_friend_status function. */ + bool is_online; - uint8_t know_dht_public_key; /* 0 if we don't know the dht public key of the other, 1 if we do. */ + bool know_dht_public_key; uint8_t dht_public_key[CRYPTO_PUBLIC_KEY_SIZE]; uint8_t real_public_key[CRYPTO_PUBLIC_KEY_SIZE]; @@ -212,7 +212,7 @@ static int onion_add_path_node(Onion_Client *onion_c, const IP_Port *ip_port, co */ uint16_t onion_backup_nodes(const Onion_Client *onion_c, Node_format *nodes, uint16_t max_num) { - if (!max_num) { + if (max_num == 0) { return 0; } @@ -1078,7 +1078,7 @@ int send_onion_data(Onion_Client *onion_c, int friend_num, const uint8_t *data, ++num_nodes; - if (list_nodes[i].is_stored) { + if (list_nodes[i].is_stored != 0) { good_nodes[num_good] = i; ++num_good; } @@ -1441,7 +1441,7 @@ int onion_set_friend_DHT_pubkey(Onion_Client *onion_c, int friend_num, const uin } onion_c->friends_list[friend_num].last_seen = mono_time_get(onion_c->mono_time); - onion_c->friends_list[friend_num].know_dht_public_key = 1; + onion_c->friends_list[friend_num].know_dht_public_key = true; memcpy(onion_c->friends_list[friend_num].dht_public_key, dht_key, CRYPTO_PUBLIC_KEY_SIZE); return 0; @@ -1492,19 +1492,16 @@ int onion_getfriendip(const Onion_Client *onion_c, int friend_num, IP_Port *ip_p /** Set if friend is online or not. * NOTE: This function is there and should be used so that we don't send useless packets to the friend if he is online. * - * is_online 1 means friend is online. - * is_online 0 means friend is offline - * * return -1 on failure. * return 0 on success. */ -int onion_set_friend_online(Onion_Client *onion_c, int friend_num, uint8_t is_online) +int onion_set_friend_online(Onion_Client *onion_c, int friend_num, bool is_online) { if ((uint32_t)friend_num >= onion_c->num_friends) { return -1; } - if (is_online == 0 && onion_c->friends_list[friend_num].is_online == 1) { + if (!is_online && onion_c->friends_list[friend_num].is_online) { onion_c->friends_list[friend_num].last_seen = mono_time_get(onion_c->mono_time); } @@ -1791,7 +1788,7 @@ static int onion_isconnected(const Onion_Client *onion_c) if (!onion_node_timed_out(&onion_c->clients_announce_list[i], onion_c->mono_time)) { ++num; - if (onion_c->clients_announce_list[i].is_stored) { + if (onion_c->clients_announce_list[i].is_stored != 0) { ++announced; } } diff --git a/toxcore/onion_client.h b/toxcore/onion_client.h index 050d1058..b5b0f6ae 100644 --- a/toxcore/onion_client.h +++ b/toxcore/onion_client.h @@ -10,6 +10,8 @@ #ifndef C_TOXCORE_TOXCORE_ONION_CLIENT_H #define C_TOXCORE_TOXCORE_ONION_CLIENT_H +#include + #include "net_crypto.h" #include "onion_announce.h" #include "ping_array.h" @@ -99,14 +101,11 @@ int onion_delfriend(Onion_Client *onion_c, int friend_num); /** Set if friend is online or not. * NOTE: This function is there and should be used so that we don't send useless packets to the friend if he is online. * - * is_online 1 means friend is online. - * is_online 0 means friend is offline - * * return -1 on failure. * return 0 on success. */ non_null() -int onion_set_friend_online(Onion_Client *onion_c, int friend_num, uint8_t is_online); +int onion_set_friend_online(Onion_Client *onion_c, int friend_num, bool is_online); /** Get the ip of friend friendnum and put it in ip_port *