From cc045d6343258d27a5e00b06fa7570b733e8cc5e Mon Sep 17 00:00:00 2001 From: iphydf Date: Fri, 18 Feb 2022 03:18:17 +0000 Subject: [PATCH] cleanup: Avoid implicit boolean and floating point conversions in decls. Also avoid implicit enum-to-int. --- .../docker/tox-bootstrapd.sha256 | 2 +- toxcore/TCP_server.c | 2 +- toxcore/net_crypto.c | 2 +- toxcore/network.c | 2 +- toxcore/onion_announce.c | 4 ++-- toxcore/onion_client.c | 4 ++-- toxcore/tox.c | 19 +++++++++++-------- 7 files changed, 19 insertions(+), 16 deletions(-) diff --git a/other/bootstrap_daemon/docker/tox-bootstrapd.sha256 b/other/bootstrap_daemon/docker/tox-bootstrapd.sha256 index 5c634617..013609f7 100644 --- a/other/bootstrap_daemon/docker/tox-bootstrapd.sha256 +++ b/other/bootstrap_daemon/docker/tox-bootstrapd.sha256 @@ -1 +1 @@ -e73d3dce83fd0dd2bc5f5517692e84fb64b856201e22fcbfc59dc84fc22e3ee6 /usr/local/bin/tox-bootstrapd +06d4c48fbc0727ccfb6a48ff6784558f8e9c377f9d29786fbf206810e9b76788 /usr/local/bin/tox-bootstrapd diff --git a/toxcore/TCP_server.c b/toxcore/TCP_server.c index 2dc26535..f5bfb489 100644 --- a/toxcore/TCP_server.c +++ b/toxcore/TCP_server.c @@ -807,7 +807,7 @@ static Socket new_listening_TCP_socket(const Logger *logger, Family family, uint return net_invalid_socket; } - int ok = set_socket_nonblock(sock); + bool ok = set_socket_nonblock(sock); if (ok && net_family_is_ipv6(family)) { ok = set_socket_dualstack(sock); diff --git a/toxcore/net_crypto.c b/toxcore/net_crypto.c index 6bf8a462..9894df96 100644 --- a/toxcore/net_crypto.c +++ b/toxcore/net_crypto.c @@ -2645,7 +2645,7 @@ static void send_crypto_packets(Net_Crypto *c) } if ((PACKET_COUNTER_AVERAGE_INTERVAL + conn->packet_counter_set) < temp_time) { - const double dt = temp_time - conn->packet_counter_set; + const double dt = (double)(temp_time - conn->packet_counter_set); conn->packet_recv_rate = (double)conn->packet_counter / (dt / 1000.0); conn->packet_counter = 0; diff --git a/toxcore/network.c b/toxcore/network.c index d800c079..15ff2820 100644 --- a/toxcore/network.c +++ b/toxcore/network.c @@ -961,7 +961,7 @@ Networking_Core *new_networking_ex(const Logger *log, const IP *ip, uint16_t por #ifndef FUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION if (net_family_is_ipv6(ip->family)) { - const int is_dualstack = set_socket_dualstack(temp->sock); + const bool is_dualstack = set_socket_dualstack(temp->sock); LOGGER_DEBUG(log, "Dual-stack socket: %s", is_dualstack ? "enabled" : "Failed to enable, won't be able to receive from/send to IPv4 addresses"); /* multicast local nodes */ diff --git a/toxcore/onion_announce.c b/toxcore/onion_announce.c index 0f519d78..c663a638 100644 --- a/toxcore/onion_announce.c +++ b/toxcore/onion_announce.c @@ -276,8 +276,8 @@ static int cmp_entry(const void *a, const void *b) const Onion_Announce_Entry entry2 = cmp2->entry; const uint8_t *cmp_public_key = cmp1->base_public_key; - const int t1 = mono_time_is_timeout(cmp1->mono_time, entry1.time, ONION_ANNOUNCE_TIMEOUT); - const int t2 = mono_time_is_timeout(cmp1->mono_time, entry2.time, ONION_ANNOUNCE_TIMEOUT); + const bool t1 = mono_time_is_timeout(cmp1->mono_time, entry1.time, ONION_ANNOUNCE_TIMEOUT); + const bool t2 = mono_time_is_timeout(cmp1->mono_time, entry2.time, ONION_ANNOUNCE_TIMEOUT); if (t1 && t2) { return 0; diff --git a/toxcore/onion_client.c b/toxcore/onion_client.c index 17bf576a..1c5e16b1 100644 --- a/toxcore/onion_client.c +++ b/toxcore/onion_client.c @@ -626,8 +626,8 @@ static int onion_client_cmp_entry(const void *a, const void *b) const Onion_Node entry2 = cmp2->entry; const uint8_t *cmp_public_key = cmp1->base_public_key; - const int t1 = onion_node_timed_out(&entry1, cmp1->mono_time); - const int t2 = onion_node_timed_out(&entry2, cmp2->mono_time); + const bool t1 = onion_node_timed_out(&entry1, cmp1->mono_time); + const bool t2 = onion_node_timed_out(&entry2, cmp2->mono_time); if (t1 && t2) { return 0; diff --git a/toxcore/tox.c b/toxcore/tox.c index 60e953ce..735ed99d 100644 --- a/toxcore/tox.c +++ b/toxcore/tox.c @@ -828,18 +828,21 @@ Tox_Connection tox_self_get_connection_status(const Tox *tox) { assert(tox != nullptr); lock(tox); - const unsigned int ret = onion_connection_status(tox->m->onion_c); + const Onion_Connection_Status ret = onion_connection_status(tox->m->onion_c); unlock(tox); - if (ret == 2) { - return TOX_CONNECTION_UDP; + switch (ret) { + case ONION_CONNECTION_STATUS_NONE: + return TOX_CONNECTION_NONE; + + case ONION_CONNECTION_STATUS_TCP: + return TOX_CONNECTION_TCP; + + case ONION_CONNECTION_STATUS_UDP: + return TOX_CONNECTION_UDP; } - if (ret == 1) { - return TOX_CONNECTION_TCP; - } - - return TOX_CONNECTION_NONE; + LOGGER_FATAL(tox->m->log, "impossible return value: %d", ret); }