Skip to content

Commit

Permalink
cleanup: Remove implicit conversions from uint32_t to bool.
Browse files Browse the repository at this point in the history
  • Loading branch information
iphydf committed Feb 22, 2022
1 parent 6be655c commit fde015b
Show file tree
Hide file tree
Showing 7 changed files with 21 additions and 21 deletions.
4 changes: 2 additions & 2 deletions toxav/bwcontroller.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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,
Expand Down
12 changes: 6 additions & 6 deletions toxav/toxav.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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");
Expand All @@ -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");
Expand Down
4 changes: 2 additions & 2 deletions toxcore/DHT.c
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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);
}

Expand Down
2 changes: 1 addition & 1 deletion toxcore/DHT.h
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
16 changes: 8 additions & 8 deletions toxcore/TCP_connection.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down Expand Up @@ -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);

Expand Down Expand Up @@ -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);

Expand Down Expand Up @@ -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);

Expand All @@ -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);

Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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;
}

Expand Down
2 changes: 1 addition & 1 deletion toxcore/group.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
2 changes: 1 addition & 1 deletion toxcore/list.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down

0 comments on commit fde015b

Please sign in to comment.