Skip to content

Commit

Permalink
cleanup: Return boolean constants, not ints from bool functions.
Browse files Browse the repository at this point in the history
  • Loading branch information
iphydf committed Feb 22, 2022
1 parent b7f95bb commit b0c93ae
Show file tree
Hide file tree
Showing 7 changed files with 98 additions and 95 deletions.
2 changes: 1 addition & 1 deletion toxcore/DHT.c
Original file line number Diff line number Diff line change
Expand Up @@ -1113,7 +1113,7 @@ static bool is_pk_in_client_list(const Client_data *list, unsigned int client_li
const uint32_t index = index_of_client_pk(list, client_list_length, public_key);

if (index == UINT32_MAX) {
return 0;
return false;
}

const IPPTsPng *assoc = net_family_is_ipv4(ip_port->ip.family)
Expand Down
4 changes: 2 additions & 2 deletions toxcore/TCP_connection.c
Original file line number Diff line number Diff line change
Expand Up @@ -680,11 +680,11 @@ static bool tcp_connection_in_conn(const TCP_Connection_to *con_to, unsigned int
{
for (unsigned int i = 0; i < MAX_FRIEND_TCP_CONNECTIONS; ++i) {
if (con_to->connections[i].tcp_connection == (tcp_connections_number + 1)) {
return 1;
return true;
}
}

return 0;
return false;
}

/** return index on success.
Expand Down
13 changes: 8 additions & 5 deletions toxcore/crypto_core.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
*/
#include "crypto_core.h"

#include <assert.h>
#include <stdlib.h>
#include <string.h>

Expand All @@ -34,7 +35,6 @@

//!TOKSTYLE-
#ifdef FUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION
#include <assert.h>
#include "../testing/fuzzing/fuzz_adapter.h"
#endif
//!TOKSTYLE+
Expand Down Expand Up @@ -178,10 +178,10 @@ uint32_t random_range_u32(uint32_t upper_bound)
bool public_key_valid(const uint8_t *public_key)
{
if (public_key[31] >= 128) { /* Last bit of key is always zero. */
return 0;
return false;
}

return 1;
return true;
}

int32_t encrypt_precompute(const uint8_t *public_key, const uint8_t *secret_key,
Expand Down Expand Up @@ -238,7 +238,8 @@ int32_t encrypt_data_symmetric(const uint8_t *shared_key, const uint8_t *nonce,
crypto_free(temp_plain, size_temp_plain);
crypto_free(temp_encrypted, size_temp_encrypted);
#endif
return length + crypto_box_MACBYTES;
assert(length < INT32_MAX - crypto_box_MACBYTES);
return (int32_t)(length + crypto_box_MACBYTES);
}

int32_t decrypt_data_symmetric(const uint8_t *shared_key, const uint8_t *nonce,
Expand Down Expand Up @@ -287,7 +288,9 @@ int32_t decrypt_data_symmetric(const uint8_t *shared_key, const uint8_t *nonce,
crypto_free(temp_plain, size_temp_plain);
crypto_free(temp_encrypted, size_temp_encrypted);
#endif
return length - crypto_box_MACBYTES;
assert(length > crypto_box_MACBYTES);
assert(length < INT32_MAX);
return (int32_t)(length - crypto_box_MACBYTES);
}

int32_t encrypt_data(const uint8_t *public_key, const uint8_t *secret_key, const uint8_t *nonce,
Expand Down
4 changes: 2 additions & 2 deletions toxcore/group.c
Original file line number Diff line number Diff line change
Expand Up @@ -1441,7 +1441,7 @@ static bool send_packet_group_peer(const Friend_Connections *fr_c, int friendcon
uint16_t group_num, const uint8_t *data, uint16_t length)
{
if (1 + sizeof(uint16_t) + length > MAX_CRYPTO_DATA_SIZE) {
return 0;
return false;
}

group_num = net_htons(group_num);
Expand All @@ -1463,7 +1463,7 @@ static bool send_lossy_group_peer(const Friend_Connections *fr_c, int friendcon_
uint16_t group_num, const uint8_t *data, uint16_t length)
{
if (1 + sizeof(uint16_t) + length > MAX_CRYPTO_DATA_SIZE) {
return 0;
return false;
}

group_num = net_htons(group_num);
Expand Down
2 changes: 1 addition & 1 deletion toxcore/onion_client.c
Original file line number Diff line number Diff line change
Expand Up @@ -416,7 +416,7 @@ non_null()
static bool path_exists(const Mono_Time *mono_time, const Onion_Client_Paths *onion_paths, uint32_t path_num)
{
if (path_timed_out(mono_time, onion_paths, path_num)) {
return 0;
return false;
}

return onion_paths->paths[path_num % NUMBER_ONION_PATHS].path_num == path_num;
Expand Down
Loading

0 comments on commit b0c93ae

Please sign in to comment.