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 870b028
Show file tree
Hide file tree
Showing 12 changed files with 36 additions and 36 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
2 changes: 1 addition & 1 deletion toxav/msi.c
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ int msi_kill(MSISession *session, const Logger *log)

MSICall *it = get_call(session, session->calls_head);

while (it) {
while (it != nullptr) {
send_message(session->messenger, it->friend_number, &msg);
MSICall *temp_it = it;
it = it->next;
Expand Down
2 changes: 1 addition & 1 deletion toxav/rtp.c
Original file line number Diff line number Diff line change
Expand Up @@ -846,7 +846,7 @@ int rtp_send_data(RTPSession *session, const uint8_t *data, uint32_t length,
/* Send remaining */
piece = length - sent;

if (piece) {
if (piece != 0) {
rtp_header_pack(rdata + 1, &header);
memcpy(rdata + 1 + RTP_HEADER_SIZE, data + sent, piece);

Expand Down
16 changes: 8 additions & 8 deletions toxav/toxav.c
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ void toxav_kill(ToxAV *av)
if (av->calls != nullptr) {
ToxAVCall *it = call_get(av, av->calls_head);

while (it) {
while (it != nullptr) {
call_kill_transmission(it);
it->msi_call = nullptr; /* msi_kill() frees the call's msi_call handle; which causes #278 */
it = call_remove(it); /* This will eventually free av->calls */
Expand Down 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 Expand Up @@ -1263,7 +1263,7 @@ static ToxAVCall *call_new(ToxAV *av, uint32_t friend_number, Toxav_Err_Call *er
call->av = av;
call->friend_number = friend_number;

if (create_recursive_mutex(call->toxav_call_mutex)) {
if (create_recursive_mutex(call->toxav_call_mutex) != 0) {
free(call);
call = nullptr;
rc = TOXAV_ERR_CALL_MALLOC;
Expand Down
8 changes: 4 additions & 4 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 @@ -1758,7 +1758,7 @@ static uint8_t do_ping_and_sendnode_requests(DHT *dht, uint64_t *lastgetnode, co
sort_client_list(list, dht->cur_time, list_count, public_key);
}

if ((num_nodes != 0) && (mono_time_is_timeout(dht->mono_time, *lastgetnode, GET_NODE_INTERVAL)
if (num_nodes > 0 && (mono_time_is_timeout(dht->mono_time, *lastgetnode, GET_NODE_INTERVAL)
|| *bootstrap_times < MAX_BOOTSTRAP_TIMES)) {
uint32_t rand_node = random_range_u32(num_nodes);

Expand Down Expand Up @@ -1834,7 +1834,7 @@ static void do_Close(DHT *dht)
for (IPPTsPng * const *it = assocs; *it; ++it) {
IPPTsPng *const assoc = *it;

if (assoc->timestamp) {
if (assoc->timestamp != 0) {
assoc->timestamp = badonly;
}
}
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
10 changes: 5 additions & 5 deletions toxcore/TCP_client.c
Original file line number Diff line number Diff line change
Expand Up @@ -443,7 +443,7 @@ static int client_send_disconnect_notification(const Logger *logger, TCP_Client_
*/
static int tcp_send_ping_request(const Logger *logger, TCP_Client_Connection *con)
{
if (!con->ping_request_id) {
if (con->ping_request_id == 0) {
return 1;
}

Expand All @@ -465,7 +465,7 @@ static int tcp_send_ping_request(const Logger *logger, TCP_Client_Connection *co
*/
static int tcp_send_ping_response(const Logger *logger, TCP_Client_Connection *con)
{
if (!con->ping_response_id) {
if (con->ping_response_id == 0) {
return 1;
}

Expand Down Expand Up @@ -714,7 +714,7 @@ static int handle_TCP_client_packet(const Logger *logger, TCP_Client_Connection
uint64_t ping_id;
memcpy(&ping_id, data + 1, sizeof(uint64_t));

if (ping_id) {
if (ping_id != 0) {
if (ping_id == conn->ping_id) {
conn->ping_id = 0;
}
Expand Down Expand Up @@ -795,7 +795,7 @@ static int do_confirmed_TCP(const Logger *logger, TCP_Client_Connection *conn, c
if (mono_time_is_timeout(mono_time, conn->last_pinged, TCP_PING_FREQUENCY)) {
uint64_t ping_id = random_u64();

if (!ping_id) {
if (ping_id == 0) {
++ping_id;
}

Expand All @@ -805,7 +805,7 @@ static int do_confirmed_TCP(const Logger *logger, TCP_Client_Connection *conn, c
conn->last_pinged = mono_time_get(mono_time);
}

if (conn->ping_id && mono_time_is_timeout(mono_time, conn->last_pinged, TCP_PING_TIMEOUT)) {
if (conn->ping_id != 0 && mono_time_is_timeout(mono_time, conn->last_pinged, TCP_PING_TIMEOUT)) {
conn->status = TCP_CLIENT_DISCONNECTED;
return 0;
}
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
6 changes: 3 additions & 3 deletions toxcore/TCP_server.c
Original file line number Diff line number Diff line change
Expand Up @@ -648,7 +648,7 @@ static int handle_TCP_packet(TCP_Server *tcp_server, uint32_t con_id, const uint
uint64_t ping_id;
memcpy(&ping_id, data + 1, sizeof(uint64_t));

if (ping_id) {
if (ping_id != 0) {
if (ping_id == con->ping_id) {
con->ping_id = 0;
}
Expand Down Expand Up @@ -1075,7 +1075,7 @@ static void do_TCP_confirmed(TCP_Server *tcp_server, const Mono_Time *mono_time)
ping[0] = TCP_PACKET_PING;
uint64_t ping_id = random_u64();

if (!ping_id) {
if (ping_id == 0) {
++ping_id;
}

Expand All @@ -1093,7 +1093,7 @@ static void do_TCP_confirmed(TCP_Server *tcp_server, const Mono_Time *mono_time)
}
}

if (conn->ping_id && mono_time_is_timeout(mono_time, conn->last_pinged, TCP_PING_TIMEOUT)) {
if (conn->ping_id != 0 && mono_time_is_timeout(mono_time, conn->last_pinged, TCP_PING_TIMEOUT)) {
kill_accepted(tcp_server, i);
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
2 changes: 1 addition & 1 deletion toxcore/net_crypto.c
Original file line number Diff line number Diff line change
Expand Up @@ -1342,7 +1342,7 @@ static int send_requested_packets(Net_Crypto *c, int crypt_connection_id, uint32
continue;
}

if (dt->sent_time) {
if (dt->sent_time != 0) {
continue;
}

Expand Down

0 comments on commit 870b028

Please sign in to comment.