From fde015b2b46cd65988c85a5abbc8cfac6b2f6d16 Mon Sep 17 00:00:00 2001 From: iphydf Date: Tue, 22 Feb 2022 21:10:50 +0000 Subject: [PATCH] cleanup: Remove implicit conversions from `uint32_t` to `bool`. --- toxav/bwcontroller.c | 4 ++-- toxav/toxav.c | 12 ++++++------ toxcore/DHT.c | 4 ++-- toxcore/DHT.h | 2 +- toxcore/TCP_connection.c | 16 ++++++++-------- toxcore/group.c | 2 +- toxcore/list.c | 2 +- 7 files changed, 21 insertions(+), 21 deletions(-) diff --git a/toxav/bwcontroller.c b/toxav/bwcontroller.c index 713f4f1f3f4..49e24ba7003 100644 --- a/toxav/bwcontroller.c +++ b/toxav/bwcontroller.c @@ -133,7 +133,7 @@ static void send_update(BWController *bwc) current_time_monotonic(bwc->bwc_mono_time) - bwc->cycle.last_sent_timestamp > BWC_SEND_INTERVAL_MS) { bwc->packet_loss_counted_cycles = 0; - if (bwc->cycle.lost) { + if (bwc->cycle.lost != 0) { LOGGER_DEBUG(bwc->m->log, "%p Sent update rcv: %u lost: %u percent: %f %%", (void *)bwc, bwc->cycle.recv, bwc->cycle.lost, ((double)bwc->cycle.lost / (bwc->cycle.recv + bwc->cycle.lost)) * 100.0); @@ -178,7 +178,7 @@ static int on_update(BWController *bwc, const struct BWCMessage *msg) const uint32_t recv = msg->recv; const uint32_t lost = msg->lost; - if (lost && bwc->mcb != nullptr) { + if (lost != 0 && bwc->mcb != nullptr) { LOGGER_DEBUG(bwc->m->log, "recved: %u lost: %u percentage: %f %%", recv, lost, ((double)lost / (recv + lost)) * 100.0); bwc->mcb(bwc, bwc->friend_number, diff --git a/toxav/toxav.c b/toxav/toxav.c index 0edbb9cc038..4d6a4f40ebd 100644 --- a/toxav/toxav.c +++ b/toxav/toxav.c @@ -369,8 +369,8 @@ bool toxav_call(ToxAV *av, uint32_t friend_number, uint32_t audio_bit_rate, uint pthread_mutex_lock(av->mutex); - if ((audio_bit_rate && audio_bit_rate_invalid(audio_bit_rate)) - || (video_bit_rate && video_bit_rate_invalid(video_bit_rate))) { + if ((audio_bit_rate != 0 && audio_bit_rate_invalid(audio_bit_rate)) + || (video_bit_rate != 0 && video_bit_rate_invalid(video_bit_rate))) { rc = TOXAV_ERR_CALL_INVALID_BIT_RATE; goto RETURN; } @@ -426,8 +426,8 @@ bool toxav_answer(ToxAV *av, uint32_t friend_number, uint32_t audio_bit_rate, ui goto RETURN; } - if ((audio_bit_rate && audio_bit_rate_invalid(audio_bit_rate)) - || (video_bit_rate && video_bit_rate_invalid(video_bit_rate)) + if ((audio_bit_rate != 0 && audio_bit_rate_invalid(audio_bit_rate)) + || (video_bit_rate != 0 && video_bit_rate_invalid(video_bit_rate)) ) { rc = TOXAV_ERR_ANSWER_INVALID_BIT_RATE; goto RETURN; @@ -1071,7 +1071,7 @@ static void callback_bwc(BWController *bwc, uint32_t friend_number, float loss, pthread_mutex_lock(call->av->mutex); - if (call->video_bit_rate) { + if (call->video_bit_rate != 0) { if (call->av->vbcb == nullptr) { pthread_mutex_unlock(call->av->mutex); LOGGER_WARNING(call->av->m->log, "No callback to report loss on"); @@ -1081,7 +1081,7 @@ static void callback_bwc(BWController *bwc, uint32_t friend_number, float loss, call->av->vbcb(call->av, friend_number, call->video_bit_rate - (call->video_bit_rate * loss), call->av->vbcb_user_data); - } else if (call->audio_bit_rate) { + } else if (call->audio_bit_rate != 0) { if (call->av->abcb == nullptr) { pthread_mutex_unlock(call->av->mutex); LOGGER_WARNING(call->av->m->log, "No callback to report loss on"); diff --git a/toxcore/DHT.c b/toxcore/DHT.c index 0bda38d72d6..f1987999ecc 100644 --- a/toxcore/DHT.c +++ b/toxcore/DHT.c @@ -1382,7 +1382,7 @@ static int sendnodes_ipv6(const DHT *dht, const IP_Port *ip_port, const uint8_t int nodes_length = 0; - if (num_nodes) { + if (num_nodes != 0) { nodes_length = pack_nodes(plain + 1, node_format_size * MAX_SENT_NODES, nodes_list, num_nodes); if (nodes_length <= 0) { @@ -2560,7 +2560,7 @@ void do_dht(DHT *dht) dht->cur_time = cur_time; // Load friends/clients if first call to do_dht - if (dht->loaded_num_nodes) { + if (dht->loaded_num_nodes != 0) { dht_connect_after_load(dht); } diff --git a/toxcore/DHT.h b/toxcore/DHT.h index 102441dcf61..c8159e89989 100644 --- a/toxcore/DHT.h +++ b/toxcore/DHT.h @@ -253,7 +253,7 @@ bool dht_getnodes(DHT *dht, const IP_Port *ip_port, const uint8_t *public_key, c typedef void dht_ip_cb(void *object, int32_t number, const IP_Port *ip_port); -typedef void dht_get_nodes_response_cb(const DHT *dht, const Node_format *node, void *userdata); +typedef void dht_get_nodes_response_cb(const DHT *dht, const Node_format *node, void *user_data); /** Sets the callback to be triggered on a getnodes response. */ non_null(1) nullable(2) diff --git a/toxcore/TCP_connection.c b/toxcore/TCP_connection.c index e4ce872df75..e0db105941b 100644 --- a/toxcore/TCP_connection.c +++ b/toxcore/TCP_connection.c @@ -312,7 +312,7 @@ int send_packet_tcp_connection(const TCP_Connections *tcp_c, int connections_num uint8_t status = con_to->connections[i].status; uint8_t connection_id = con_to->connections[i].connection_id; - if (tcp_con_num && status == TCP_CONNECTIONS_STATUS_ONLINE) { + if (tcp_con_num != 0 && status == TCP_CONNECTIONS_STATUS_ONLINE) { tcp_con_num -= 1; TCP_con *tcp_con = get_tcp_connection(tcp_c, tcp_con_num); @@ -344,7 +344,7 @@ int send_packet_tcp_connection(const TCP_Connections *tcp_c, int connections_num uint32_t tcp_con_num = con_to->connections[i].tcp_connection; uint8_t status = con_to->connections[i].status; - if (tcp_con_num && status == TCP_CONNECTIONS_STATUS_REGISTERED) { + if (tcp_con_num != 0 && status == TCP_CONNECTIONS_STATUS_REGISTERED) { tcp_con_num -= 1; TCP_con *tcp_con = get_tcp_connection(tcp_c, tcp_con_num); @@ -575,7 +575,7 @@ int kill_tcp_connection_to(TCP_Connections *tcp_c, int connections_number) } for (unsigned int i = 0; i < MAX_FRIEND_TCP_CONNECTIONS; ++i) { - if (con_to->connections[i].tcp_connection) { + if (con_to->connections[i].tcp_connection != 0) { unsigned int tcp_connections_number = con_to->connections[i].tcp_connection - 1; TCP_con *tcp_con = get_tcp_connection(tcp_c, tcp_connections_number); @@ -625,7 +625,7 @@ int set_tcp_connection_to_status(const TCP_Connections *tcp_c, int connections_n } for (unsigned int i = 0; i < MAX_FRIEND_TCP_CONNECTIONS; ++i) { - if (con_to->connections[i].tcp_connection) { + if (con_to->connections[i].tcp_connection != 0) { unsigned int tcp_connections_number = con_to->connections[i].tcp_connection - 1; TCP_con *tcp_con = get_tcp_connection(tcp_c, tcp_connections_number); @@ -649,7 +649,7 @@ int set_tcp_connection_to_status(const TCP_Connections *tcp_c, int connections_n } for (unsigned int i = 0; i < MAX_FRIEND_TCP_CONNECTIONS; ++i) { - if (con_to->connections[i].tcp_connection) { + if (con_to->connections[i].tcp_connection != 0) { unsigned int tcp_connections_number = con_to->connections[i].tcp_connection - 1; TCP_con *tcp_con = get_tcp_connection(tcp_c, tcp_connections_number); @@ -728,7 +728,7 @@ static uint32_t online_tcp_connection_from_conn(const TCP_Connection_to *con_to) uint32_t count = 0; for (uint32_t i = 0; i < MAX_FRIEND_TCP_CONNECTIONS; ++i) { - if (con_to->connections[i].tcp_connection) { + if (con_to->connections[i].tcp_connection != 0) { if (con_to->connections[i].status == TCP_CONNECTIONS_STATUS_ONLINE) { ++count; } @@ -1512,7 +1512,7 @@ static void do_tcp_conns(const Logger *logger, TCP_Connections *tcp_c, void *use } if (tcp_con->status == TCP_CONN_CONNECTED - && !tcp_con->onion && tcp_con->lock_count + && !tcp_con->onion && tcp_con->lock_count != 0 && tcp_con->lock_count == tcp_con->sleep_count && mono_time_is_timeout(tcp_c->mono_time, tcp_con->connected_time, TCP_CONNECTION_ANNOUNCE_TIMEOUT)) { sleep_tcp_relay_connection(tcp_c, i); @@ -1549,7 +1549,7 @@ static void kill_nonused_tcp(TCP_Connections *tcp_c) } if (tcp_con->status == TCP_CONN_CONNECTED) { - if (tcp_con->onion || tcp_con->lock_count) { // connection is in use so we skip it + if (tcp_con->onion || tcp_con->lock_count != 0) { // connection is in use so we skip it continue; } diff --git a/toxcore/group.c b/toxcore/group.c index 2a63851ee7f..a1c6e79bd84 100644 --- a/toxcore/group.c +++ b/toxcore/group.c @@ -2520,7 +2520,7 @@ static int send_message_group(const Group_Chats *g_c, uint32_t groupnumber, uint ++g->message_number; - if (!g->message_number) { + if (g->message_number == 0) { ++g->message_number; } diff --git a/toxcore/list.c b/toxcore/list.c index d4f88bfbdda..4f80f35a049 100644 --- a/toxcore/list.c +++ b/toxcore/list.c @@ -51,7 +51,7 @@ static int find(const BS_List *list, const uint8_t *data) uint32_t i = list->n / 2; // current position in the array uint32_t delta = i / 2; // how much we move in the array - if (!delta) { + if (delta == 0) { delta = 1; }