From 608c8817acf8418cd96e51fcb2b5e272b2c43dcc Mon Sep 17 00:00:00 2001 From: iphydf Date: Thu, 31 Aug 2023 11:32:51 +0000 Subject: [PATCH] cleanup: Initialise all local variables. It's unnecessary in any of these cases, but having the warning is useful, and may catch errors in the future. --- .clang-tidy | 3 + auto_tests/auto_test_support.c | 8 +-- auto_tests/conference_av_test.c | 14 +++-- auto_tests/conference_double_invite_test.c | 6 +- auto_tests/conference_invite_merge_test.c | 6 +- auto_tests/conference_peer_nick_test.c | 10 ++-- auto_tests/conference_simple_test.c | 12 ++-- auto_tests/conference_test.c | 12 ++-- auto_tests/conference_two_test.c | 2 +- auto_tests/crypto_test.c | 12 ++-- auto_tests/encryptsave_test.c | 16 ++--- auto_tests/file_saving_test.c | 6 +- auto_tests/file_transfer_test.c | 12 ++-- auto_tests/forwarding_test.c | 2 +- auto_tests/friend_request_spam_test.c | 2 +- auto_tests/group_general_test.c | 32 +++++----- auto_tests/group_invite_test.c | 14 ++--- auto_tests/group_message_test.c | 40 ++++++------- auto_tests/group_moderation_test.c | 28 ++++----- auto_tests/group_save_test.c | 30 +++++----- auto_tests/group_state_test.c | 30 +++++----- auto_tests/group_sync_test.c | 16 ++--- auto_tests/group_tcp_test.c | 16 ++--- auto_tests/group_topic_test.c | 22 +++---- auto_tests/lan_discovery_test.c | 2 +- auto_tests/network_test.c | 2 +- auto_tests/onion_test.c | 4 +- auto_tests/overflow_recvq_test.c | 2 +- auto_tests/overflow_sendq_test.c | 2 +- auto_tests/proxy_test.c | 2 +- auto_tests/save_compatibility_test.c | 2 +- auto_tests/save_friend_test.c | 2 +- auto_tests/save_load_test.c | 2 +- auto_tests/send_message_test.c | 2 +- auto_tests/set_name_test.c | 2 +- auto_tests/set_status_message_test.c | 2 +- auto_tests/tox_dispatch_test.c | 4 +- auto_tests/tox_events_test.c | 4 +- auto_tests/tox_many_tcp_test.c | 10 ++-- auto_tests/tox_many_test.c | 2 +- auto_tests/toxav_basic_test.c | 42 ++++++------- auto_tests/toxav_many_test.c | 16 ++--- auto_tests/typing_test.c | 2 +- other/DHT_bootstrap.c | 2 +- other/analysis/run-clang-tidy | 24 ++++---- .../docker/tox-bootstrapd.sha256 | 2 +- .../src/command_line_arguments.c | 2 +- other/bootstrap_daemon/src/config.c | 20 +++---- other/bootstrap_daemon/src/tox-bootstrapd.c | 52 +++++++--------- other/fun/cracker.c | 10 ++-- other/fun/create_savedata.c | 6 +- other/fun/save-generator.c | 6 +- other/fun/sign.c | 6 +- other/fun/strkey.c | 6 +- super_donators/grencez_tok5.c | 2 +- toxav/audio.c | 4 +- toxav/bwcontroller.c | 2 +- toxav/groupav.c | 4 +- toxav/ring_buffer.c | 2 +- toxav/rtp.c | 2 +- toxav/toxav.c | 14 ++--- toxav/video.c | 8 +-- toxcore/DHT.c | 44 +++++++------- toxcore/Messenger.c | 40 ++++++------- toxcore/TCP_client.c | 4 +- toxcore/TCP_common.c | 2 +- toxcore/TCP_connection.c | 4 +- toxcore/TCP_server.c | 8 +-- toxcore/announce.c | 2 +- toxcore/bin_unpack.c | 6 +- toxcore/crypto_core.c | 8 +-- toxcore/friend_connection.c | 2 +- toxcore/group.c | 34 +++++------ toxcore/group_announce.c | 2 +- toxcore/group_chats.c | 60 +++++++++---------- toxcore/net_crypto.c | 26 ++++---- toxcore/network.c | 14 ++--- toxcore/onion_announce.c | 2 +- toxcore/onion_client.c | 36 +++++------ toxcore/ping.c | 14 ++--- toxcore/state.c | 10 ++-- toxcore/tox.c | 10 ++-- toxcore/tox_events.c | 6 +- toxcore/tox_private.c | 2 +- toxcore/tox_unpack.c | 10 ++-- toxcore/util.c | 2 +- toxencryptsave/toxencryptsave.c | 2 +- 87 files changed, 493 insertions(+), 488 deletions(-) diff --git a/.clang-tidy b/.clang-tidy index f808e71f13a..2a396a2cfe3 100644 --- a/.clang-tidy +++ b/.clang-tidy @@ -33,3 +33,6 @@ CheckOptions: value: Camel_Snake_Case - key: readability-identifier-naming.VariableCase value: lower_case + + - key: llvmlibc-restrict-system-libc-headers.Includes + value: "arpa/inet.h,assert.h,ctype.h,errno.h,fcntl.h,getopt.h,libconfig.h,linux/netdevice.h,math.h,netdb.h,netinet/in.h,opus.h,pthread.h,signal.h,sodium/crypto_scalarmult_curve25519.h,sodium.h,sodium/randombytes.h,stdio.h,stdlib.h,string.h,sys/ioctl.h,syslog.h,sys/resource.h,sys/socket.h,sys/stat.h,sys/time.h,sys/types.h,time.h,unistd.h,vpx/vp8cx.h,vpx/vp8dx.h,vpx/vpx_decoder.h,vpx/vpx_encoder.h,vpx/vpx_image.h" diff --git a/auto_tests/auto_test_support.c b/auto_tests/auto_test_support.c index 320acc4bc70..acd0c709f50 100644 --- a/auto_tests/auto_test_support.c +++ b/auto_tests/auto_test_support.c @@ -85,7 +85,7 @@ void bootstrap_tox_live_network(Tox *tox, bool enable_tcp) uint16_t port = bootstrap_nodes[j].port; const uint8_t *key = bootstrap_nodes[j].key; - Tox_Err_Bootstrap err; + Tox_Err_Bootstrap err = TOX_ERR_BOOTSTRAP_OK; tox_bootstrap(tox, ip, port, key, &err); if (err != TOX_ERR_BOOTSTRAP_OK) { @@ -287,7 +287,7 @@ static void autotox_add_friend(AutoTox *autotoxes, uint32_t adding, uint32_t add { uint8_t public_key[TOX_PUBLIC_KEY_SIZE]; tox_self_get_public_key(autotoxes[added].tox, public_key); - Tox_Err_Friend_Add err; + Tox_Err_Friend_Add err = TOX_ERR_FRIEND_ADD_OK; tox_friend_add_norequest(autotoxes[adding].tox, public_key, &err); ck_assert(err == TOX_ERR_FRIEND_ADD_OK); } @@ -330,7 +330,7 @@ static void bootstrap_autotoxes(struct Tox_Options *options, uint32_t tox_count, const uint16_t dht_port = tox_self_get_udp_port(autotoxes[0].tox, nullptr); for (uint32_t i = 1; i < tox_count; ++i) { - Tox_Err_Bootstrap err; + Tox_Err_Bootstrap err = TOX_ERR_BOOTSTRAP_OK; tox_bootstrap(autotoxes[i].tox, "localhost", dht_port, dht_key, &err); ck_assert(err == TOX_ERR_BOOTSTRAP_OK); } @@ -340,7 +340,7 @@ static void bootstrap_autotoxes(struct Tox_Options *options, uint32_t tox_count, printf("bootstrapping all toxes to local TCP relay running on port %d\n", autotest_opts->tcp_port); for (uint32_t i = 0; i < tox_count; ++i) { - Tox_Err_Bootstrap err; + Tox_Err_Bootstrap err = TOX_ERR_BOOTSTRAP_OK; tox_add_tcp_relay(autotoxes[i].tox, "localhost", autotest_opts->tcp_port, dht_key, &err); ck_assert(err == TOX_ERR_BOOTSTRAP_OK); } diff --git a/auto_tests/conference_av_test.c b/auto_tests/conference_av_test.c index 8e42f359e96..b0b35ece30b 100644 --- a/auto_tests/conference_av_test.c +++ b/auto_tests/conference_av_test.c @@ -90,7 +90,7 @@ static void handle_conference_connected( return; } - Tox_Err_Conference_Invite err; + Tox_Err_Conference_Invite err = TOX_ERR_CONFERENCE_INVITE_OK; tox_conference_invite(tox, 1, 0, &err); ck_assert_msg(err == TOX_ERR_CONFERENCE_INVITE_OK, "tox #%u failed to invite next friend: err = %d", autotox->index, err); @@ -167,7 +167,7 @@ static bool all_connected_to_group(uint32_t tox_count, AutoTox *autotoxes) */ static uint32_t random_false_index(const Random *rng, bool *list, const uint32_t length) { - uint32_t index; + uint32_t index = 0; do { index = random_u32(rng) % length; @@ -255,8 +255,12 @@ static void test_eventual_audio(AutoTox *autotoxes, const bool *disabled, uint64 uint64_t start = autotoxes[0].clock; while (autotoxes[0].clock < start + timeout) { - if (test_audio(autotoxes, disabled, true) - && test_audio(autotoxes, disabled, true)) { + if (!test_audio(autotoxes, disabled, true)) { + continue; + } + + // It needs to succeed twice in a row for the test to pass. + if (test_audio(autotoxes, disabled, true)) { printf("audio test successful after %d seconds\n", (int)((autotoxes[0].clock - start) / 1000)); return; } @@ -433,7 +437,7 @@ static void test_groupav(AutoTox *autotoxes) iterate_all_wait(autotoxes, NUM_AV_GROUP_TOX, ITERATION_INTERVAL); for (uint32_t i = 0; i < NUM_AV_GROUP_TOX; ++i) { - Tox_Err_Conference_Peer_Query err; + Tox_Err_Conference_Peer_Query err = TOX_ERR_CONFERENCE_PEER_QUERY_OK; uint32_t peer_count = tox_conference_peer_count(autotoxes[i].tox, 0, &err); if (err != TOX_ERR_CONFERENCE_PEER_QUERY_OK) { diff --git a/auto_tests/conference_double_invite_test.c b/auto_tests/conference_double_invite_test.c index 201dd8f5d71..6acfccaa237 100644 --- a/auto_tests/conference_double_invite_test.c +++ b/auto_tests/conference_double_invite_test.c @@ -25,7 +25,7 @@ static void handle_conference_invite( ck_assert_msg(!state->joined, "invitation callback generated for already joined conference"); if (friend_number != -1) { - Tox_Err_Conference_Join err; + Tox_Err_Conference_Join err = TOX_ERR_CONFERENCE_JOIN_OK; state->conference = tox_conference_join(tox, friend_number, cookie, length, &err); ck_assert_msg(err == TOX_ERR_CONFERENCE_JOIN_OK, "attempting to join the conference returned with an error: %d", err); @@ -46,7 +46,7 @@ static void conference_double_invite_test(AutoTox *autotoxes) { // Create new conference, tox0 is the founder. - Tox_Err_Conference_New err; + Tox_Err_Conference_New err = TOX_ERR_CONFERENCE_NEW_OK; state[0]->conference = tox_conference_new(autotoxes[0].tox, &err); state[0]->joined = true; ck_assert_msg(err == TOX_ERR_CONFERENCE_NEW_OK, @@ -56,7 +56,7 @@ static void conference_double_invite_test(AutoTox *autotoxes) { // Invite friend. - Tox_Err_Conference_Invite err; + Tox_Err_Conference_Invite err = TOX_ERR_CONFERENCE_INVITE_OK; tox_conference_invite(autotoxes[0].tox, 0, state[0]->conference, &err); ck_assert_msg(err == TOX_ERR_CONFERENCE_INVITE_OK, "attempting to invite a friend returned with an error: %d", err); diff --git a/auto_tests/conference_invite_merge_test.c b/auto_tests/conference_invite_merge_test.c index c02c59b4865..cad442e851e 100644 --- a/auto_tests/conference_invite_merge_test.c +++ b/auto_tests/conference_invite_merge_test.c @@ -19,7 +19,7 @@ static void handle_conference_invite( State *state = (State *)autotox->state; if (friend_number != -1) { - Tox_Err_Conference_Join err; + Tox_Err_Conference_Join err = TOX_ERR_CONFERENCE_JOIN_OK; state->conference = tox_conference_join(tox, friend_number, cookie, length, &err); ck_assert_msg(err == TOX_ERR_CONFERENCE_JOIN_OK, "attempting to join the conference returned with an error: %d", err); @@ -48,7 +48,7 @@ static void do_invite(AutoTox *autotoxes, AutoTox *inviter, AutoTox *invitee, ui { fprintf(stderr, "#%u inviting #%u\n", inviter->index, invitee->index); - Tox_Err_Conference_Invite err; + Tox_Err_Conference_Invite err = TOX_ERR_CONFERENCE_INVITE_OK; tox_conference_invite(inviter->tox, friendnum, ((State *)inviter->state)->conference, &err); ck_assert_msg(err == TOX_ERR_CONFERENCE_INVITE_OK, "#%u attempting to invite #%u (friendnumber %u) returned with an error: %d", inviter->index, invitee->index, @@ -103,7 +103,7 @@ static void conference_invite_merge_test(AutoTox *autotoxes) { // Create new conference, tox 2 is the founder. - Tox_Err_Conference_New err; + Tox_Err_Conference_New err = TOX_ERR_CONFERENCE_NEW_OK; state2->conference = tox_conference_new(autotoxes[2].tox, &err); state2->connected = true; ck_assert_msg(err == TOX_ERR_CONFERENCE_NEW_OK, diff --git a/auto_tests/conference_peer_nick_test.c b/auto_tests/conference_peer_nick_test.c index d1d12979fe4..1e70aff4eda 100644 --- a/auto_tests/conference_peer_nick_test.c +++ b/auto_tests/conference_peer_nick_test.c @@ -23,7 +23,7 @@ static void handle_conference_invite( autotox->index, friend_number, type, (unsigned)length); fprintf(stderr, "tox%u joining conference\n", autotox->index); - Tox_Err_Conference_Join err; + Tox_Err_Conference_Join err = TOX_ERR_CONFERENCE_JOIN_OK; state->conference = tox_conference_join(tox, friend_number, cookie, length, &err); ck_assert_msg(err == TOX_ERR_CONFERENCE_JOIN_OK, "attempting to join the conference returned with an error: %d", err); @@ -39,7 +39,7 @@ static void handle_peer_list_changed(Tox *tox, uint32_t conference_number, void fprintf(stderr, "handle_peer_list_changed(#%u, %u, _)\n", autotox->index, conference_number); - Tox_Err_Conference_Peer_Query err; + Tox_Err_Conference_Peer_Query err = TOX_ERR_CONFERENCE_PEER_QUERY_OK; uint32_t const count = tox_conference_peer_count(tox, conference_number, &err); ck_assert_msg(err == TOX_ERR_CONFERENCE_PEER_QUERY_OK, "failed to get conference peer count: err = %d", err); @@ -52,7 +52,7 @@ static void rebuild_peer_list(Tox *tox) for (uint32_t conference_number = 0; conference_number < tox_conference_get_chatlist_size(tox); ++conference_number) { - Tox_Err_Conference_Peer_Query err; + Tox_Err_Conference_Peer_Query err = TOX_ERR_CONFERENCE_PEER_QUERY_OK; uint32_t const count = tox_conference_peer_count(tox, conference_number, &err); ck_assert_msg(err == TOX_ERR_CONFERENCE_PEER_QUERY_OK, "failed to get conference peer count for conference %u: err = %d", conference_number, err); @@ -90,7 +90,7 @@ static void conference_peer_nick_test(AutoTox *autotoxes) { // Create new conference, tox0 is the founder. - Tox_Err_Conference_New err; + Tox_Err_Conference_New err = TOX_ERR_CONFERENCE_NEW_OK; state[0]->conference = tox_conference_new(autotoxes[0].tox, &err); state[0]->joined = true; ck_assert_msg(err == TOX_ERR_CONFERENCE_NEW_OK, @@ -100,7 +100,7 @@ static void conference_peer_nick_test(AutoTox *autotoxes) { // Invite friend. - Tox_Err_Conference_Invite err; + Tox_Err_Conference_Invite err = TOX_ERR_CONFERENCE_INVITE_OK; tox_conference_invite(autotoxes[0].tox, 0, state[0]->conference, &err); ck_assert_msg(err == TOX_ERR_CONFERENCE_INVITE_OK, "attempting to invite a friend returned with an error: %d", err); diff --git a/auto_tests/conference_simple_test.c b/auto_tests/conference_simple_test.c index 2c445d4b44b..280fb47a2eb 100644 --- a/auto_tests/conference_simple_test.c +++ b/auto_tests/conference_simple_test.c @@ -47,7 +47,7 @@ static void handle_conference_invite(Tox *tox, uint32_t friend_number, Tox_Confe fprintf(stderr, "tox%u joining conference\n", state->id); { - Tox_Err_Conference_Join err; + Tox_Err_Conference_Join err = TOX_ERR_CONFERENCE_JOIN_OK; state->conference = tox_conference_join(tox, friend_number, cookie, length, &err); ck_assert_msg(err == TOX_ERR_CONFERENCE_JOIN_OK, "failed to join a conference: err = %d", err); fprintf(stderr, "tox%u Joined conference %u\n", state->id, state->conference); @@ -74,7 +74,7 @@ static void handle_conference_peer_list_changed(Tox *tox, uint32_t conference_nu fprintf(stderr, "handle_conference_peer_list_changed(#%u, %u, _)\n", state->id, conference_number); - Tox_Err_Conference_Peer_Query err; + Tox_Err_Conference_Peer_Query err = TOX_ERR_CONFERENCE_PEER_QUERY_OK; uint32_t count = tox_conference_peer_count(tox, conference_number, &err); if (err != TOX_ERR_CONFERENCE_PEER_QUERY_OK) { @@ -92,7 +92,7 @@ static void handle_conference_connected(Tox *tox, uint32_t conference_number, vo // We're tox2, so now we invite tox3. if (state->id == 2 && !state->invited_next) { - Tox_Err_Conference_Invite err; + Tox_Err_Conference_Invite err = TOX_ERR_CONFERENCE_INVITE_OK; tox_conference_invite(tox, 1, state->conference, &err); ck_assert_msg(err == TOX_ERR_CONFERENCE_INVITE_OK, "tox2 failed to invite tox3: err = %d", err); @@ -187,7 +187,7 @@ int main(void) { // Create new conference, tox1 is the founder. - Tox_Err_Conference_New err; + Tox_Err_Conference_New err = TOX_ERR_CONFERENCE_NEW_OK; state1.conference = tox_conference_new(tox1, &err); state1.joined = true; ck_assert_msg(err == TOX_ERR_CONFERENCE_NEW_OK, "failed to create a conference: err = %d", err); @@ -196,7 +196,7 @@ int main(void) { // Invite friend. - Tox_Err_Conference_Invite err; + Tox_Err_Conference_Invite err = TOX_ERR_CONFERENCE_INVITE_OK; tox_conference_invite(tox1, 0, state1.conference, &err); ck_assert_msg(err == TOX_ERR_CONFERENCE_INVITE_OK, "failed to invite a friend: err = %d", err); state1.invited_next = true; @@ -229,7 +229,7 @@ int main(void) { fprintf(stderr, "tox1 sends a message to the group: \"hello!\"\n"); - Tox_Err_Conference_Send_Message err; + Tox_Err_Conference_Send_Message err = TOX_ERR_CONFERENCE_SEND_MESSAGE_OK; tox_conference_send_message(tox1, state1.conference, TOX_MESSAGE_TYPE_NORMAL, (const uint8_t *)"hello!", 7, &err); diff --git a/auto_tests/conference_test.c b/auto_tests/conference_test.c index 66edddd85c7..885b0fd595e 100644 --- a/auto_tests/conference_test.c +++ b/auto_tests/conference_test.c @@ -55,7 +55,7 @@ static void handle_conference_invite( const AutoTox *autotox = (AutoTox *)user_data; ck_assert_msg(type == TOX_CONFERENCE_TYPE_TEXT, "tox #%u: wrong conference type: %d", autotox->index, type); - Tox_Err_Conference_Join err; + Tox_Err_Conference_Join err = TOX_ERR_CONFERENCE_JOIN_OK; uint32_t g_num = tox_conference_join(tox, friendnumber, data, length, &err); ck_assert_msg(err == TOX_ERR_CONFERENCE_JOIN_OK, "tox #%u: error joining group: %d", autotox->index, err); @@ -77,7 +77,7 @@ static void handle_conference_connected( return; } - Tox_Err_Conference_Invite err; + Tox_Err_Conference_Invite err = TOX_ERR_CONFERENCE_INVITE_OK; tox_conference_invite(tox, 1, 0, &err); ck_assert_msg(err == TOX_ERR_CONFERENCE_INVITE_OK, "tox #%u failed to invite next friend: err = %d", autotox->index, err); @@ -181,7 +181,7 @@ static bool names_propagated(uint32_t tox_count, AutoTox *autotoxes) */ static uint32_t random_false_index(const Random *rng, bool *list, const uint32_t length) { - uint32_t index; + uint32_t index = 0; do { index = random_u32(rng) % length; @@ -204,7 +204,7 @@ static void run_conference_tests(AutoTox *autotoxes) printf("restricting number of frozen peers to %u\n", max_frozen); for (uint16_t i = 0; i < NUM_GROUP_TOX; ++i) { - Tox_Err_Conference_Set_Max_Offline err; + Tox_Err_Conference_Set_Max_Offline err = TOX_ERR_CONFERENCE_SET_MAX_OFFLINE_OK; tox_conference_set_max_offline(autotoxes[i].tox, 0, max_frozen, &err); ck_assert_msg(err == TOX_ERR_CONFERENCE_SET_MAX_OFFLINE_OK, "tox #%u failed to set max offline: err = %d", autotoxes[i].index, err); @@ -291,7 +291,7 @@ static void run_conference_tests(AutoTox *autotoxes) iterate_all_wait(autotoxes, NUM_GROUP_TOX, ITERATION_INTERVAL); } - Tox_Err_Conference_Send_Message err; + Tox_Err_Conference_Send_Message err = TOX_ERR_CONFERENCE_SEND_MESSAGE_OK; ck_assert_msg( tox_conference_send_message( autotoxes[random_u32(rng) % NUM_GROUP_TOX].tox, 0, TOX_MESSAGE_TYPE_NORMAL, (const uint8_t *)GROUP_MESSAGE, @@ -382,7 +382,7 @@ static void test_many_group(AutoTox *autotoxes) iterate_all_wait(autotoxes, NUM_GROUP_TOX, ITERATION_INTERVAL); for (uint32_t i = 0; i < NUM_GROUP_TOX; ++i) { - Tox_Err_Conference_Peer_Query err; + Tox_Err_Conference_Peer_Query err = TOX_ERR_CONFERENCE_PEER_QUERY_OK; uint32_t peer_count = tox_conference_peer_count(autotoxes[i].tox, 0, &err); if (err != TOX_ERR_CONFERENCE_PEER_QUERY_OK) { diff --git a/auto_tests/conference_two_test.c b/auto_tests/conference_two_test.c index 3a8b102cee8..c5e2006784e 100644 --- a/auto_tests/conference_two_test.c +++ b/auto_tests/conference_two_test.c @@ -15,7 +15,7 @@ int main(void) Tox *tox1 = tox_new_log(nullptr, nullptr, &id); // Create two conferences and then exit. - Tox_Err_Conference_New err; + Tox_Err_Conference_New err = TOX_ERR_CONFERENCE_NEW_OK; tox_conference_new(tox1, &err); ck_assert_msg(err == TOX_ERR_CONFERENCE_NEW_OK, "failed to create conference 1: %d", err); tox_conference_new(tox1, &err); diff --git a/auto_tests/crypto_test.c b/auto_tests/crypto_test.c index f4fdf3e22de..c9401f24c09 100644 --- a/auto_tests/crypto_test.c +++ b/auto_tests/crypto_test.c @@ -9,7 +9,7 @@ static void rand_bytes(const Random *rng, uint8_t *b, size_t blen) { - size_t i; + size_t i = 0; for (i = 0; i < blen; i++) { b[i] = random_u08(rng); @@ -84,7 +84,7 @@ static void test_known(void) { uint8_t c[147]; uint8_t m[131]; - uint16_t clen, mlen; + uint16_t clen = 0, mlen = 0; ck_assert_msg(sizeof(c) == sizeof(m) + CRYPTO_MAC_SIZE * sizeof(uint8_t), "cyphertext should be CRYPTO_MAC_SIZE bytes longer than plaintext"); @@ -107,7 +107,7 @@ static void test_fast_known(void) uint8_t k[CRYPTO_SHARED_KEY_SIZE]; uint8_t c[147]; uint8_t m[131]; - uint16_t clen, mlen; + uint16_t clen = 0, mlen = 0; encrypt_precompute(bobpk, alicesk, k); @@ -275,7 +275,7 @@ static void test_large_data_symmetric(void) static void increment_nonce_number_cmp(uint8_t *nonce, uint32_t num) { - uint32_t num1, num2; + uint32_t num1 = 0, num2 = 0; memcpy(&num1, nonce + (CRYPTO_NONCE_SIZE - sizeof(num1)), sizeof(num1)); num1 = net_ntohl(num1); num2 = num + num1; @@ -299,7 +299,7 @@ static void test_increment_nonce(void) const Random *rng = system_random(); ck_assert(rng != nullptr); - uint32_t i; + uint32_t i = 0; uint8_t n[CRYPTO_NONCE_SIZE]; @@ -331,7 +331,7 @@ static void test_memzero(void) memcpy(src, test_c, sizeof(test_c)); crypto_memzero(src, sizeof(src)); - size_t i; + size_t i = 0; for (i = 0; i < sizeof(src); i++) { ck_assert_msg(src[i] == 0, "Memory is not zeroed"); diff --git a/auto_tests/encryptsave_test.c b/auto_tests/encryptsave_test.c index fb49c4e2af2..8b05be5d3de 100644 --- a/auto_tests/encryptsave_test.c +++ b/auto_tests/encryptsave_test.c @@ -66,7 +66,7 @@ static void test_save_friend(void) size_t size2 = size + TOX_PASS_ENCRYPTION_EXTRA_LENGTH; uint8_t *enc_data = (uint8_t *)malloc(size2); ck_assert(enc_data != nullptr); - Tox_Err_Encryption error1; + Tox_Err_Encryption error1 = TOX_ERR_ENCRYPTION_OK; bool ret = tox_pass_encrypt(data, size, (const uint8_t *)"correcthorsebatterystaple", 25, enc_data, &error1); ck_assert_msg(ret, "failed to encrypted save: %d", error1); ck_assert_msg(tox_is_data_encrypted(enc_data), "magic number missing"); @@ -76,14 +76,14 @@ static void test_save_friend(void) tox_options_set_savedata_type(options, TOX_SAVEDATA_TYPE_TOX_SAVE); tox_options_set_savedata_data(options, enc_data, size2); - Tox_Err_New err2; + Tox_Err_New err2 = TOX_ERR_NEW_OK; Tox *tox3 = tox_new_log(options, &err2, nullptr); ck_assert_msg(err2 == TOX_ERR_NEW_LOAD_ENCRYPTED, "wrong error! %d. should fail with %d", err2, TOX_ERR_NEW_LOAD_ENCRYPTED); ck_assert_msg(tox3 == nullptr, "tox_new with error should return NULL"); uint8_t *dec_data = (uint8_t *)malloc(size); ck_assert(dec_data != nullptr); - Tox_Err_Decryption err3; + Tox_Err_Decryption err3 = TOX_ERR_DECRYPTION_OK; ret = tox_pass_decrypt(enc_data, size2, (const uint8_t *)"correcthorsebatterystaple", 25, dec_data, &err3); ck_assert_msg(ret, "failed to decrypt save: %d", err3); tox_options_set_savedata_data(options, dec_data, size); @@ -98,7 +98,7 @@ static void test_save_friend(void) uint8_t *data2 = (uint8_t *)malloc(size); ck_assert(data2 != nullptr); tox_get_savedata(tox3, data2); - Tox_Err_Key_Derivation keyerr; + Tox_Err_Key_Derivation keyerr = TOX_ERR_KEY_DERIVATION_OK; Tox_Pass_Key *key = tox_pass_key_derive((const uint8_t *)"123qweasdzxc", 12, &keyerr); ck_assert_msg(key != nullptr, "pass key allocation failure"); memcpy((uint8_t *)key, test_salt, TOX_PASS_SALT_LENGTH); @@ -149,9 +149,9 @@ static void test_save_friend(void) static void test_keys(void) { - Tox_Err_Encryption encerr; - Tox_Err_Decryption decerr; - Tox_Err_Key_Derivation keyerr; + Tox_Err_Encryption encerr = TOX_ERR_ENCRYPTION_OK; + Tox_Err_Decryption decerr = TOX_ERR_DECRYPTION_OK; + Tox_Err_Key_Derivation keyerr = TOX_ERR_KEY_DERIVATION_OK; const uint8_t *key_char = (const uint8_t *)"123qweasdzxc"; Tox_Pass_Key *key = tox_pass_key_derive(key_char, 12, &keyerr); ck_assert_msg(key != nullptr, "generic failure 1: %d", keyerr); @@ -213,7 +213,7 @@ static void test_keys(void) ck_assert_msg(memcmp(out1, string, 44) == 0, "decryption 3 failed"); uint8_t salt[TOX_PASS_SALT_LENGTH]; - Tox_Err_Get_Salt salt_err; + Tox_Err_Get_Salt salt_err = TOX_ERR_GET_SALT_OK; ck_assert_msg(tox_get_salt(encrypted, salt, &salt_err), "couldn't get salt"); ck_assert_msg(salt_err == TOX_ERR_GET_SALT_OK, "get_salt returned an error"); Tox_Pass_Key *key2 = tox_pass_key_derive_with_salt((const uint8_t *)"123qweasdzxc", 12, salt, &keyerr); diff --git a/auto_tests/file_saving_test.c b/auto_tests/file_saving_test.c index 58a1b6def4c..a898cdfca99 100644 --- a/auto_tests/file_saving_test.c +++ b/auto_tests/file_saving_test.c @@ -43,7 +43,7 @@ static void save_data_encrypted(void) size += TOX_PASS_ENCRYPTION_EXTRA_LENGTH; uint8_t *cipher = (uint8_t *)malloc(size); - Tox_Err_Encryption eerr; + Tox_Err_Encryption eerr = TOX_ERR_ENCRYPTION_OK; ck_assert_msg(tox_pass_encrypt(clear, size - TOX_PASS_ENCRYPTION_EXTRA_LENGTH, (const uint8_t *)pphrase, strlen(pphrase), cipher, @@ -75,7 +75,7 @@ static void load_data_decrypted(void) size_t read_value = fread(cipher, sizeof(*cipher), size, f); printf("Read read_value = %u of %u\n", (unsigned)read_value, (unsigned)size); - Tox_Err_Decryption derr; + Tox_Err_Decryption derr = TOX_ERR_DECRYPTION_OK; ck_assert_msg(tox_pass_decrypt(cipher, size, (const uint8_t *)pphrase, strlen(pphrase), clear, &derr), "Could not decrypt, error code %d.", derr); @@ -87,7 +87,7 @@ static void load_data_decrypted(void) tox_options_set_savedata_data(options, clear, size); - Tox_Err_New err; + Tox_Err_New err = TOX_ERR_NEW_OK; Tox *t = tox_new_log(options, &err, nullptr); diff --git a/auto_tests/file_transfer_test.c b/auto_tests/file_transfer_test.c index b65fa016990..de1ce945a40 100644 --- a/auto_tests/file_transfer_test.c +++ b/auto_tests/file_transfer_test.c @@ -57,7 +57,7 @@ static void tox_file_receive(Tox *tox, uint32_t friend_number, uint32_t file_num if (filesize) { sending_pos = size_recv = 1337; - Tox_Err_File_Seek err_s; + Tox_Err_File_Seek err_s = TOX_ERR_FILE_SEEK_OK; ck_assert_msg(tox_file_seek(tox, friend_number, file_number, 1337, &err_s), "tox_file_seek error"); @@ -67,13 +67,13 @@ static void tox_file_receive(Tox *tox, uint32_t friend_number, uint32_t file_num sending_pos = size_recv = 0; } - Tox_Err_File_Control error; + Tox_Err_File_Control error = TOX_ERR_FILE_CONTROL_OK; ck_assert_msg(tox_file_control(tox, friend_number, file_number, TOX_FILE_CONTROL_RESUME, &error), "tox_file_control failed. %i", error); ++file_accepted; - Tox_Err_File_Seek err_s; + Tox_Err_File_Seek err_s = TOX_ERR_FILE_SEEK_OK; ck_assert_msg(!tox_file_seek(tox, friend_number, file_number, 1234, &err_s), "tox_file_seek no error"); @@ -118,7 +118,7 @@ static void tox_file_chunk_request(Tox *tox, uint32_t friend_number, uint32_t fi VLA(uint8_t, f_data, length); memset(f_data, sending_num, length); - Tox_Err_File_Send_Chunk error; + Tox_Err_File_Send_Chunk error = TOX_ERR_FILE_SEND_CHUNK_OK; tox_file_send_chunk(tox, friend_number, file_number, position, f_data, length, &error); @@ -156,7 +156,7 @@ static void file_transfer_test(void) printf("Starting test: few_clients\n"); uint32_t index[] = { 1, 2, 3 }; long long unsigned int cur_time = time(nullptr); - Tox_Err_New t_n_error; + Tox_Err_New t_n_error = TOX_ERR_NEW_OK; Tox *tox1 = tox_new_log(nullptr, &t_n_error, &index[0]); ck_assert_msg(t_n_error == TOX_ERR_NEW_OK, "wrong error"); Tox *tox2 = tox_new_log(nullptr, &t_n_error, &index[1]); @@ -215,7 +215,7 @@ static void file_transfer_test(void) sizeof("Gentoo.exe"), nullptr); ck_assert_msg(fnum != UINT32_MAX, "tox_new_file_sender fail"); - Tox_Err_File_Get gfierr; + Tox_Err_File_Get gfierr = TOX_ERR_FILE_GET_OK; ck_assert_msg(!tox_file_get_file_id(tox2, 1, fnum, file_cmp_id, &gfierr), "tox_file_get_file_id didn't fail"); ck_assert_msg(gfierr == TOX_ERR_FILE_GET_FRIEND_NOT_FOUND, "wrong error"); ck_assert_msg(!tox_file_get_file_id(tox2, 0, fnum + 1, file_cmp_id, &gfierr), "tox_file_get_file_id didn't fail"); diff --git a/auto_tests/forwarding_test.c b/auto_tests/forwarding_test.c index f9c82784f20..39db4126820 100644 --- a/auto_tests/forwarding_test.c +++ b/auto_tests/forwarding_test.c @@ -73,7 +73,7 @@ static void test_forwarded_response_cb(void *object, return; } - uint32_t send_back; + uint32_t send_back = 0; net_unpack_u32(data + 8, &send_back); if (test_data->send_back == send_back) { diff --git a/auto_tests/friend_request_spam_test.c b/auto_tests/friend_request_spam_test.c index 8916f250662..eed899cabbb 100644 --- a/auto_tests/friend_request_spam_test.c +++ b/auto_tests/friend_request_spam_test.c @@ -41,7 +41,7 @@ static void test_friend_request(AutoTox *autotoxes) tox_self_get_address(autotoxes[0].tox, address); for (uint32_t i = 2; i < FR_TOX_COUNT; ++i) { - Tox_Err_Friend_Add err; + Tox_Err_Friend_Add err = TOX_ERR_FRIEND_ADD_OK; tox_friend_add(autotoxes[i].tox, address, (const uint8_t *)FR_MESSAGE, sizeof(FR_MESSAGE), &err); ck_assert_msg(err == TOX_ERR_FRIEND_ADD_OK, "tox %u failed to add friend error code: %d", autotoxes[i].index, err); } diff --git a/auto_tests/group_general_test.c b/auto_tests/group_general_test.c index 1a506ab4f78..16135e15fbc 100644 --- a/auto_tests/group_general_test.c +++ b/auto_tests/group_general_test.c @@ -72,7 +72,7 @@ static void group_peer_join_handler(Tox *tox, uint32_t groupnumber, uint32_t pee State *state = (State *)autotox->state; // we do a connection test here for fun - Tox_Err_Group_Peer_Query pq_err; + Tox_Err_Group_Peer_Query pq_err = TOX_ERR_GROUP_PEER_QUERY_OK; TOX_CONNECTION connection_status = tox_group_peer_get_connection_status(tox, groupnumber, peer_id, &pq_err); ck_assert(pq_err == TOX_ERR_GROUP_PEER_QUERY_OK); ck_assert(connection_status != TOX_CONNECTION_NONE); @@ -132,7 +132,7 @@ static void group_peer_self_join_handler(Tox *tox, uint32_t groupnumber, void *u // make sure we see our own correct peer state on join callback - Tox_Err_Group_Self_Query sq_err; + Tox_Err_Group_Self_Query sq_err = TOX_ERR_GROUP_SELF_QUERY_OK; size_t self_length = tox_group_self_get_name_size(tox, groupnumber, &sq_err); ck_assert(sq_err == TOX_ERR_GROUP_SELF_QUERY_OK); @@ -169,7 +169,7 @@ static void group_peer_self_join_handler(Tox *tox, uint32_t groupnumber, void *u ck_assert(tox_group_get_name_size(tox, groupnumber, nullptr) == GROUP_NAME_LEN); ck_assert(tox_group_get_topic_size(tox, groupnumber, nullptr) == TOPIC_LEN); - Tox_Err_Group_State_Queries query_err; + Tox_Err_Group_State_Queries query_err = TOX_ERR_GROUP_STATE_QUERIES_OK; tox_group_get_name(tox, groupnumber, group_name, &query_err); ck_assert_msg(query_err == TOX_ERR_GROUP_STATE_QUERIES_OK, "%d", query_err); ck_assert(memcmp(group_name, GROUP_NAME, GROUP_NAME_LEN) == 0); @@ -223,7 +223,7 @@ static void group_peer_status_handler(Tox *tox, uint32_t groupnumber, uint32_t p State *state = (State *)autotox->state; - Tox_Err_Group_Peer_Query err; + Tox_Err_Group_Peer_Query err = TOX_ERR_GROUP_PEER_QUERY_OK; TOX_USER_STATUS cur_status = tox_group_peer_get_status(tox, groupnumber, peer_id, &err); ck_assert_msg(cur_status == status, "%d, %d", cur_status, status); @@ -251,7 +251,7 @@ static void group_announce_test(AutoTox *autotoxes) tox_callback_group_peer_exit(tox1, group_peer_exit_handler); // tox0 makes new group. - Tox_Err_Group_New err_new; + Tox_Err_Group_New err_new = TOX_ERR_GROUP_NEW_OK; uint32_t groupnumber = tox_group_new(tox0, TOX_GROUP_PRIVACY_STATE_PUBLIC, (const uint8_t *) GROUP_NAME, GROUP_NAME_LEN, (const uint8_t *)PEER0_NICK, PEER0_NICK_LEN, &err_new); @@ -262,22 +262,22 @@ static void group_announce_test(AutoTox *autotoxes) iterate_all_wait(autotoxes, NUM_GROUP_TOXES, ITERATION_INTERVAL); // changes the state (for sync check purposes) - Tox_Err_Group_Founder_Set_Peer_Limit limit_set_err; + Tox_Err_Group_Founder_Set_Peer_Limit limit_set_err = TOX_ERR_GROUP_FOUNDER_SET_PEER_LIMIT_OK; tox_group_founder_set_peer_limit(tox0, groupnumber, PEER_LIMIT, &limit_set_err); ck_assert_msg(limit_set_err == TOX_ERR_GROUP_FOUNDER_SET_PEER_LIMIT_OK, "failed to set peer limit: %d", limit_set_err); - Tox_Err_Group_Topic_Set tp_err; + Tox_Err_Group_Topic_Set tp_err = TOX_ERR_GROUP_TOPIC_SET_OK; tox_group_set_topic(tox0, groupnumber, (const uint8_t *)TOPIC, TOPIC_LEN, &tp_err); ck_assert(tp_err == TOX_ERR_GROUP_TOPIC_SET_OK); // get the chat id of the new group. - Tox_Err_Group_State_Queries err_id; + Tox_Err_Group_State_Queries err_id = TOX_ERR_GROUP_STATE_QUERIES_OK; uint8_t chat_id[TOX_GROUP_CHAT_ID_SIZE]; tox_group_get_chat_id(tox0, groupnumber, chat_id, &err_id); ck_assert(err_id == TOX_ERR_GROUP_STATE_QUERIES_OK); // tox1 joins it. - Tox_Err_Group_Join err_join; + Tox_Err_Group_Join err_join = TOX_ERR_GROUP_JOIN_OK; tox_group_join(tox1, chat_id, (const uint8_t *)PEER1_NICK, PEER1_NICK_LEN, nullptr, 0, &err_join); ck_assert(err_join == TOX_ERR_GROUP_JOIN_OK); @@ -294,13 +294,13 @@ static void group_announce_test(AutoTox *autotoxes) fprintf(stderr, "Peers connected to group\n"); // tox 0 changes name - Tox_Err_Group_Self_Name_Set n_err; + Tox_Err_Group_Self_Name_Set n_err = TOX_ERR_GROUP_SELF_NAME_SET_OK; tox_group_self_set_name(tox0, groupnumber, (const uint8_t *)PEER0_NICK2, PEER0_NICK2_LEN, &n_err); ck_assert(n_err == TOX_ERR_GROUP_SELF_NAME_SET_OK); iterate_all_wait(autotoxes, NUM_GROUP_TOXES, ITERATION_INTERVAL); - Tox_Err_Group_Self_Query sq_err; + Tox_Err_Group_Self_Query sq_err = TOX_ERR_GROUP_SELF_QUERY_OK; size_t self_length = tox_group_self_get_name_size(tox0, groupnumber, &sq_err); ck_assert(sq_err == TOX_ERR_GROUP_SELF_QUERY_OK); ck_assert(self_length == PEER0_NICK2_LEN); @@ -313,7 +313,7 @@ static void group_announce_test(AutoTox *autotoxes) fprintf(stderr, "Peer 0 successfully changed nick\n"); // tox 0 changes status - Tox_Err_Group_Self_Status_Set s_err; + Tox_Err_Group_Self_Status_Set s_err = TOX_ERR_GROUP_SELF_STATUS_SET_OK; tox_group_self_set_status(tox0, groupnumber, TOX_USER_STATUS_BUSY, &s_err); ck_assert(s_err == TOX_ERR_GROUP_SELF_STATUS_SET_OK); @@ -334,7 +334,7 @@ static void group_announce_test(AutoTox *autotoxes) tox_group_self_get_public_key(tox0, groupnumber, tox0_self_pk, &sq_err); ck_assert(sq_err == TOX_ERR_GROUP_SELF_QUERY_OK); - Tox_Err_Group_Peer_Query pq_err; + Tox_Err_Group_Peer_Query pq_err = TOX_ERR_GROUP_PEER_QUERY_OK; uint8_t tox0_pk_query[TOX_GROUP_PEER_PUBLIC_KEY_SIZE]; tox_group_peer_get_public_key(tox1, groupnumber, state1->peer_id, tox0_pk_query, &pq_err); ck_assert(pq_err == TOX_ERR_GROUP_PEER_QUERY_OK); @@ -342,7 +342,7 @@ static void group_announce_test(AutoTox *autotoxes) fprintf(stderr, "Peer 0 disconnecting...\n"); // tox 0 disconnects then reconnects - Tox_Err_Group_Disconnect d_err; + Tox_Err_Group_Disconnect d_err = TOX_ERR_GROUP_DISCONNECT_OK; tox_group_disconnect(tox0, groupnumber, &d_err); ck_assert(d_err == TOX_ERR_GROUP_DISCONNECT_OK); @@ -355,7 +355,7 @@ static void group_announce_test(AutoTox *autotoxes) ck_assert(s_err == TOX_ERR_GROUP_SELF_STATUS_SET_OK); fprintf(stderr, "Peer 0 reconnecting...\n"); - Tox_Err_Group_Reconnect r_err; + Tox_Err_Group_Reconnect r_err = TOX_ERR_GROUP_RECONNECT_OK; tox_group_reconnect(tox0, groupnumber, &r_err); ck_assert(r_err == TOX_ERR_GROUP_RECONNECT_OK); @@ -393,7 +393,7 @@ static void group_announce_test(AutoTox *autotoxes) fprintf(stderr, "Both peers exiting group...\n"); - Tox_Err_Group_Leave err_exit; + Tox_Err_Group_Leave err_exit = TOX_ERR_GROUP_LEAVE_OK; tox_group_leave(tox0, groupnumber, (const uint8_t *)EXIT_MESSAGE, EXIT_MESSAGE_LEN, &err_exit); ck_assert(err_exit == TOX_ERR_GROUP_LEAVE_OK); diff --git a/auto_tests/group_invite_test.c b/auto_tests/group_invite_test.c index f8dde62ab11..6f8073d9722 100644 --- a/auto_tests/group_invite_test.c +++ b/auto_tests/group_invite_test.c @@ -126,21 +126,21 @@ static void group_invite_test(AutoTox *autotoxes) State *state5 = (State *)autotoxes[5].state; State *state6 = (State *)autotoxes[6].state; - Tox_Err_Group_New new_err; + Tox_Err_Group_New new_err = TOX_ERR_GROUP_NEW_OK; uint32_t groupnumber = tox_group_new(tox0, TOX_GROUP_PRIVACY_STATE_PUBLIC, (const uint8_t *)"test", 4, (const uint8_t *)"test", 4, &new_err); ck_assert_msg(new_err == TOX_ERR_GROUP_NEW_OK, "tox_group_new failed: %d", new_err); iterate_all_wait(autotoxes, NUM_GROUP_TOXES, ITERATION_INTERVAL); - Tox_Err_Group_State_Queries id_err; + Tox_Err_Group_State_Queries id_err = TOX_ERR_GROUP_STATE_QUERIES_OK; uint8_t chat_id[TOX_GROUP_CHAT_ID_SIZE]; tox_group_get_chat_id(tox0, groupnumber, chat_id, &id_err); ck_assert_msg(id_err == TOX_ERR_GROUP_STATE_QUERIES_OK, "%d", id_err); // peer 1 joins public group with no password - Tox_Err_Group_Join join_err; + Tox_Err_Group_Join join_err = TOX_ERR_GROUP_JOIN_OK; tox_group_join(tox1, chat_id, (const uint8_t *)"Test", 4, nullptr, 0, &join_err); ck_assert_msg(join_err == TOX_ERR_GROUP_JOIN_OK, "%d", join_err); @@ -151,7 +151,7 @@ static void group_invite_test(AutoTox *autotoxes) printf("Peer 1 joined group\n"); // founder sets a password - Tox_Err_Group_Founder_Set_Password pass_set_err; + Tox_Err_Group_Founder_Set_Password pass_set_err = TOX_ERR_GROUP_FOUNDER_SET_PASSWORD_OK; tox_group_founder_set_password(tox0, groupnumber, (const uint8_t *)PASSWORD, PASS_LEN, &pass_set_err); ck_assert_msg(pass_set_err == TOX_ERR_GROUP_FOUNDER_SET_PASSWORD_OK, "%d", pass_set_err); @@ -178,7 +178,7 @@ static void group_invite_test(AutoTox *autotoxes) printf("Peer 3 successfully blocked with invalid password\n"); // founder sets peer limit to 1 - Tox_Err_Group_Founder_Set_Peer_Limit limit_set_err; + Tox_Err_Group_Founder_Set_Peer_Limit limit_set_err = TOX_ERR_GROUP_FOUNDER_SET_PEER_LIMIT_OK; tox_group_founder_set_peer_limit(tox0, groupnumber, 1, &limit_set_err); ck_assert_msg(limit_set_err == TOX_ERR_GROUP_FOUNDER_SET_PEER_LIMIT_OK, "%d", limit_set_err); @@ -214,7 +214,7 @@ static void group_invite_test(AutoTox *autotoxes) printf("Peer 5 successfully joined the group\n"); // founder makes group private - Tox_Err_Group_Founder_Set_Privacy_State priv_err; + Tox_Err_Group_Founder_Set_Privacy_State priv_err = TOX_ERR_GROUP_FOUNDER_SET_PRIVACY_STATE_OK; tox_group_founder_set_privacy_state(tox0, groupnumber, TOX_GROUP_PRIVACY_STATE_PRIVATE, &priv_err); ck_assert_msg(priv_err == TOX_ERR_GROUP_FOUNDER_SET_PRIVACY_STATE_OK, "%d", priv_err); @@ -254,7 +254,7 @@ static void group_invite_test(AutoTox *autotoxes) printf("Every peer sees every other peer\n"); for (size_t i = 0; i < NUM_GROUP_TOXES; i++) { - Tox_Err_Group_Leave err_exit; + Tox_Err_Group_Leave err_exit = TOX_ERR_GROUP_LEAVE_OK; tox_group_leave(autotoxes[i].tox, 0, nullptr, 0, &err_exit); ck_assert(err_exit == TOX_ERR_GROUP_LEAVE_OK); } diff --git a/auto_tests/group_message_test.c b/auto_tests/group_message_test.c index d7a00a9fee0..43181aac7db 100644 --- a/auto_tests/group_message_test.c +++ b/auto_tests/group_message_test.c @@ -71,7 +71,7 @@ static void group_invite_handler(Tox *tox, uint32_t friend_number, const uint8_t const uint8_t *group_name, size_t group_name_length, void *user_data) { printf("invite arrived; accepting\n"); - Tox_Err_Group_Invite_Accept err_accept; + Tox_Err_Group_Invite_Accept err_accept = TOX_ERR_GROUP_INVITE_ACCEPT_OK; tox_group_invite_accept(tox, friend_number, invite_data, length, (const uint8_t *)PEER0_NICK, PEER0_NICK_LEN, nullptr, 0, &err_accept); ck_assert(err_accept == TOX_ERR_GROUP_INVITE_ACCEPT_OK); @@ -106,7 +106,7 @@ static void group_custom_private_packet_handler(Tox *tox, uint32_t groupnumber, memcpy(message_buf, data, length); message_buf[length] = 0; - Tox_Err_Group_Peer_Query q_err; + Tox_Err_Group_Peer_Query q_err = TOX_ERR_GROUP_PEER_QUERY_OK; size_t peer_name_len = tox_group_peer_get_name_size(tox, groupnumber, peer_id, &q_err); ck_assert(q_err == TOX_ERR_GROUP_PEER_QUERY_OK); @@ -119,7 +119,7 @@ static void group_custom_private_packet_handler(Tox *tox, uint32_t groupnumber, ck_assert(q_err == TOX_ERR_GROUP_PEER_QUERY_OK); ck_assert(memcmp(peer_name, PEER0_NICK, peer_name_len) == 0); - Tox_Err_Group_Self_Query s_err; + Tox_Err_Group_Self_Query s_err = TOX_ERR_GROUP_SELF_QUERY_OK; size_t self_name_len = tox_group_self_get_name_size(tox, groupnumber, &s_err); ck_assert(s_err == TOX_ERR_GROUP_SELF_QUERY_OK); ck_assert(self_name_len <= TOX_MAX_NAME_LENGTH); @@ -151,7 +151,7 @@ static void group_custom_packet_handler(Tox *tox, uint32_t groupnumber, uint32_t memcpy(message_buf, data, length); message_buf[length] = 0; - Tox_Err_Group_Peer_Query q_err; + Tox_Err_Group_Peer_Query q_err = TOX_ERR_GROUP_PEER_QUERY_OK; size_t peer_name_len = tox_group_peer_get_name_size(tox, groupnumber, peer_id, &q_err); ck_assert(q_err == TOX_ERR_GROUP_PEER_QUERY_OK); @@ -164,7 +164,7 @@ static void group_custom_packet_handler(Tox *tox, uint32_t groupnumber, uint32_t ck_assert(q_err == TOX_ERR_GROUP_PEER_QUERY_OK); ck_assert(memcmp(peer_name, PEER0_NICK, peer_name_len) == 0); - Tox_Err_Group_Self_Query s_err; + Tox_Err_Group_Self_Query s_err = TOX_ERR_GROUP_SELF_QUERY_OK; size_t self_name_len = tox_group_self_get_name_size(tox, groupnumber, &s_err); ck_assert(s_err == TOX_ERR_GROUP_SELF_QUERY_OK); ck_assert(self_name_len <= TOX_MAX_NAME_LENGTH); @@ -197,7 +197,7 @@ static void group_message_handler(Tox *tox, uint32_t groupnumber, uint32_t peer_ memcpy(message_buf, message, length); message_buf[length] = 0; - Tox_Err_Group_Peer_Query q_err; + Tox_Err_Group_Peer_Query q_err = TOX_ERR_GROUP_PEER_QUERY_OK; size_t peer_name_len = tox_group_peer_get_name_size(tox, groupnumber, peer_id, &q_err); ck_assert(q_err == TOX_ERR_GROUP_PEER_QUERY_OK); @@ -210,7 +210,7 @@ static void group_message_handler(Tox *tox, uint32_t groupnumber, uint32_t peer_ ck_assert(q_err == TOX_ERR_GROUP_PEER_QUERY_OK); ck_assert(memcmp(peer_name, PEER0_NICK, peer_name_len) == 0); - Tox_Err_Group_Self_Query s_err; + Tox_Err_Group_Self_Query s_err = TOX_ERR_GROUP_SELF_QUERY_OK; size_t self_name_len = tox_group_self_get_name_size(tox, groupnumber, &s_err); ck_assert(s_err == TOX_ERR_GROUP_SELF_QUERY_OK); ck_assert(self_name_len <= TOX_MAX_NAME_LENGTH); @@ -244,7 +244,7 @@ static void group_private_message_handler(Tox *tox, uint32_t groupnumber, uint32 memcpy(message_buf, message, length); message_buf[length] = 0; - Tox_Err_Group_Peer_Query q_err; + Tox_Err_Group_Peer_Query q_err = TOX_ERR_GROUP_PEER_QUERY_OK; size_t peer_name_len = tox_group_peer_get_name_size(tox, groupnumber, peer_id, &q_err); ck_assert(q_err == TOX_ERR_GROUP_PEER_QUERY_OK); @@ -257,7 +257,7 @@ static void group_private_message_handler(Tox *tox, uint32_t groupnumber, uint32 ck_assert(q_err == TOX_ERR_GROUP_PEER_QUERY_OK); ck_assert(memcmp(peer_name, PEER0_NICK, peer_name_len) == 0); - Tox_Err_Group_Self_Query s_err; + Tox_Err_Group_Self_Query s_err = TOX_ERR_GROUP_SELF_QUERY_OK; size_t self_name_len = tox_group_self_get_name_size(tox, groupnumber, &s_err); ck_assert(s_err == TOX_ERR_GROUP_SELF_QUERY_OK); ck_assert(self_name_len <= TOX_MAX_NAME_LENGTH); @@ -292,8 +292,8 @@ static void group_message_handler_lossless_test(Tox *tox, uint32_t groupnumber, ck_assert(length >= 4 && length <= TOX_GROUP_MAX_MESSAGE_LENGTH); - uint16_t start; - uint16_t checksum; + uint16_t start = 0; + uint16_t checksum = 0; memcpy(&start, message, sizeof(uint16_t)); memcpy(&checksum, message + sizeof(uint16_t), sizeof(uint16_t)); @@ -317,7 +317,7 @@ static void group_message_handler_wraparound_test(Tox *tox, uint32_t groupnumber ck_assert(length == 2); - uint16_t num; + uint16_t num = 0; memcpy(&num, message, sizeof(uint16_t)); ck_assert_msg(num == state->last_msg_recv + 1, "Expected %d, got start %u", state->last_msg_recv + 1, num); @@ -357,19 +357,19 @@ static void group_message_test(AutoTox *autotoxes) tox_callback_group_custom_private_packet(tox0, group_custom_private_packet_handler); tox_callback_group_private_message(tox0, group_private_message_handler); - Tox_Err_Group_Send_Message err_send; + Tox_Err_Group_Send_Message err_send = TOX_ERR_GROUP_SEND_MESSAGE_OK; fprintf(stderr, "Tox 0 creates new group and invites tox1...\n"); // tox0 makes new group. - Tox_Err_Group_New err_new; + Tox_Err_Group_New err_new = TOX_ERR_GROUP_NEW_OK; const uint32_t group_number = tox_group_new(tox0, TOX_GROUP_PRIVACY_STATE_PRIVATE, (const uint8_t *)TEST_GROUP_NAME, TEST_GROUP_NAME_LEN, (const uint8_t *)PEER1_NICK, PEER1_NICK_LEN, &err_new); ck_assert(err_new == TOX_ERR_GROUP_NEW_OK); // tox0 invites tox1 - Tox_Err_Group_Invite_Friend err_invite; + Tox_Err_Group_Invite_Friend err_invite = TOX_ERR_GROUP_INVITE_FRIEND_OK; tox_group_invite_friend(tox0, group_number, 0, &err_invite); ck_assert(err_invite == TOX_ERR_GROUP_INVITE_FRIEND_OK); @@ -393,7 +393,7 @@ static void group_message_test(AutoTox *autotoxes) ck_assert(conn_1 != TOX_CONNECTION_NONE && conn_2 != TOX_CONNECTION_NONE); // tox0 ignores tox1 - Tox_Err_Group_Set_Ignore ig_err; + Tox_Err_Group_Set_Ignore ig_err = TOX_ERR_GROUP_SET_IGNORE_OK; tox_group_set_ignore(tox0, group_number, state0->peer_id, true, &ig_err); ck_assert_msg(ig_err == TOX_ERR_GROUP_SET_IGNORE_OK, "%d", ig_err); @@ -412,7 +412,7 @@ static void group_message_test(AutoTox *autotoxes) fprintf(stderr, "Sending private message...\n"); // tox0 sends a private action to tox1 - Tox_Err_Group_Send_Private_Message m_err; + Tox_Err_Group_Send_Private_Message m_err = TOX_ERR_GROUP_SEND_PRIVATE_MESSAGE_OK; tox_group_send_private_message(tox1, group_number, state1->peer_id, TOX_MESSAGE_TYPE_ACTION, (const uint8_t *)TEST_PRIVATE_MESSAGE, TEST_PRIVATE_MESSAGE_LEN, &m_err); ck_assert_msg(m_err == TOX_ERR_GROUP_SEND_PRIVATE_MESSAGE_OK, "%d", m_err); @@ -420,7 +420,7 @@ static void group_message_test(AutoTox *autotoxes) fprintf(stderr, "Sending custom packets...\n"); // tox0 sends a lossless and lossy custom packet to tox1 - Tox_Err_Group_Send_Custom_Packet c_err; + Tox_Err_Group_Send_Custom_Packet c_err = TOX_ERR_GROUP_SEND_CUSTOM_PACKET_OK; tox_group_send_custom_packet(tox1, group_number, true, (const uint8_t *)TEST_CUSTOM_PACKET, TEST_CUSTOM_PACKET_LEN, &c_err); ck_assert_msg(c_err == TOX_ERR_GROUP_SEND_CUSTOM_PACKET_OK, "%d", c_err); @@ -432,7 +432,7 @@ static void group_message_test(AutoTox *autotoxes) fprintf(stderr, "Sending custom private packets...\n"); // tox0 sends a lossless and lossy custom private packet to tox1 - Tox_Err_Group_Send_Custom_Private_Packet cperr; + Tox_Err_Group_Send_Custom_Private_Packet cperr = TOX_ERR_GROUP_SEND_CUSTOM_PRIVATE_PACKET_OK; tox_group_send_custom_private_packet(tox1, group_number, state1->peer_id, true, (const uint8_t *)TEST_CUSTOM_PRIVATE_PACKET, TEST_CUSTOM_PRIVATE_PACKET_LEN, &cperr); @@ -506,7 +506,7 @@ static void group_message_test(AutoTox *autotoxes) } for (size_t i = 0; i < NUM_GROUP_TOXES; i++) { - Tox_Err_Group_Leave err_exit; + Tox_Err_Group_Leave err_exit = TOX_ERR_GROUP_LEAVE_OK; tox_group_leave(autotoxes[i].tox, group_number, nullptr, 0, &err_exit); ck_assert(err_exit == TOX_ERR_GROUP_LEAVE_OK); } diff --git a/auto_tests/group_moderation_test.c b/auto_tests/group_moderation_test.c index a53609feba5..bfba488529b 100644 --- a/auto_tests/group_moderation_test.c +++ b/auto_tests/group_moderation_test.c @@ -172,7 +172,7 @@ static void group_peer_join_handler(Tox *tox, uint32_t group_number, uint32_t pe char peer_name[TOX_MAX_NAME_LENGTH + 1]; - Tox_Err_Group_Peer_Query q_err; + Tox_Err_Group_Peer_Query q_err = TOX_ERR_GROUP_PEER_QUERY_OK; size_t peer_name_len = tox_group_peer_get_name_size(tox, group_number, peer_id, &q_err); ck_assert(q_err == TOX_ERR_GROUP_PEER_QUERY_OK); @@ -258,7 +258,7 @@ static void group_mod_event_handler(Tox *tox, uint32_t group_number, uint32_t so char peer_name[TOX_MAX_NAME_LENGTH + 1]; - Tox_Err_Group_Peer_Query q_err; + Tox_Err_Group_Peer_Query q_err = TOX_ERR_GROUP_PEER_QUERY_OK; size_t peer_name_len = tox_group_peer_get_name_size(tox, group_number, target_peer_id, &q_err); if (q_err == TOX_ERR_GROUP_PEER_QUERY_PEER_NOT_FOUND) { // may occurr on sync attempts @@ -307,7 +307,7 @@ static void group_mod_event_handler(Tox *tox, uint32_t group_number, uint32_t so /* Checks that `peer_id` sees itself with the role `role`. */ static void check_self_role(AutoTox *autotoxes, uint32_t peer_id, Tox_Group_Role role) { - Tox_Err_Group_Self_Query sq_err; + Tox_Err_Group_Self_Query sq_err = TOX_ERR_GROUP_SELF_QUERY_OK; for (size_t i = 0; i < NUM_GROUP_TOXES; ++i) { State *state = (State *)autotoxes[i].state; @@ -329,11 +329,11 @@ static void voice_state_message_test(AutoTox *autotox, Tox_Group_Voice_State voi { const State *state = (State *)autotox->state; - Tox_Err_Group_Self_Query sq_err; + Tox_Err_Group_Self_Query sq_err = TOX_ERR_GROUP_SELF_QUERY_OK; Tox_Group_Role self_role = tox_group_self_get_role(autotox->tox, state->group_number, &sq_err); ck_assert(sq_err == TOX_ERR_GROUP_SELF_QUERY_OK); - Tox_Err_Group_Send_Message msg_err; + Tox_Err_Group_Send_Message msg_err = TOX_ERR_GROUP_SEND_MESSAGE_OK; bool send_ret = tox_group_send_message(autotox->tox, state->group_number, TOX_MESSAGE_TYPE_NORMAL, (const uint8_t *)"test", 4, nullptr, &msg_err); @@ -374,7 +374,7 @@ static void voice_state_message_test(AutoTox *autotox, Tox_Group_Voice_State voi static bool all_peers_got_voice_state_change(AutoTox *autotoxes, uint32_t num_toxes, Tox_Group_Voice_State expected_voice_state) { - Tox_Err_Group_State_Queries query_err; + Tox_Err_Group_State_Queries query_err = TOX_ERR_GROUP_STATE_QUERIES_OK; for (uint32_t i = 0; i < num_toxes; ++i) { const State *state = (State *)autotoxes[i].state; @@ -394,7 +394,7 @@ static void check_voice_state(AutoTox *autotoxes, uint32_t num_toxes) { // founder sets voice state to Moderator const State *state = (State *)autotoxes[0].state; - Tox_Err_Group_Founder_Set_Voice_State voice_set_err; + Tox_Err_Group_Founder_Set_Voice_State voice_set_err = TOX_ERR_GROUP_FOUNDER_SET_VOICE_STATE_OK; tox_group_founder_set_voice_state(autotoxes[0].tox, state->group_number, TOX_GROUP_VOICE_STATE_MODERATOR, &voice_set_err); ck_assert(voice_set_err == TOX_ERR_GROUP_FOUNDER_SET_VOICE_STATE_OK); @@ -457,7 +457,7 @@ static void group_moderation_test(AutoTox *autotoxes) State *state0 = (State *)autotoxes[0].state; Tox *tox0 = autotoxes[0].tox; - Tox_Err_Group_New err_new; + Tox_Err_Group_New err_new = TOX_ERR_GROUP_NEW_OK; state0->group_number = tox_group_new(tox0, TOX_GROUP_PRIVACY_STATE_PUBLIC, (const uint8_t *)GROUP_NAME, GROUP_NAME_LEN, (const uint8_t *)state0->self_name, state0->self_name_length, &err_new); @@ -465,7 +465,7 @@ static void group_moderation_test(AutoTox *autotoxes) ck_assert_msg(err_new == TOX_ERR_GROUP_NEW_OK, "Failed to create group. error: %d\n", err_new); /* Founder gets chat ID */ - Tox_Err_Group_State_Queries id_err; + Tox_Err_Group_State_Queries id_err = TOX_ERR_GROUP_STATE_QUERIES_OK; uint8_t chat_id[TOX_GROUP_CHAT_ID_SIZE]; tox_group_get_chat_id(tox0, state0->group_number, chat_id, &id_err); @@ -477,7 +477,7 @@ static void group_moderation_test(AutoTox *autotoxes) iterate_all_wait(autotoxes, NUM_GROUP_TOXES, ITERATION_INTERVAL); State *state = (State *)autotoxes[i].state; - Tox_Err_Group_Join join_err; + Tox_Err_Group_Join join_err = TOX_ERR_GROUP_JOIN_OK; state->group_number = tox_group_join(autotoxes[i].tox, chat_id, (const uint8_t *)state->self_name, state->self_name_length, nullptr, 0, &join_err); @@ -502,7 +502,7 @@ static void group_moderation_test(AutoTox *autotoxes) } /* founder checks his own role */ - Tox_Err_Group_Self_Query sq_err; + Tox_Err_Group_Self_Query sq_err = TOX_ERR_GROUP_SELF_QUERY_OK; Tox_Group_Role self_role = tox_group_self_get_role(tox0, state0->group_number, &sq_err); ck_assert(sq_err == TOX_ERR_GROUP_SELF_QUERY_OK); ck_assert(self_role == TOX_GROUP_ROLE_FOUNDER); @@ -518,7 +518,7 @@ static void group_moderation_test(AutoTox *autotoxes) /* founder sets first peer to moderator */ fprintf(stderr, "Founder setting %s to moderator\n", state0->peers[0].name); - Tox_Err_Group_Mod_Set_Role role_err; + Tox_Err_Group_Mod_Set_Role role_err = TOX_ERR_GROUP_MOD_SET_ROLE_OK; tox_group_mod_set_role(tox0, state0->group_number, state0->peers[0].peer_id, TOX_GROUP_ROLE_MODERATOR, &role_err); ck_assert_msg(role_err == TOX_ERR_GROUP_MOD_SET_ROLE_OK, "Failed to set moderator. error: %d", role_err); @@ -600,7 +600,7 @@ static void group_moderation_test(AutoTox *autotoxes) tox_group_mod_set_role(tox1, state1->group_number, founder_peer_id, TOX_GROUP_ROLE_OBSERVER, &role_err); ck_assert_msg(role_err != TOX_ERR_GROUP_MOD_SET_ROLE_OK, "Mod set founder to observer"); - Tox_Err_Group_Mod_Kick_Peer k_err; + Tox_Err_Group_Mod_Kick_Peer k_err = TOX_ERR_GROUP_MOD_KICK_PEER_OK; tox_group_mod_kick_peer(tox1, state1->group_number, founder_peer_id, &k_err); ck_assert_msg(k_err != TOX_ERR_GROUP_MOD_KICK_PEER_OK, "Mod kicked founder"); @@ -628,7 +628,7 @@ static void group_moderation_test(AutoTox *autotoxes) for (size_t i = 0; i < NUM_GROUP_TOXES; i++) { const State *state = (const State *)autotoxes[i].state; - Tox_Err_Group_Leave err_exit; + Tox_Err_Group_Leave err_exit = TOX_ERR_GROUP_LEAVE_OK; tox_group_leave(autotoxes[i].tox, state->group_number, nullptr, 0, &err_exit); ck_assert(err_exit == TOX_ERR_GROUP_LEAVE_OK); } diff --git a/auto_tests/group_save_test.c b/auto_tests/group_save_test.c index 0cca6cd9a96..d48229e81f3 100644 --- a/auto_tests/group_save_test.c +++ b/auto_tests/group_save_test.c @@ -29,7 +29,7 @@ typedef struct State { static void group_invite_handler(Tox *tox, uint32_t friend_number, const uint8_t *invite_data, size_t length, const uint8_t *group_name, size_t group_name_length, void *user_data) { - Tox_Err_Group_Invite_Accept err_accept; + Tox_Err_Group_Invite_Accept err_accept = TOX_ERR_GROUP_INVITE_ACCEPT_OK; tox_group_invite_accept(tox, friend_number, invite_data, length, (const uint8_t *)"test2", 5, nullptr, 0, &err_accept); ck_assert(err_accept == TOX_ERR_GROUP_INVITE_ACCEPT_OK); @@ -52,7 +52,7 @@ static void group_peer_join_handler(Tox *tox, uint32_t group_number, uint32_t pe */ static int has_correct_group_state(const Tox *tox, uint32_t group_number, const uint8_t *expected_chat_id) { - Tox_Err_Group_State_Queries query_err; + Tox_Err_Group_State_Queries query_err = TOX_ERR_GROUP_STATE_QUERIES_OK; Tox_Group_Privacy_State priv_state = tox_group_get_privacy_state(tox, group_number, &query_err); ck_assert(query_err == TOX_ERR_GROUP_STATE_QUERIES_OK); @@ -93,7 +93,7 @@ static int has_correct_group_state(const Tox *tox, uint32_t group_number, const return -5; } - Tox_Err_Group_State_Queries id_err; + Tox_Err_Group_State_Queries id_err = TOX_ERR_GROUP_STATE_QUERIES_OK; uint8_t chat_id[TOX_GROUP_CHAT_ID_SIZE]; tox_group_get_chat_id(tox, group_number, chat_id, &id_err); @@ -108,7 +108,7 @@ static int has_correct_group_state(const Tox *tox, uint32_t group_number, const static int has_correct_self_state(const Tox *tox, uint32_t group_number, const uint8_t *expected_self_pk) { - Tox_Err_Group_Self_Query sq_err; + Tox_Err_Group_Self_Query sq_err = TOX_ERR_GROUP_SELF_QUERY_OK; size_t self_length = tox_group_self_get_name_size(tox, group_number, &sq_err); ck_assert(sq_err == TOX_ERR_GROUP_SELF_QUERY_OK); @@ -161,7 +161,7 @@ static void group_save_test(AutoTox *autotoxes) const State *state0 = (State *)autotoxes[0].state; const State *state1 = (State *)autotoxes[1].state; - Tox_Err_Group_New err_new; + Tox_Err_Group_New err_new = TOX_ERR_GROUP_NEW_OK; const uint32_t group_number = tox_group_new(tox0, TOX_GROUP_PRIVACY_STATE_PRIVATE, (const uint8_t *)GROUP_NAME, GROUP_NAME_LEN, (const uint8_t *)"test", 4, &err_new); @@ -169,18 +169,18 @@ static void group_save_test(AutoTox *autotoxes) uint8_t chat_id[TOX_GROUP_CHAT_ID_SIZE]; - Tox_Err_Group_State_Queries id_err; + Tox_Err_Group_State_Queries id_err = TOX_ERR_GROUP_STATE_QUERIES_OK; tox_group_get_chat_id(tox0, group_number, chat_id, &id_err); ck_assert(id_err == TOX_ERR_GROUP_STATE_QUERIES_OK); uint8_t founder_pk[TOX_GROUP_PEER_PUBLIC_KEY_SIZE]; - Tox_Err_Group_Self_Query sq_err; + Tox_Err_Group_Self_Query sq_err = TOX_ERR_GROUP_SELF_QUERY_OK; tox_group_self_get_public_key(tox0, group_number, founder_pk, &sq_err); ck_assert(sq_err == TOX_ERR_GROUP_SELF_QUERY_OK); - Tox_Err_Group_Invite_Friend err_invite; + Tox_Err_Group_Invite_Friend err_invite = TOX_ERR_GROUP_INVITE_FRIEND_OK; tox_group_invite_friend(tox0, group_number, 0, &err_invite); ck_assert(err_invite == TOX_ERR_GROUP_INVITE_FRIEND_OK); @@ -192,32 +192,32 @@ static void group_save_test(AutoTox *autotoxes) printf("tox0 invites tox1 to group\n"); // change group state - Tox_Err_Group_Topic_Set top_err; + Tox_Err_Group_Topic_Set top_err = TOX_ERR_GROUP_TOPIC_SET_OK; tox_group_set_topic(tox0, group_number, (const uint8_t *)TOPIC, TOPIC_LEN, &top_err); ck_assert(top_err == TOX_ERR_GROUP_TOPIC_SET_OK); - Tox_Err_Group_Founder_Set_Topic_Lock lock_set_err; + Tox_Err_Group_Founder_Set_Topic_Lock lock_set_err = TOX_ERR_GROUP_FOUNDER_SET_TOPIC_LOCK_OK; tox_group_founder_set_topic_lock(tox0, group_number, TOX_GROUP_TOPIC_LOCK_DISABLED, &lock_set_err); ck_assert(lock_set_err == TOX_ERR_GROUP_FOUNDER_SET_TOPIC_LOCK_OK); - Tox_Err_Group_Founder_Set_Privacy_State priv_err; + Tox_Err_Group_Founder_Set_Privacy_State priv_err = TOX_ERR_GROUP_FOUNDER_SET_PRIVACY_STATE_OK; tox_group_founder_set_privacy_state(tox0, group_number, NEW_PRIV_STATE, &priv_err); ck_assert(priv_err == TOX_ERR_GROUP_FOUNDER_SET_PRIVACY_STATE_OK); - Tox_Err_Group_Founder_Set_Password pass_set_err; + Tox_Err_Group_Founder_Set_Password pass_set_err = TOX_ERR_GROUP_FOUNDER_SET_PASSWORD_OK; tox_group_founder_set_password(tox0, group_number, (const uint8_t *)PASSWORD, PASS_LEN, &pass_set_err); ck_assert(pass_set_err == TOX_ERR_GROUP_FOUNDER_SET_PASSWORD_OK); - Tox_Err_Group_Founder_Set_Peer_Limit limit_set_err; + Tox_Err_Group_Founder_Set_Peer_Limit limit_set_err = TOX_ERR_GROUP_FOUNDER_SET_PEER_LIMIT_OK; tox_group_founder_set_peer_limit(tox0, group_number, PEER_LIMIT, &limit_set_err); ck_assert(limit_set_err == TOX_ERR_GROUP_FOUNDER_SET_PEER_LIMIT_OK); // change self state - Tox_Err_Group_Self_Name_Set n_err; + Tox_Err_Group_Self_Name_Set n_err = TOX_ERR_GROUP_SELF_NAME_SET_OK; tox_group_self_set_name(tox0, group_number, (const uint8_t *)PEER0_NICK, PEER0_NICK_LEN, &n_err); ck_assert(n_err == TOX_ERR_GROUP_SELF_NAME_SET_OK); - Tox_Err_Group_Self_Status_Set s_err; + Tox_Err_Group_Self_Status_Set s_err = TOX_ERR_GROUP_SELF_STATUS_SET_OK; tox_group_self_set_status(tox0, group_number, NEW_USER_STATUS, &s_err); ck_assert(s_err == TOX_ERR_GROUP_SELF_STATUS_SET_OK); diff --git a/auto_tests/group_state_test.c b/auto_tests/group_state_test.c index adbe1725fc2..7b191db1449 100644 --- a/auto_tests/group_state_test.c +++ b/auto_tests/group_state_test.c @@ -63,7 +63,7 @@ static bool all_group_peers_connected(const AutoTox *autotoxes, uint32_t tox_cou static void group_topic_lock_handler(Tox *tox, uint32_t groupnumber, Tox_Group_Topic_Lock topic_lock, void *user_data) { - Tox_Err_Group_State_Queries err; + Tox_Err_Group_State_Queries err = TOX_ERR_GROUP_STATE_QUERIES_OK; Tox_Group_Topic_Lock current_topic_lock = tox_group_get_topic_lock(tox, groupnumber, &err); ck_assert(err == TOX_ERR_GROUP_STATE_QUERIES_OK); @@ -74,7 +74,7 @@ static void group_topic_lock_handler(Tox *tox, uint32_t groupnumber, Tox_Group_T static void group_voice_state_handler(Tox *tox, uint32_t groupnumber, Tox_Group_Voice_State voice_state, void *user_data) { - Tox_Err_Group_State_Queries err; + Tox_Err_Group_State_Queries err = TOX_ERR_GROUP_STATE_QUERIES_OK; Tox_Group_Voice_State current_voice_state = tox_group_get_voice_state(tox, groupnumber, &err); ck_assert(err == TOX_ERR_GROUP_STATE_QUERIES_OK); @@ -85,7 +85,7 @@ static void group_voice_state_handler(Tox *tox, uint32_t groupnumber, Tox_Group_ static void group_privacy_state_handler(Tox *tox, uint32_t groupnumber, Tox_Group_Privacy_State privacy_state, void *user_data) { - Tox_Err_Group_State_Queries err; + Tox_Err_Group_State_Queries err = TOX_ERR_GROUP_STATE_QUERIES_OK; Tox_Group_Privacy_State current_pstate = tox_group_get_privacy_state(tox, groupnumber, &err); ck_assert(err == TOX_ERR_GROUP_STATE_QUERIES_OK); @@ -94,7 +94,7 @@ static void group_privacy_state_handler(Tox *tox, uint32_t groupnumber, Tox_Grou static void group_peer_limit_handler(Tox *tox, uint32_t groupnumber, uint32_t peer_limit, void *user_data) { - Tox_Err_Group_State_Queries err; + Tox_Err_Group_State_Queries err = TOX_ERR_GROUP_STATE_QUERIES_OK; uint32_t current_plimit = tox_group_get_peer_limit(tox, groupnumber, &err); ck_assert(err == TOX_ERR_GROUP_STATE_QUERIES_OK); @@ -105,7 +105,7 @@ static void group_peer_limit_handler(Tox *tox, uint32_t groupnumber, uint32_t pe static void group_password_handler(Tox *tox, uint32_t groupnumber, const uint8_t *password, size_t length, void *user_data) { - Tox_Err_Group_State_Queries err; + Tox_Err_Group_State_Queries err = TOX_ERR_GROUP_STATE_QUERIES_OK; size_t curr_pwlength = tox_group_get_password_size(tox, groupnumber, &err); ck_assert(err == TOX_ERR_GROUP_STATE_QUERIES_OK); @@ -137,7 +137,7 @@ static int check_group_state(const Tox *tox, uint32_t groupnumber, uint32_t peer Tox_Group_Privacy_State priv_state, Tox_Group_Voice_State voice_state, const uint8_t *password, size_t pass_len, Tox_Group_Topic_Lock topic_lock) { - Tox_Err_Group_State_Queries query_err; + Tox_Err_Group_State_Queries query_err = TOX_ERR_GROUP_STATE_QUERIES_OK; Tox_Group_Privacy_State my_priv_state = tox_group_get_privacy_state(tox, groupnumber, &query_err); ck_assert_msg(query_err == TOX_ERR_GROUP_STATE_QUERIES_OK, "Failed to get privacy state: %d", query_err); @@ -213,24 +213,24 @@ static void set_group_state(Tox *tox, uint32_t groupnumber, uint32_t peer_limit, Tox_Group_Topic_Lock topic_lock) { - Tox_Err_Group_Founder_Set_Peer_Limit limit_set_err; + Tox_Err_Group_Founder_Set_Peer_Limit limit_set_err = TOX_ERR_GROUP_FOUNDER_SET_PEER_LIMIT_OK; tox_group_founder_set_peer_limit(tox, groupnumber, peer_limit, &limit_set_err); ck_assert_msg(limit_set_err == TOX_ERR_GROUP_FOUNDER_SET_PEER_LIMIT_OK, "failed to set peer limit: %d", limit_set_err); - Tox_Err_Group_Founder_Set_Privacy_State priv_err; + Tox_Err_Group_Founder_Set_Privacy_State priv_err = TOX_ERR_GROUP_FOUNDER_SET_PRIVACY_STATE_OK; tox_group_founder_set_privacy_state(tox, groupnumber, priv_state, &priv_err); ck_assert_msg(priv_err == TOX_ERR_GROUP_FOUNDER_SET_PRIVACY_STATE_OK, "failed to set privacy state: %d", priv_err); - Tox_Err_Group_Founder_Set_Password pass_set_err; + Tox_Err_Group_Founder_Set_Password pass_set_err = TOX_ERR_GROUP_FOUNDER_SET_PASSWORD_OK; tox_group_founder_set_password(tox, groupnumber, password, pass_len, &pass_set_err); ck_assert_msg(pass_set_err == TOX_ERR_GROUP_FOUNDER_SET_PASSWORD_OK, "failed to set password: %d", pass_set_err); - Tox_Err_Group_Founder_Set_Topic_Lock lock_set_err; + Tox_Err_Group_Founder_Set_Topic_Lock lock_set_err = TOX_ERR_GROUP_FOUNDER_SET_TOPIC_LOCK_OK; tox_group_founder_set_topic_lock(tox, groupnumber, topic_lock, &lock_set_err); ck_assert_msg(lock_set_err == TOX_ERR_GROUP_FOUNDER_SET_TOPIC_LOCK_OK, "failed to set topic lock: %d", lock_set_err); - Tox_Err_Group_Founder_Set_Voice_State voice_set_err; + Tox_Err_Group_Founder_Set_Voice_State voice_set_err = TOX_ERR_GROUP_FOUNDER_SET_VOICE_STATE_OK; tox_group_founder_set_voice_state(tox, groupnumber, voice_state, &voice_set_err); ck_assert_msg(voice_set_err == TOX_ERR_GROUP_FOUNDER_SET_VOICE_STATE_OK, "failed to set voice state: %d", voice_set_err); @@ -253,7 +253,7 @@ static void group_state_test(AutoTox *autotoxes) Tox *tox0 = autotoxes[0].tox; /* Tox 0 creates a group and is the founder of a newly created group */ - Tox_Err_Group_New new_err; + Tox_Err_Group_New new_err = TOX_ERR_GROUP_NEW_OK; uint32_t groupnum = tox_group_new(tox0, TOX_GROUP_PRIVACY_STATE_PUBLIC, (const uint8_t *)GROUP_NAME, GROUP_NAME_LEN, (const uint8_t *)PEER0_NICK, PEER0_NICK_LEN, &new_err); @@ -264,7 +264,7 @@ static void group_state_test(AutoTox *autotoxes) (const uint8_t *)PASSWORD, PASS_LEN, TOX_GROUP_TOPIC_LOCK_ENABLED); /* Founder gets the Chat ID and implicitly shares it publicly */ - Tox_Err_Group_State_Queries id_err; + Tox_Err_Group_State_Queries id_err = TOX_ERR_GROUP_STATE_QUERIES_OK; uint8_t chat_id[TOX_GROUP_CHAT_ID_SIZE]; tox_group_get_chat_id(tox0, groupnum, chat_id, &id_err); @@ -274,7 +274,7 @@ static void group_state_test(AutoTox *autotoxes) for (size_t i = 1; i < NUM_GROUP_TOXES; ++i) { iterate_all_wait(autotoxes, NUM_GROUP_TOXES, ITERATION_INTERVAL); - Tox_Err_Group_Join join_err; + Tox_Err_Group_Join join_err = TOX_ERR_GROUP_JOIN_OK; tox_group_join(autotoxes[i].tox, chat_id, (const uint8_t *)"Test", 4, (const uint8_t *)PASSWORD, PASS_LEN, &join_err); ck_assert_msg(join_err == TOX_ERR_GROUP_JOIN_OK, "tox_group_join failed: %d", join_err); @@ -312,7 +312,7 @@ static void group_state_test(AutoTox *autotoxes) } for (size_t i = 0; i < NUM_GROUP_TOXES; ++i) { - Tox_Err_Group_Leave err_exit; + Tox_Err_Group_Leave err_exit = TOX_ERR_GROUP_LEAVE_OK; tox_group_leave(autotoxes[i].tox, groupnum, nullptr, 0, &err_exit); ck_assert_msg(err_exit == TOX_ERR_GROUP_LEAVE_OK, "%d", err_exit); } diff --git a/auto_tests/group_sync_test.c b/auto_tests/group_sync_test.c index 4d2bc1866dc..6e780265436 100644 --- a/auto_tests/group_sync_test.c +++ b/auto_tests/group_sync_test.c @@ -52,7 +52,7 @@ static int add_peer(Peers *peers, uint32_t peer_id) static int del_peer(Peers *peers, uint32_t peer_id) { bool found_peer = false; - int64_t i; + int64_t i = 0; for (i = 0; i < peers->num_peers; ++i) { if (peers->peer_ids[i] == peer_id) { @@ -242,7 +242,7 @@ static bool set_topic_all_peers(const Random *rng, AutoTox *autotoxes, size_t nu snprintf(new_topic, sizeof(new_topic), "peer %zu's topic %u", i, random_u32(rng)); const size_t length = strlen(new_topic); - Tox_Err_Group_Topic_Set err; + Tox_Err_Group_Topic_Set err = TOX_ERR_GROUP_TOPIC_SET_OK; tox_group_set_topic(autotoxes[i].tox, groupnumber, (const uint8_t *)new_topic, length, &err); if (err != TOX_ERR_GROUP_TOPIC_SET_OK) { @@ -260,7 +260,7 @@ static bool all_peers_have_same_topic(const AutoTox *autotoxes, uint32_t num_pee { uint8_t expected_topic[TOX_GROUP_MAX_TOPIC_LENGTH]; - Tox_Err_Group_State_Queries query_err; + Tox_Err_Group_State_Queries query_err = TOX_ERR_GROUP_STATE_QUERIES_OK; size_t expected_topic_length = tox_group_get_topic_size(autotoxes[0].tox, groupnumber, &query_err); ck_assert(query_err == TOX_ERR_GROUP_STATE_QUERIES_OK); @@ -349,7 +349,7 @@ static void group_sync_test(AutoTox *autotoxes) Tox *tox0 = autotoxes[0].tox; State *state0 = (State *)autotoxes[0].state; - Tox_Err_Group_New err_new; + Tox_Err_Group_New err_new = TOX_ERR_GROUP_NEW_OK; uint32_t groupnumber = tox_group_new(tox0, TOX_GROUP_PRIVACY_STATE_PUBLIC, (const uint8_t *) "test", 4, (const uint8_t *)"test", 4, &err_new); @@ -357,14 +357,14 @@ static void group_sync_test(AutoTox *autotoxes) fprintf(stderr, "tox0 creats new group and invites all his friends"); - Tox_Err_Group_State_Queries id_err; + Tox_Err_Group_State_Queries id_err = TOX_ERR_GROUP_STATE_QUERIES_OK; uint8_t chat_id[TOX_GROUP_CHAT_ID_SIZE]; tox_group_get_chat_id(tox0, groupnumber, chat_id, &id_err); ck_assert_msg(id_err == TOX_ERR_GROUP_STATE_QUERIES_OK, "%d", id_err); for (size_t i = 1; i < NUM_GROUP_TOXES; ++i) { - Tox_Err_Group_Join join_err; + Tox_Err_Group_Join join_err = TOX_ERR_GROUP_JOIN_OK; tox_group_join(autotoxes[i].tox, chat_id, (const uint8_t *)"Test", 4, nullptr, 0, &join_err); ck_assert_msg(join_err == TOX_ERR_GROUP_JOIN_OK, "%d", join_err); iterate_all_wait(autotoxes, NUM_GROUP_TOXES, ITERATION_INTERVAL); @@ -376,7 +376,7 @@ static void group_sync_test(AutoTox *autotoxes) fprintf(stderr, "%d peers joined the group\n", NUM_GROUP_TOXES); - Tox_Err_Group_Founder_Set_Topic_Lock lock_set_err; + Tox_Err_Group_Founder_Set_Topic_Lock lock_set_err = TOX_ERR_GROUP_FOUNDER_SET_TOPIC_LOCK_OK; tox_group_founder_set_topic_lock(tox0, groupnumber, TOX_GROUP_TOPIC_LOCK_DISABLED, &lock_set_err); ck_assert_msg(lock_set_err == TOX_ERR_GROUP_FOUNDER_SET_TOPIC_LOCK_OK, "failed to disable topic lock: %d", lock_set_err); @@ -399,7 +399,7 @@ static void group_sync_test(AutoTox *autotoxes) && !all_peers_see_same_roles(autotoxes, NUM_GROUP_TOXES, groupnumber) && state0->peers->num_peers != NUM_GROUP_TOXES - 1); - Tox_Err_Group_Mod_Set_Role role_err; + Tox_Err_Group_Mod_Set_Role role_err = TOX_ERR_GROUP_MOD_SET_ROLE_OK; for (size_t i = 0; i < state0->peers->num_peers; ++i) { tox_group_mod_set_role(tox0, groupnumber, (uint32_t)state0->peers->peer_ids[i], TOX_GROUP_ROLE_MODERATOR, diff --git a/auto_tests/group_tcp_test.c b/auto_tests/group_tcp_test.c index c1f66de9283..57a9f2039ba 100644 --- a/auto_tests/group_tcp_test.c +++ b/auto_tests/group_tcp_test.c @@ -26,7 +26,7 @@ static void group_invite_handler(Tox *tox, uint32_t friend_number, const uint8_t { printf("Accepting friend invite\n"); - Tox_Err_Group_Invite_Accept err_accept; + Tox_Err_Group_Invite_Accept err_accept = TOX_ERR_GROUP_INVITE_ACCEPT_OK; tox_group_invite_accept(tox, friend_number, invite_data, length, (const uint8_t *)"test", 4, nullptr, 0, &err_accept); ck_assert(err_accept == TOX_ERR_GROUP_INVITE_ACCEPT_OK); @@ -143,14 +143,14 @@ static void group_tcp_test(AutoTox *autotoxes) tox_callback_group_message(autotoxes[1].tox, group_message_handler); tox_callback_group_invite(autotoxes[1].tox, group_invite_handler); - Tox_Err_Group_New new_err; + Tox_Err_Group_New new_err = TOX_ERR_GROUP_NEW_OK; uint32_t groupnumber = tox_group_new(autotoxes[0].tox, TOX_GROUP_PRIVACY_STATE_PUBLIC, (const uint8_t *)"test", 4, (const uint8_t *)"test", 4, &new_err); ck_assert_msg(new_err == TOX_ERR_GROUP_NEW_OK, "tox_group_new failed: %d", new_err); iterate_group(autotoxes, NUM_GROUP_TOXES, GROUP_ITERATION_INTERVAL); - Tox_Err_Group_State_Queries id_err; + Tox_Err_Group_State_Queries id_err = TOX_ERR_GROUP_STATE_QUERIES_OK; uint8_t chat_id[TOX_GROUP_CHAT_ID_SIZE]; tox_group_get_chat_id(autotoxes[0].tox, groupnumber, chat_id, &id_err); @@ -159,7 +159,7 @@ static void group_tcp_test(AutoTox *autotoxes) printf("Tox 0 created new group...\n"); for (size_t i = 1; i < NUM_GROUP_TOXES; ++i) { - Tox_Err_Group_Join jerr; + Tox_Err_Group_Join jerr = TOX_ERR_GROUP_JOIN_OK; tox_group_join(autotoxes[i].tox, chat_id, (const uint8_t *)"test", 4, nullptr, 0, &jerr); ck_assert_msg(jerr == TOX_ERR_GROUP_JOIN_OK, "%d", jerr); iterate_group(autotoxes, NUM_GROUP_TOXES, GROUP_ITERATION_INTERVAL * 10); @@ -174,7 +174,7 @@ static void group_tcp_test(AutoTox *autotoxes) for (size_t i = 0; i < NUM_GROUP_TOXES - 1; ++i) { - Tox_Err_Group_Send_Private_Message perr; + Tox_Err_Group_Send_Private_Message perr = TOX_ERR_GROUP_SEND_PRIVATE_MESSAGE_OK; tox_group_send_private_message(autotoxes[0].tox, groupnumber, state0->peer_id[i], TOX_MESSAGE_TYPE_NORMAL, (const uint8_t *)CODEWORD, CODEWORD_LEN, &perr); @@ -184,7 +184,7 @@ static void group_tcp_test(AutoTox *autotoxes) while (!all_peers_got_code(autotoxes)) ; - Tox_Err_Group_Leave err_exit; + Tox_Err_Group_Leave err_exit = TOX_ERR_GROUP_LEAVE_OK; tox_group_leave(autotoxes[1].tox, groupnumber, nullptr, 0, &err_exit); ck_assert(err_exit == TOX_ERR_GROUP_LEAVE_OK); @@ -197,7 +197,7 @@ static void group_tcp_test(AutoTox *autotoxes) printf("Tox1 leaves group and Tox0 does a friend group invite for tox1\n"); - Tox_Err_Group_Invite_Friend err_invite; + Tox_Err_Group_Invite_Friend err_invite = TOX_ERR_GROUP_INVITE_FRIEND_OK; tox_group_invite_friend(autotoxes[0].tox, groupnumber, 0, &err_invite); ck_assert(err_invite == TOX_ERR_GROUP_INVITE_FRIEND_OK); @@ -207,7 +207,7 @@ static void group_tcp_test(AutoTox *autotoxes) printf("Tox 1 successfully joined. Waiting for code...\n"); - Tox_Err_Group_Send_Message merr; + Tox_Err_Group_Send_Message merr = TOX_ERR_GROUP_SEND_MESSAGE_OK; tox_group_send_message(autotoxes[0].tox, groupnumber, TOX_MESSAGE_TYPE_NORMAL, (const uint8_t *)CODEWORD, CODEWORD_LEN, nullptr, &merr); ck_assert(merr == TOX_ERR_GROUP_SEND_MESSAGE_OK); diff --git a/auto_tests/group_topic_test.c b/auto_tests/group_topic_test.c index 26dafcb459a..2ae97c0ebc2 100644 --- a/auto_tests/group_topic_test.c +++ b/auto_tests/group_topic_test.c @@ -70,7 +70,7 @@ static void group_topic_handler(Tox *tox, uint32_t groupnumber, uint32_t peer_id { ck_assert(length <= TOX_GROUP_MAX_TOPIC_LENGTH); - Tox_Err_Group_State_Queries query_err; + Tox_Err_Group_State_Queries query_err = TOX_ERR_GROUP_STATE_QUERIES_OK; uint8_t topic2[TOX_GROUP_MAX_TOPIC_LENGTH]; tox_group_get_topic(tox, groupnumber, topic2, &query_err); ck_assert(query_err == TOX_ERR_GROUP_STATE_QUERIES_OK); @@ -83,7 +83,7 @@ static void group_topic_handler(Tox *tox, uint32_t groupnumber, uint32_t peer_id static void group_topic_lock_handler(Tox *tox, uint32_t groupnumber, Tox_Group_Topic_Lock topic_lock, void *user_data) { - Tox_Err_Group_State_Queries err; + Tox_Err_Group_State_Queries err = TOX_ERR_GROUP_STATE_QUERIES_OK; Tox_Group_Topic_Lock current_lock = tox_group_get_topic_lock(tox, groupnumber, &err); ck_assert(err == TOX_ERR_GROUP_STATE_QUERIES_OK); @@ -96,7 +96,7 @@ static void group_topic_lock_handler(Tox *tox, uint32_t groupnumber, Tox_Group_T */ static bool set_topic(Tox *tox, uint32_t groupnumber, const char *topic, size_t length) { - Tox_Err_Group_Topic_Set err; + Tox_Err_Group_Topic_Set err = TOX_ERR_GROUP_TOPIC_SET_OK; tox_group_set_topic(tox, groupnumber, (const uint8_t *)topic, length, &err); return err == TOX_ERR_GROUP_TOPIC_SET_OK; @@ -107,7 +107,7 @@ static bool set_topic(Tox *tox, uint32_t groupnumber, const char *topic, size_t */ static int check_topic(const Tox *tox, uint32_t groupnumber, const char *expected_topic, size_t expected_length) { - Tox_Err_Group_State_Queries query_err; + Tox_Err_Group_State_Queries query_err = TOX_ERR_GROUP_STATE_QUERIES_OK; size_t topic_length = tox_group_get_topic_size(tox, groupnumber, &query_err); if (query_err != TOX_ERR_GROUP_STATE_QUERIES_OK) { @@ -140,7 +140,7 @@ static void wait_topic_lock(AutoTox *autotoxes, uint32_t groupnumber, Tox_Group_ uint32_t count = 0; for (size_t i = 0; i < NUM_GROUP_TOXES; ++i) { - Tox_Err_Group_State_Queries err; + Tox_Err_Group_State_Queries err = TOX_ERR_GROUP_STATE_QUERIES_OK; Tox_Group_Topic_Lock topic_lock = tox_group_get_topic_lock(autotoxes[i].tox, groupnumber, &err); ck_assert(err == TOX_ERR_GROUP_STATE_QUERIES_OK); @@ -220,7 +220,7 @@ static void group_topic_test(AutoTox *autotoxes) } /* Tox1 creates a group and is the founder of a newly created group */ - Tox_Err_Group_New new_err; + Tox_Err_Group_New new_err = TOX_ERR_GROUP_NEW_OK; const uint32_t groupnumber = tox_group_new(tox0, TOX_GROUP_PRIVACY_STATE_PUBLIC, (const uint8_t *)GROUP_NAME, GROUP_NAME_LEN, (const uint8_t *)PEER0_NICK, PEER0_NICK_LEN, &new_err); @@ -234,7 +234,7 @@ static void group_topic_test(AutoTox *autotoxes) ck_assert_msg(s_ret, "Founder failed to set topic"); /* Founder gets the Chat ID and implicitly shares it publicly */ - Tox_Err_Group_State_Queries id_err; + Tox_Err_Group_State_Queries id_err = TOX_ERR_GROUP_STATE_QUERIES_OK; uint8_t chat_id[TOX_GROUP_CHAT_ID_SIZE]; tox_group_get_chat_id(tox0, groupnumber, chat_id, &id_err); @@ -244,7 +244,7 @@ static void group_topic_test(AutoTox *autotoxes) for (size_t i = 1; i < NUM_GROUP_TOXES; ++i) { iterate_all_wait(autotoxes, NUM_GROUP_TOXES, ITERATION_INTERVAL); - Tox_Err_Group_Join join_err; + Tox_Err_Group_Join join_err = TOX_ERR_GROUP_JOIN_OK; tox_group_join(autotoxes[i].tox, chat_id, (const uint8_t *)"Test", 4, nullptr, 0, &join_err); ck_assert_msg(join_err == TOX_ERR_GROUP_JOIN_OK, "tox_group_join failed: %d", join_err); @@ -258,7 +258,7 @@ static void group_topic_test(AutoTox *autotoxes) wait_state_topic(autotoxes, groupnumber, TOPIC, TOPIC_LEN); /* Founder disables topic lock */ - Tox_Err_Group_Founder_Set_Topic_Lock lock_set_err; + Tox_Err_Group_Founder_Set_Topic_Lock lock_set_err = TOX_ERR_GROUP_FOUNDER_SET_TOPIC_LOCK_OK; tox_group_founder_set_topic_lock(tox0, groupnumber, TOX_GROUP_TOPIC_LOCK_DISABLED, &lock_set_err); ck_assert_msg(lock_set_err == TOX_ERR_GROUP_FOUNDER_SET_TOPIC_LOCK_OK, "failed to disable topic lock: %d", lock_set_err); @@ -274,7 +274,7 @@ static void group_topic_test(AutoTox *autotoxes) ck_assert_msg(change_count == NUM_GROUP_TOXES, "%u peers changed the topic with topic lock disabled", change_count); /* founder silences the last peer he saw join */ - Tox_Err_Group_Mod_Set_Role merr; + Tox_Err_Group_Mod_Set_Role merr = TOX_ERR_GROUP_MOD_SET_ROLE_OK; tox_group_mod_set_role(tox0, groupnumber, state0->peer_id, TOX_GROUP_ROLE_OBSERVER, &merr); ck_assert_msg(merr == TOX_ERR_GROUP_MOD_SET_ROLE_OK, "Failed to set %u to observer role: %d", state0->peer_id, merr); @@ -312,7 +312,7 @@ static void group_topic_test(AutoTox *autotoxes) wait_state_topic(autotoxes, groupnumber, TOPIC2, TOPIC_LEN2); for (size_t i = 0; i < NUM_GROUP_TOXES; ++i) { - Tox_Err_Group_Leave err_exit; + Tox_Err_Group_Leave err_exit = TOX_ERR_GROUP_LEAVE_OK; tox_group_leave(autotoxes[i].tox, groupnumber, nullptr, 0, &err_exit); ck_assert_msg(err_exit == TOX_ERR_GROUP_LEAVE_OK, "%d", err_exit); } diff --git a/auto_tests/lan_discovery_test.c b/auto_tests/lan_discovery_test.c index d7bf594b2bf..0eb4543adf4 100644 --- a/auto_tests/lan_discovery_test.c +++ b/auto_tests/lan_discovery_test.c @@ -22,7 +22,7 @@ int main(void) ck_assert(tox2 != nullptr); uint64_t clock = current_time_monotonic(tox1->mono_time); - Mono_Time *mono_time; + Mono_Time *mono_time = NULL; mono_time = tox1->mono_time; mono_time_set_current_time_callback(mono_time, get_state_clock_callback, &clock); diff --git a/auto_tests/network_test.c b/auto_tests/network_test.c index df3b625a9e1..3b5621288f6 100644 --- a/auto_tests/network_test.c +++ b/auto_tests/network_test.c @@ -101,7 +101,7 @@ static void test_addr_resolv_localhost(void) static void test_ip_equal(void) { - int res; + int res = 0; IP ip1, ip2; ip_reset(&ip1); ip_reset(&ip2); diff --git a/auto_tests/onion_test.c b/auto_tests/onion_test.c index 282b99637e6..0eb81c3b5ef 100644 --- a/auto_tests/onion_test.c +++ b/auto_tests/onion_test.c @@ -290,7 +290,7 @@ static void test_basic(void) ck_assert_msg((onion1_a != nullptr) && (onion2_a != nullptr), "Onion_Announce failed initializing."); uint8_t zeroes[64] = {0}; random_bytes(rng, sb_data, sizeof(sb_data)); - uint64_t s; + uint64_t s = 0; memcpy(&s, sb_data, sizeof(uint64_t)); memcpy(test_3_pub_key, nodes[3].public_key, CRYPTO_PUBLIC_KEY_SIZE); int ret = send_announce_request(onion1->net, rng, &path, &nodes[3], @@ -574,7 +574,7 @@ static void dht_pk_callback(void *object, int32_t number, const uint8_t *dht_pub static void test_announce(void) { - uint32_t i, j; + uint32_t i = 0, j = 0; uint32_t index[NUM_ONIONS]; Onions *onions[NUM_ONIONS]; const Random *rng = system_random(); diff --git a/auto_tests/overflow_recvq_test.c b/auto_tests/overflow_recvq_test.c index 8855f70f3e8..197c4808ed1 100644 --- a/auto_tests/overflow_recvq_test.c +++ b/auto_tests/overflow_recvq_test.c @@ -30,7 +30,7 @@ static void net_crypto_overflow_test(AutoTox *autotoxes) uint8_t message[128] = {0}; snprintf((char *)message, sizeof(message), "%u-%u", tox_index, i); - Tox_Err_Friend_Send_Message err; + Tox_Err_Friend_Send_Message err = TOX_ERR_FRIEND_SEND_MESSAGE_OK; tox_friend_send_message(autotoxes[tox_index].tox, 0, TOX_MESSAGE_TYPE_NORMAL, message, sizeof message, &err); if (err == TOX_ERR_FRIEND_SEND_MESSAGE_SENDQ) { diff --git a/auto_tests/overflow_sendq_test.c b/auto_tests/overflow_sendq_test.c index fab0f008731..35009aad62f 100644 --- a/auto_tests/overflow_sendq_test.c +++ b/auto_tests/overflow_sendq_test.c @@ -13,7 +13,7 @@ static void net_crypto_overflow_test(AutoTox *autotoxes) bool errored = false; for (uint32_t i = 0; i < NUM_MSGS; i++) { - Tox_Err_Friend_Send_Message err; + Tox_Err_Friend_Send_Message err = TOX_ERR_FRIEND_SEND_MESSAGE_OK; tox_friend_send_message(autotoxes[0].tox, 0, TOX_MESSAGE_TYPE_NORMAL, message, sizeof message, &err); if (err != TOX_ERR_FRIEND_SEND_MESSAGE_OK) { diff --git a/auto_tests/proxy_test.c b/auto_tests/proxy_test.c index d6f2d8cff1c..0c027fa67ea 100644 --- a/auto_tests/proxy_test.c +++ b/auto_tests/proxy_test.c @@ -55,7 +55,7 @@ int main(int argc, char **argv) setvbuf(stdout, nullptr, _IONBF, 0); if (argc >= 3) { char *proxy_bin = argv[2]; - pthread_t proxy_thread; + pthread_t proxy_thread = 0; pthread_create(&proxy_thread, nullptr, proxy_routine, proxy_bin); c_sleep(100); } diff --git a/auto_tests/save_compatibility_test.c b/auto_tests/save_compatibility_test.c index 74d7b51a263..47ee1af84b9 100644 --- a/auto_tests/save_compatibility_test.c +++ b/auto_tests/save_compatibility_test.c @@ -82,7 +82,7 @@ static void test_save_compatibility(const char *save_path) options.savedata_type = TOX_SAVEDATA_TYPE_TOX_SAVE; size_t index = 0; - Tox_Err_New err; + Tox_Err_New err = TOX_ERR_NEW_OK; Tox *tox = tox_new_log(&options, &err, &index); ck_assert_msg(tox, "failed to create tox, error number: %d", err); diff --git a/auto_tests/save_friend_test.c b/auto_tests/save_friend_test.c index 80a6ed037e8..8823dbe8823 100644 --- a/auto_tests/save_friend_test.c +++ b/auto_tests/save_friend_test.c @@ -22,7 +22,7 @@ struct test_data { static void set_random(Tox *m, const Random *rng, bool (*setter)(Tox *, const uint8_t *, size_t, Tox_Err_Set_Info *), size_t length) { VLA(uint8_t, text, length); - uint32_t i; + uint32_t i = 0; for (i = 0; i < length; ++i) { text[i] = random_u08(rng); diff --git a/auto_tests/save_load_test.c b/auto_tests/save_load_test.c index 97077735633..cc89d90411a 100644 --- a/auto_tests/save_load_test.c +++ b/auto_tests/save_load_test.c @@ -139,7 +139,7 @@ static void test_few_clients(void) struct Tox_Options *opts1 = tox_options_new(nullptr); tox_options_set_tcp_port(opts1, TCP_RELAY_PORT); - Tox_Err_New t_n_error; + Tox_Err_New t_n_error = TOX_ERR_NEW_OK; Tox *tox1 = tox_new_log(opts1, &t_n_error, &index[0]); ck_assert_msg(t_n_error == TOX_ERR_NEW_OK, "Failed to create tox instance: %d", t_n_error); tox_options_free(opts1); diff --git a/auto_tests/send_message_test.c b/auto_tests/send_message_test.c index 52470f3331f..04b31a90286 100644 --- a/auto_tests/send_message_test.c +++ b/auto_tests/send_message_test.c @@ -44,7 +44,7 @@ static void send_message_test(AutoTox *autotoxes) uint8_t *msgs = (uint8_t *)malloc(msgs_len); memset(msgs, MESSAGE_FILLER, msgs_len); - Tox_Err_Friend_Send_Message errm; + Tox_Err_Friend_Send_Message errm = TOX_ERR_FRIEND_SEND_MESSAGE_OK; tox_friend_send_message(autotoxes[0].tox, 0, TOX_MESSAGE_TYPE_NORMAL, msgs, msgs_len, &errm); ck_assert_msg(errm == TOX_ERR_FRIEND_SEND_MESSAGE_TOO_LONG, "tox_max_message_length() is too small? error=%d", errm); diff --git a/auto_tests/set_name_test.c b/auto_tests/set_name_test.c index 9ad7946c443..9da0143c03b 100644 --- a/auto_tests/set_name_test.c +++ b/auto_tests/set_name_test.c @@ -68,7 +68,7 @@ static void test_set_name(void) printf("tox clients connected took %lu seconds\n", (unsigned long)(time(nullptr) - con_time)); tox_callback_friend_name(tox2, nickchange_callback); - Tox_Err_Set_Info err_n; + Tox_Err_Set_Info err_n = TOX_ERR_SET_INFO_OK; bool ret = tox_self_set_name(tox1, (const uint8_t *)NICKNAME, sizeof(NICKNAME), &err_n); ck_assert_msg(ret && err_n == TOX_ERR_SET_INFO_OK, "tox_self_set_name failed because %d\n", err_n); diff --git a/auto_tests/set_status_message_test.c b/auto_tests/set_status_message_test.c index 435d2239c83..4e8180601b5 100644 --- a/auto_tests/set_status_message_test.c +++ b/auto_tests/set_status_message_test.c @@ -69,7 +69,7 @@ static void test_set_status_message(void) printf("tox clients connected took %lu seconds\n", (unsigned long)(time(nullptr) - con_time)); - Tox_Err_Set_Info err_n; + Tox_Err_Set_Info err_n = TOX_ERR_SET_INFO_OK; tox_callback_friend_status_message(tox2, status_callback); bool ret = tox_self_set_status_message(tox1, (const uint8_t *)STATUS_MESSAGE, sizeof(STATUS_MESSAGE), &err_n); diff --git a/auto_tests/tox_dispatch_test.c b/auto_tests/tox_dispatch_test.c index 209e13788f2..f3414694614 100644 --- a/auto_tests/tox_dispatch_test.c +++ b/auto_tests/tox_dispatch_test.c @@ -105,7 +105,7 @@ static void test_tox_events(void) const Tox_System *sys = tox_get_system(toxes[0]); - Tox_Err_Dispatch_New err_new; + Tox_Err_Dispatch_New err_new = TOX_ERR_DISPATCH_NEW_OK; Tox_Dispatch *dispatch = tox_dispatch_new(&err_new); ck_assert_msg(dispatch != nullptr, "failed to create event dispatcher"); ck_assert(err_new == TOX_ERR_DISPATCH_NEW_OK); @@ -147,7 +147,7 @@ static void test_tox_events(void) printf("friends are connected via %s, now sending message\n", tox_friend_get_connection_status(toxes[0], 0, nullptr) == TOX_CONNECTION_TCP ? "TCP" : "UDP"); - Tox_Err_Friend_Send_Message err; + Tox_Err_Friend_Send_Message err = TOX_ERR_FRIEND_SEND_MESSAGE_OK; tox_friend_send_message(toxes[0], 0, TOX_MESSAGE_TYPE_NORMAL, message, sizeof(message), &err); ck_assert(err == TOX_ERR_FRIEND_SEND_MESSAGE_OK); diff --git a/auto_tests/tox_events_test.c b/auto_tests/tox_events_test.c index 04549b2179c..d3a0d8c0454 100644 --- a/auto_tests/tox_events_test.c +++ b/auto_tests/tox_events_test.c @@ -60,7 +60,7 @@ static void test_tox_events(void) } uint64_t clock = current_time_monotonic(toxes[0]->mono_time); - Mono_Time *mono_time; + Mono_Time *mono_time = NULL; mono_time = toxes[0]->mono_time; mono_time_set_current_time_callback(mono_time, get_state_clock_callback, &clock); @@ -104,7 +104,7 @@ static void test_tox_events(void) printf("friends are connected via %s, now sending message\n", tox_friend_get_connection_status(toxes[0], 0, nullptr) == TOX_CONNECTION_TCP ? "TCP" : "UDP"); - Tox_Err_Friend_Send_Message err; + Tox_Err_Friend_Send_Message err = TOX_ERR_FRIEND_SEND_MESSAGE_OK; tox_friend_send_message(toxes[0], 0, TOX_MESSAGE_TYPE_NORMAL, message, sizeof(message), &err); ck_assert(err == TOX_ERR_FRIEND_SEND_MESSAGE_OK); diff --git a/auto_tests/tox_many_tcp_test.c b/auto_tests/tox_many_tcp_test.c index f466e3e1711..d0cfb31fba4 100644 --- a/auto_tests/tox_many_tcp_test.c +++ b/auto_tests/tox_many_tcp_test.c @@ -46,7 +46,7 @@ static void test_many_clients_tcp(void) long long unsigned int cur_time = time(nullptr); Tox *toxes[NUM_TOXES_TCP]; uint32_t index[NUM_TOXES_TCP]; - uint32_t i, j; + uint32_t i = 0, j = 0; uint32_t to_comp = 974536; for (i = 0; i < NUM_TOXES_TCP; ++i) { @@ -59,7 +59,7 @@ static void test_many_clients_tcp(void) } index[i] = i + 1; - Tox_Err_New err; + Tox_Err_New err = TOX_ERR_NEW_OK; toxes[i] = tox_new_log(opts, &err, &index[i]); if (i == 0 && err == TOX_ERR_NEW_PORT_ALLOC) { ck_assert(toxes[i] == nullptr); @@ -101,7 +101,7 @@ static void test_many_clients_tcp(void) tox_self_get_address(toxes[pairs[i].tox1], address); - Tox_Err_Friend_Add test; + Tox_Err_Friend_Add test = TOX_ERR_FRIEND_ADD_OK; uint32_t num = tox_friend_add(toxes[pairs[i].tox2], address, (const uint8_t *)"Gentoo", 7, &test); if (test == TOX_ERR_FRIEND_ADD_ALREADY_SENT) { @@ -149,7 +149,7 @@ static void test_many_clients_tcp_b(void) long long unsigned int cur_time = time(nullptr); Tox *toxes[NUM_TOXES_TCP]; uint32_t index[NUM_TOXES_TCP]; - uint32_t i, j; + uint32_t i = 0, j = 0; uint32_t to_comp = 974536; for (i = 0; i < NUM_TOXES_TCP; ++i) { @@ -196,7 +196,7 @@ static void test_many_clients_tcp_b(void) tox_self_get_address(toxes[pairs[i].tox1], address); - Tox_Err_Friend_Add test; + Tox_Err_Friend_Add test = TOX_ERR_FRIEND_ADD_OK; uint32_t num = tox_friend_add(toxes[pairs[i].tox2], address, (const uint8_t *)"Gentoo", 7, &test); if (test == TOX_ERR_FRIEND_ADD_ALREADY_SENT) { diff --git a/auto_tests/tox_many_test.c b/auto_tests/tox_many_test.c index 8501b5c172a..96ad84504e1 100644 --- a/auto_tests/tox_many_test.c +++ b/auto_tests/tox_many_test.c @@ -67,7 +67,7 @@ static void test_many_clients(void) tox_self_get_address(toxes[pairs[i].tox1], address); - Tox_Err_Friend_Add test; + Tox_Err_Friend_Add test = TOX_ERR_FRIEND_ADD_OK; uint32_t num = tox_friend_add(toxes[pairs[i].tox2], address, (const uint8_t *)"Gentoo", 7, &test); if (test == TOX_ERR_FRIEND_ADD_ALREADY_SENT) { diff --git a/auto_tests/toxav_basic_test.c b/auto_tests/toxav_basic_test.c index cdf043232cc..6921852d663 100644 --- a/auto_tests/toxav_basic_test.c +++ b/auto_tests/toxav_basic_test.c @@ -25,7 +25,7 @@ #define ck_assert_call_control(a, b, c) do { \ - Toxav_Err_Call_Control cc_err; \ + Toxav_Err_Call_Control cc_err = TOXAV_ERR_CALL_CONTROL_OK; \ bool ok = toxav_call_control(a, b, c, &cc_err); \ if (!ok) { \ printf("toxav_call_control returned error %d\n", cc_err); \ @@ -116,7 +116,7 @@ static void regular_call_flow( clear_call_control(alice_cc); clear_call_control(bob_cc); - Toxav_Err_Call call_err; + Toxav_Err_Call call_err = TOXAV_ERR_CALL_OK; toxav_call(alice_av, 0, a_br, v_br, &call_err); ck_assert_msg(call_err == TOXAV_ERR_CALL_OK, "toxav_call failed: %d\n", call_err); @@ -125,7 +125,7 @@ static void regular_call_flow( do { if (bob_cc->incoming) { - Toxav_Err_Answer answer_err; + Toxav_Err_Answer answer_err = TOXAV_ERR_ANSWER_OK; toxav_answer(bob_av, 0, a_br, v_br, &answer_err); ck_assert_msg(answer_err == TOXAV_ERR_ANSWER_OK, "toxav_answer failed: %d\n", answer_err); @@ -134,7 +134,7 @@ static void regular_call_flow( } else { /* TODO(mannol): rtp */ if (time(nullptr) - start_time >= 1) { - Toxav_Err_Call_Control cc_err; + Toxav_Err_Call_Control cc_err = TOXAV_ERR_CALL_CONTROL_OK; toxav_call_control(alice_av, 0, TOXAV_CALL_CONTROL_CANCEL, &cc_err); ck_assert_msg(cc_err == TOXAV_ERR_CALL_CONTROL_OK, "toxav_call_control failed: %d\n", cc_err); @@ -149,14 +149,14 @@ static void regular_call_flow( static void test_av_flows(void) { - Tox *alice, *bob, *bootstrap; - ToxAV *alice_av, *bob_av; + Tox *alice = NULL, *bob = NULL, *bootstrap = NULL; + ToxAV *alice_av = NULL, *bob_av = NULL; uint32_t index[] = { 1, 2, 3 }; CallControl alice_cc, bob_cc; { - Tox_Err_New error; + Tox_Err_New error = TOX_ERR_NEW_OK; bootstrap = tox_new_log(nullptr, &error, &index[0]); ck_assert(error == TOX_ERR_NEW_OK); @@ -209,7 +209,7 @@ static void test_av_flows(void) { - Toxav_Err_New error; + Toxav_Err_New error = TOXAV_ERR_NEW_OK; alice_av = toxav_new(alice, &error); ck_assert(error == TOXAV_ERR_NEW_OK); @@ -255,7 +255,7 @@ static void test_av_flows(void) clear_call_control(&bob_cc); { - Toxav_Err_Call rc; + Toxav_Err_Call rc = TOXAV_ERR_CALL_OK; toxav_call(alice_av, 0, 48, 0, &rc); ck_assert_msg(rc == TOXAV_ERR_CALL_OK, "toxav_call failed: %d\n", rc); @@ -267,7 +267,7 @@ static void test_av_flows(void) /* Reject */ { - Toxav_Err_Call_Control rc; + Toxav_Err_Call_Control rc = TOXAV_ERR_CALL_CONTROL_OK; toxav_call_control(bob_av, 0, TOXAV_CALL_CONTROL_CANCEL, &rc); ck_assert_msg(rc == TOXAV_ERR_CALL_CONTROL_OK, "toxav_call_control failed: %d\n", rc); @@ -287,7 +287,7 @@ static void test_av_flows(void) clear_call_control(&bob_cc); { - Toxav_Err_Call rc; + Toxav_Err_Call rc = TOXAV_ERR_CALL_OK; toxav_call(alice_av, 0, 48, 0, &rc); ck_assert_msg(rc == TOXAV_ERR_CALL_OK, "toxav_call failed: %d\n", rc); @@ -299,7 +299,7 @@ static void test_av_flows(void) /* Cancel */ { - Toxav_Err_Call_Control rc; + Toxav_Err_Call_Control rc = TOXAV_ERR_CALL_CONTROL_OK; toxav_call_control(alice_av, 0, TOXAV_CALL_CONTROL_CANCEL, &rc); ck_assert_msg(rc == TOXAV_ERR_CALL_CONTROL_OK, "toxav_call_control failed: %d\n", rc); @@ -321,7 +321,7 @@ static void test_av_flows(void) /* Assume sending audio and video */ { - Toxav_Err_Call rc; + Toxav_Err_Call rc = TOXAV_ERR_CALL_OK; toxav_call(alice_av, 0, 48, 1000, &rc); ck_assert_msg(rc == TOXAV_ERR_CALL_OK, "toxav_call failed: %d\n", rc); @@ -340,7 +340,7 @@ static void test_av_flows(void) ck_assert(!toxav_call_control(alice_av, 0, TOXAV_CALL_CONTROL_SHOW_VIDEO, nullptr)); { - Toxav_Err_Answer rc; + Toxav_Err_Answer rc = TOXAV_ERR_ANSWER_OK; toxav_answer(bob_av, 0, 48, 4000, &rc); ck_assert_msg(rc == TOXAV_ERR_ANSWER_OK, "toxav_answer failed: %d\n", rc); @@ -382,7 +382,7 @@ static void test_av_flows(void) ck_assert(bob_cc.state & TOXAV_FRIEND_CALL_STATE_ACCEPTING_V); { - Toxav_Err_Call_Control rc; + Toxav_Err_Call_Control rc = TOXAV_ERR_CALL_CONTROL_OK; toxav_call_control(alice_av, 0, TOXAV_CALL_CONTROL_CANCEL, &rc); ck_assert_msg(rc == TOXAV_ERR_CALL_CONTROL_OK, "toxav_call_control failed: %d\n", rc); @@ -402,7 +402,7 @@ static void test_av_flows(void) /* Assume sending audio and video */ { - Toxav_Err_Call rc; + Toxav_Err_Call rc = TOXAV_ERR_CALL_OK; toxav_call(alice_av, 0, 48, 0, &rc); ck_assert_msg(rc == TOXAV_ERR_CALL_OK, "toxav_call failed: %d\n", rc); @@ -413,7 +413,7 @@ static void test_av_flows(void) } while (!bob_cc.incoming); { - Toxav_Err_Answer rc; + Toxav_Err_Answer rc = TOXAV_ERR_ANSWER_OK; toxav_answer(bob_av, 0, 48, 0, &rc); ck_assert_msg(rc == TOXAV_ERR_ANSWER_OK, "toxav_answer failed: %d\n", rc); @@ -441,7 +441,7 @@ static void test_av_flows(void) ck_assert(!(bob_cc.state & TOXAV_FRIEND_CALL_STATE_SENDING_A)); { - Toxav_Err_Call_Control rc; + Toxav_Err_Call_Control rc = TOXAV_ERR_CALL_CONTROL_OK; toxav_call_control(alice_av, 0, TOXAV_CALL_CONTROL_CANCEL, &rc); ck_assert_msg(rc == TOXAV_ERR_CALL_CONTROL_OK, "toxav_call_control failed: %d\n", rc); @@ -461,7 +461,7 @@ static void test_av_flows(void) /* Assume sending audio and video */ { - Toxav_Err_Call rc; + Toxav_Err_Call rc = TOXAV_ERR_CALL_OK; toxav_call(alice_av, 0, 48, 0, &rc); ck_assert_msg(rc == TOXAV_ERR_CALL_OK, "toxav_call failed: %d\n", rc); @@ -472,7 +472,7 @@ static void test_av_flows(void) } while (!bob_cc.incoming); { - Toxav_Err_Answer rc; + Toxav_Err_Answer rc = TOXAV_ERR_ANSWER_OK; toxav_answer(bob_av, 0, 48, 0, &rc); ck_assert_msg(rc == TOXAV_ERR_ANSWER_OK, "toxav_answer failed: %d\n", rc); @@ -490,7 +490,7 @@ static void test_av_flows(void) iterate_tox(bootstrap, alice, bob); { - Toxav_Err_Call_Control rc; + Toxav_Err_Call_Control rc = TOXAV_ERR_CALL_CONTROL_OK; toxav_call_control(alice_av, 0, TOXAV_CALL_CONTROL_CANCEL, &rc); ck_assert_msg(rc == TOXAV_ERR_CALL_CONTROL_OK, "toxav_call_control failed: %d\n", rc); diff --git a/auto_tests/toxav_many_test.c b/auto_tests/toxav_many_test.c index b1f2f9fa946..5a7b9e3ed92 100644 --- a/auto_tests/toxav_many_test.c +++ b/auto_tests/toxav_many_test.c @@ -80,7 +80,7 @@ static void t_accept_friend_request_cb(Tox *m, const uint8_t *public_key, const */ static ToxAV *setup_av_instance(Tox *tox, CallControl *cc) { - Toxav_Err_New error; + Toxav_Err_New error = TOXAV_ERR_NEW_OK; ToxAV *av = toxav_new(tox, &error); ck_assert(error == TOXAV_ERR_NEW_OK); @@ -160,16 +160,16 @@ static void set_current_time_callback(Tox *tox, Time_Data *time_data) static void test_av_three_calls(void) { uint32_t index[] = { 1, 2, 3, 4, 5 }; - Tox *alice, *bootstrap, *bobs[3]; - ToxAV *alice_av, *bobs_av[3]; - void *retval; + Tox *alice = NULL, *bootstrap = NULL, *bobs[3]; + ToxAV *alice_av = NULL, *bobs_av[3]; + void *retval = NULL; CallControl alice_cc[3], bobs_cc[3]; Time_Data time_data; pthread_mutex_init(&time_data.lock, nullptr); { - Tox_Err_New error; + Tox_Err_New error = TOX_ERR_NEW_OK; bootstrap = tox_new_log(nullptr, &error, &index[0]); ck_assert(error == TOX_ERR_NEW_OK); @@ -290,7 +290,7 @@ static void test_av_three_calls(void) /* Call */ for (size_t i = 0; i < 3; i++) { - Toxav_Err_Call rc; + Toxav_Err_Call rc = TOXAV_ERR_CALL_OK; toxav_call(alice_av, tds[i].friend_number, 48, 3000, &rc); if (rc != TOXAV_ERR_CALL_OK) { @@ -310,7 +310,7 @@ static void test_av_three_calls(void) for (size_t i = 0; i < 3; i++) { if (bobs_cc[i].incoming) { /* Answer */ - Toxav_Err_Answer rc; + Toxav_Err_Answer rc = TOXAV_ERR_ANSWER_OK; toxav_answer(bobs_av[i], 0, 8, 500, &rc); if (rc != TOXAV_ERR_ANSWER_OK) { @@ -328,7 +328,7 @@ static void test_av_three_calls(void) /* Hangup */ for (size_t i = 0; i < 3; i++) { - Toxav_Err_Call_Control rc; + Toxav_Err_Call_Control rc = TOXAV_ERR_CALL_CONTROL_OK; toxav_call_control(alice_av, i, TOXAV_CALL_CONTROL_CANCEL, &rc); if (rc != TOXAV_ERR_CALL_CONTROL_OK) { diff --git a/auto_tests/typing_test.c b/auto_tests/typing_test.c index 5c015987897..8aaa0219c61 100644 --- a/auto_tests/typing_test.c +++ b/auto_tests/typing_test.c @@ -43,7 +43,7 @@ static void test_typing(AutoTox *autotoxes) iterate_all_wait(autotoxes, 2, 200); } while (((State *)autotoxes[1].state)->friend_is_typing); - Tox_Err_Friend_Query err_t; + Tox_Err_Friend_Query err_t = TOX_ERR_FRIEND_QUERY_OK; ck_assert_msg(tox_friend_get_typing(autotoxes[1].tox, 0, &err_t) == 0, "tox_friend_get_typing should have returned false, but it didn't"); ck_assert_msg(err_t == TOX_ERR_FRIEND_QUERY_OK, "tox_friend_get_typing call did not return correct error"); diff --git a/other/DHT_bootstrap.c b/other/DHT_bootstrap.c index f48b3025f87..b0f146fc176 100644 --- a/other/DHT_bootstrap.c +++ b/other/DHT_bootstrap.c @@ -85,7 +85,7 @@ static void manage_keys(DHT *dht) static void print_log(void *context, Logger_Level level, const char *file, int line, const char *func, const char *message, void *userdata) { - const char *strlevel; + const char *strlevel = NULL; switch (level) { case LOGGER_LEVEL_TRACE: diff --git a/other/analysis/run-clang-tidy b/other/analysis/run-clang-tidy index c8d1a86a88c..5c2aab23ca7 100755 --- a/other/analysis/run-clang-tidy +++ b/other/analysis/run-clang-tidy @@ -29,21 +29,24 @@ CHECKS="$CHECKS,-cert-dcl51-cpp" # the toxencryptsave magic number. CHECKS="$CHECKS,-bugprone-not-null-terminated-result" +# We don't want default labels in enum switches. +CHECKS="$CHECKS,-hicpp-multiway-paths-covered" + +# This can make readability quite a bit worse when the 2 cases look very +# similar. +CHECKS="$CHECKS,-llvm-else-after-return" +CHECKS="$CHECKS,-readability-else-after-return" + +# We need 'return;' in empty functions because cimple won't allow empty +# functions otherwise. +CHECKS="$CHECKS,-readability-redundant-control-flow" + # TODO(iphydf): We might want some of these. For the ones we don't want, add a # comment explaining why not. CHECKS="$CHECKS,-clang-analyzer-optin.performance.Padding" -CHECKS="$CHECKS,-cppcoreguidelines-init-variables" -CHECKS="$CHECKS,-hicpp-multiway-paths-covered" CHECKS="$CHECKS,-hicpp-signed-bitwise" -CHECKS="$CHECKS,-llvm-else-after-return" -CHECKS="$CHECKS,-llvmlibc-restrict-system-libc-headers" -CHECKS="$CHECKS,-misc-redundant-expression" CHECKS="$CHECKS,-misc-unused-parameters" -CHECKS="$CHECKS,-readability-else-after-return" CHECKS="$CHECKS,-readability-function-cognitive-complexity" -CHECKS="$CHECKS,-readability-inconsistent-declaration-parameter-name" -CHECKS="$CHECKS,-readability-magic-numbers" -CHECKS="$CHECKS,-readability-redundant-control-flow" # TODO(iphydf): Maybe fix these? CHECKS="$CHECKS,-altera-id-dependent-backward-branch" @@ -61,13 +64,14 @@ CHECKS="$CHECKS,-clang-analyzer-valist.Uninitialized" CHECKS="$CHECKS,-concurrency-mt-unsafe" CHECKS="$CHECKS,-cppcoreguidelines-avoid-non-const-global-variables" CHECKS="$CHECKS,-cppcoreguidelines-narrowing-conversions" -CHECKS="$CHECKS,-google-readability-casting" CHECKS="$CHECKS,-misc-no-recursion" # TODO(iphydf): Probably fix these. CHECKS="$CHECKS,-cert-err33-c" CHECKS="$CHECKS,-cppcoreguidelines-avoid-magic-numbers" +CHECKS="$CHECKS,-google-readability-casting" CHECKS="$CHECKS,-modernize-macro-to-enum" +CHECKS="$CHECKS,-readability-magic-numbers" ERRORS="*" diff --git a/other/bootstrap_daemon/docker/tox-bootstrapd.sha256 b/other/bootstrap_daemon/docker/tox-bootstrapd.sha256 index 251196a3104..f13c30ca59a 100644 --- a/other/bootstrap_daemon/docker/tox-bootstrapd.sha256 +++ b/other/bootstrap_daemon/docker/tox-bootstrapd.sha256 @@ -1 +1 @@ -a8917dcace422e2a6644f140463da7b9e70e67a7e15f5209c572b72650d87368 /usr/local/bin/tox-bootstrapd +dd1d4bd8f7eeb5de6a7e6137824d337c9edf6579a24e43442e5fb417add69e07 /usr/local/bin/tox-bootstrapd diff --git a/other/bootstrap_daemon/src/command_line_arguments.c b/other/bootstrap_daemon/src/command_line_arguments.c index f7af443ead6..df38843c09e 100644 --- a/other/bootstrap_daemon/src/command_line_arguments.c +++ b/other/bootstrap_daemon/src/command_line_arguments.c @@ -72,7 +72,7 @@ void handle_command_line_arguments(int argc, char *argv[], char **cfg_file_path, *run_in_foreground = false; - int opt; + int opt = 0; while ((opt = getopt_long(argc, argv, ":", long_options, nullptr)) != -1) { diff --git a/other/bootstrap_daemon/src/config.c b/other/bootstrap_daemon/src/config.c index c9701cd05f4..3c3c3de0402 100644 --- a/other/bootstrap_daemon/src/config.c +++ b/other/bootstrap_daemon/src/config.c @@ -156,7 +156,7 @@ int get_general_config(const char *cfg_file_path, char **pid_file_path, char **k } // Get PID file location - const char *tmp_pid_file; + const char *tmp_pid_file = NULL; if (config_lookup_string(&cfg, NAME_PID_FILE_PATH, &tmp_pid_file) == CONFIG_FALSE) { log_write(LOG_LEVEL_WARNING, "No '%s' setting in configuration file.\n", NAME_PID_FILE_PATH); @@ -169,7 +169,7 @@ int get_general_config(const char *cfg_file_path, char **pid_file_path, char **k memcpy(*pid_file_path, tmp_pid_file, pid_file_path_len); // Get keys file location - const char *tmp_keys_file; + const char *tmp_keys_file = NULL; if (config_lookup_string(&cfg, NAME_KEYS_FILE_PATH, &tmp_keys_file) == CONFIG_FALSE) { log_write(LOG_LEVEL_WARNING, "No '%s' setting in configuration file.\n", NAME_KEYS_FILE_PATH); @@ -228,7 +228,7 @@ int get_general_config(const char *cfg_file_path, char **pid_file_path, char **k if (*enable_motd) { // Get MOTD - const char *tmp_motd; + const char *tmp_motd = NULL; if (config_lookup_string(&cfg, NAME_MOTD, &tmp_motd) == CONFIG_FALSE) { log_write(LOG_LEVEL_WARNING, "No '%s' setting in configuration file.\n", NAME_MOTD); @@ -297,7 +297,7 @@ static uint8_t *bootstrap_hex_string_to_bin(const char *hex_string) const char *pos = hex_string; for (size_t i = 0; i < len; ++i, pos += 2) { - unsigned int val; + unsigned int val = 0; sscanf(pos, "%02x", &val); ret[i] = val; } @@ -338,17 +338,17 @@ int bootstrap_from_config(const char *cfg_file_path, DHT *dht, int enable_ipv6) return 1; } - int bs_port; - const char *bs_address; - const char *bs_public_key; + int bs_port = 0; + const char *bs_address = NULL; + const char *bs_public_key = NULL; - config_setting_t *node; + config_setting_t *node = NULL; int i = 0; while (config_setting_length(node_list)) { - int address_resolved; - uint8_t *bs_public_key_bin; + int address_resolved = 0; + uint8_t *bs_public_key_bin = NULL; node = config_setting_get_elem(node_list, 0); diff --git a/other/bootstrap_daemon/src/tox-bootstrapd.c b/other/bootstrap_daemon/src/tox-bootstrapd.c index 2d86e9d26eb..17802d87392 100644 --- a/other/bootstrap_daemon/src/tox-bootstrapd.c +++ b/other/bootstrap_daemon/src/tox-bootstrapd.c @@ -61,7 +61,7 @@ static int manage_keys(DHT *dht, char *keys_file_path) { enum { KEYS_SIZE = CRYPTO_PUBLIC_KEY_SIZE + CRYPTO_SECRET_KEY_SIZE }; uint8_t keys[KEYS_SIZE]; - FILE *keys_file; + FILE *keys_file = NULL; // Check if file exits, proceed to open and load keys keys_file = fopen(keys_file_path, "rb"); @@ -120,7 +120,7 @@ static void print_public_key(const uint8_t *public_key) static void daemonize(LOG_BACKEND log_backend, char *pid_file_path) { // Check if the PID file exists - FILE *pid_file; + FILE *pid_file = NULL; if ((pid_file = fopen(pid_file_path, "r"))) { log_write(LOG_LEVEL_WARNING, "Another instance of the daemon is already running, PID file %s exists.\n", pid_file_path); @@ -175,38 +175,33 @@ static void daemonize(LOG_BACKEND log_backend, char *pid_file_path) // Logs toxcore logger message using our logger facility -static void toxcore_logger_callback(void *context, Logger_Level level, const char *file, int line, - const char *func, const char *message, void *userdata) +static LOG_LEVEL logger_level_to_log_level(Logger_Level level) { - LOG_LEVEL log_level; - switch (level) { case LOGGER_LEVEL_TRACE: - log_level = LOG_LEVEL_INFO; - break; + return LOG_LEVEL_INFO; case LOGGER_LEVEL_DEBUG: - log_level = LOG_LEVEL_INFO; - break; + return LOG_LEVEL_INFO; case LOGGER_LEVEL_INFO: - log_level = LOG_LEVEL_INFO; - break; + return LOG_LEVEL_INFO; case LOGGER_LEVEL_WARNING: - log_level = LOG_LEVEL_WARNING; - break; + return LOG_LEVEL_WARNING; case LOGGER_LEVEL_ERROR: - log_level = LOG_LEVEL_ERROR; - break; + return LOG_LEVEL_ERROR; default: - log_level = LOG_LEVEL_INFO; - break; + return LOG_LEVEL_INFO; } +} - log_write(log_level, "%s:%d(%s) %s\n", file, line, func, message); +static void toxcore_logger_callback(void *context, Logger_Level level, const char *file, int line, + const char *func, const char *message, void *userdata) +{ + log_write(logger_level_to_log_level(level), "%s:%d(%s) %s\n", file, line, func, message); } static volatile sig_atomic_t caught_signal = 0; @@ -220,11 +215,10 @@ int main(int argc, char *argv[]) { umask(077); char *cfg_file_path = nullptr; - LOG_BACKEND log_backend; - bool run_in_foreground; + bool run_in_foreground = 0; // choose backend for printing command line argument parsing output based on whether the daemon is being run from a terminal - log_backend = isatty(STDOUT_FILENO) ? LOG_BACKEND_STDOUT : LOG_BACKEND_SYSLOG; + LOG_BACKEND log_backend = isatty(STDOUT_FILENO) ? LOG_BACKEND_STDOUT : LOG_BACKEND_SYSLOG; log_open(log_backend); handle_command_line_arguments(argc, argv, &cfg_file_path, &log_backend, &run_in_foreground); @@ -236,14 +230,14 @@ int main(int argc, char *argv[]) char *pid_file_path = nullptr; char *keys_file_path = nullptr; - int start_port; - int enable_ipv6; - int enable_ipv4_fallback; - int enable_lan_discovery; - int enable_tcp_relay; + int start_port = 0; + int enable_ipv6 = 0; + int enable_ipv4_fallback = 0; + int enable_lan_discovery = 0; + int enable_tcp_relay = 0; uint16_t *tcp_relay_ports = nullptr; - int tcp_relay_port_count; - int enable_motd; + int tcp_relay_port_count = 0; + int enable_motd = 0; char *motd = nullptr; if (get_general_config(cfg_file_path, &pid_file_path, &keys_file_path, &start_port, &enable_ipv6, &enable_ipv4_fallback, diff --git a/other/fun/cracker.c b/other/fun/cracker.c index 7c30d1b8c23..69e3d55b844 100644 --- a/other/fun/cracker.c +++ b/other/fun/cracker.c @@ -46,12 +46,12 @@ static void print_key(const uint8_t *client_id) /// bytes needs to be at least (hex_len+1)/2 long static size_t hex_string_to_bin(const char *hex_string, size_t hex_len, uint8_t *bytes) { - size_t i; + size_t i = 0; const char *pos = hex_string; // make even for (i = 0; i < hex_len / 2; ++i, pos += 2) { - uint8_t val; + uint8_t val = 0; if (sscanf(pos, "%02hhx", &val) != 1) { return 0; @@ -61,7 +61,7 @@ static size_t hex_string_to_bin(const char *hex_string, size_t hex_len, uint8_t } if (i * 2 < hex_len) { - uint8_t val; + uint8_t val = 0; if (sscanf(pos, "%hhx", &val) != 1) { return 0; @@ -78,7 +78,7 @@ static size_t match_hex_prefix(const uint8_t *key, const uint8_t *prefix, size_t { size_t same = 0; uint8_t diff = 0; - size_t i; + size_t i = 0; for (i = 0; i < prefix_len / 2; ++i) { diff = key[i] ^ prefix[i]; @@ -133,7 +133,7 @@ static void cracker_core(uint64_t range_start, uint64_t range_end, uint64_t rang const unsigned matching = (unsigned) match_hex_prefix(pub_key, hex_prefix, prefix_chars_len); // Global compare and update - uint32_t l_longest_match; + uint32_t l_longest_match = 0; #pragma omp atomic read l_longest_match = *longest_match; diff --git a/other/fun/create_savedata.c b/other/fun/create_savedata.c index 8a30525cc75..7af0049e8d8 100644 --- a/other/fun/create_savedata.c +++ b/other/fun/create_savedata.c @@ -19,7 +19,7 @@ static bool create_tox(const unsigned char *const secret_key, Tox **const tox) { - Tox_Err_Options_New options_error; + Tox_Err_Options_New options_error = TOX_ERR_OPTIONS_NEW_OK; struct Tox_Options *const options = tox_options_new(&options_error); if (options_error != TOX_ERR_OPTIONS_NEW_OK) { @@ -29,7 +29,7 @@ static bool create_tox(const unsigned char *const secret_key, Tox **const tox) tox_options_set_savedata_type(options, TOX_SAVEDATA_TYPE_SECRET_KEY); tox_options_set_savedata_data(options, secret_key, crypto_box_SECRETKEYBYTES); - Tox_Err_New tox_error; + Tox_Err_New tox_error = TOX_ERR_NEW_OK; *tox = tox_new(options, &tox_error); if (tox_error != TOX_ERR_NEW_OK) { @@ -90,7 +90,7 @@ int main(const int argc, const char *const argv[]) print_keys(public_key, secret_key); - Tox *tox; + Tox *tox = NULL; if (!create_tox(secret_key, &tox)) { printf("Error: Failed to create a Tox instance.\n"); diff --git a/other/fun/save-generator.c b/other/fun/save-generator.c index 7e8aa344c85..2d5dac92f5f 100644 --- a/other/fun/save-generator.c +++ b/other/fun/save-generator.c @@ -41,7 +41,7 @@ static bool bootstrap_tox(Tox *tox) return false; } - Tox_Err_Bootstrap err; + Tox_Err_Bootstrap err = TOX_ERR_BOOTSTRAP_OK; tox_bootstrap(tox, BOOTSTRAP_IP, BOOTSTRAP_UDP_PORT, key, &err); free(key); @@ -116,7 +116,7 @@ int main(int argc, char *argv[]) c_sleep(tox_iteration_interval(tox)); } - Tox_Err_Set_Info err; + Tox_Err_Set_Info err = TOX_ERR_SET_INFO_OK; const uint8_t *name = (uint8_t *)argv[1]; tox_self_set_name(tox, name, strlen((const char *)name), &err); @@ -132,7 +132,7 @@ int main(int argc, char *argv[]) for (unsigned int i = 2; i < argc; i++) { //start at 2 because that is where the tox ids are uint8_t *address = hex_string_to_bin(argv[i]); - Tox_Err_Friend_Add friend_err; + Tox_Err_Friend_Add friend_err = TOX_ERR_FRIEND_ADD_OK; tox_friend_add(tox, address, (const uint8_t *)GENERATED_REQUEST_MESSAGE, strlen(GENERATED_REQUEST_MESSAGE), &friend_err); free(address); diff --git a/other/fun/sign.c b/other/fun/sign.c index f6dcc71e827..766553e2005 100644 --- a/other/fun/sign.c +++ b/other/fun/sign.c @@ -78,7 +78,7 @@ int main(int argc, char *argv[]) goto fail; } - unsigned long long smlen; + unsigned long long smlen = 0; unsigned char *sm = (unsigned char *)malloc(size + crypto_sign_ed25519_BYTES * 2); crypto_sign_ed25519(sm, &smlen, data, size, secret_key); free(data); @@ -111,7 +111,7 @@ int main(int argc, char *argv[]) if (argc == 4 && argv[1][0] == 'c') { unsigned char *public_key = hex_string_to_bin(argv[2]); - unsigned char *data; + unsigned char *data = NULL; int size = load_file(argv[3], &data); if (size < 0) { @@ -125,7 +125,7 @@ int main(int argc, char *argv[]) free(data); unsigned char *m = (unsigned char *)malloc(size); - unsigned long long mlen; + unsigned long long mlen = 0; if (crypto_sign_ed25519_open(m, &mlen, signe, size, public_key) == -1) { printf("Failed checking sig.\n"); diff --git a/other/fun/strkey.c b/other/fun/strkey.c index 0b0aa5c2b9c..782f89905d3 100644 --- a/other/fun/strkey.c +++ b/other/fun/strkey.c @@ -61,7 +61,7 @@ int main(int argc, char *argv[]) unsigned char public_key[crypto_box_PUBLICKEYBYTES]; // null terminator unsigned char secret_key[crypto_box_SECRETKEYBYTES]; long int offset = 0; - size_t len; + size_t len = 0; unsigned char desired_bin[crypto_box_PUBLICKEYBYTES]; // null terminator if (argc == 3) { @@ -89,10 +89,10 @@ int main(int argc, char *argv[]) // convert hex to bin char *pos = desired_hex; - size_t i; + size_t i = 0; for (i = 0; i < len; pos += 2) { - unsigned int value; + unsigned int value = 0; sscanf(pos, "%02x", &value); desired_bin[i] = value; ++i; diff --git a/super_donators/grencez_tok5.c b/super_donators/grencez_tok5.c index 5c5be83cd55..cf01b4f8626 100644 --- a/super_donators/grencez_tok5.c +++ b/super_donators/grencez_tok5.c @@ -8,7 +8,7 @@ #include int main(int i, char** msg) { - int j, fd[4], xpd, xid; + int j = 0, fd[4], xpd = 0, xid = 0; if (--i<1) return 1; srand(getpid()); pipe(fd); diff --git a/toxav/audio.c b/toxav/audio.c index 7792fc8575e..8e68f72c392 100644 --- a/toxav/audio.c +++ b/toxav/audio.c @@ -43,7 +43,7 @@ ACSession *ac_new(Mono_Time *mono_time, const Logger *log, ToxAV *av, uint32_t f return nullptr; } - int status; + int status = 0; ac->decoder = opus_decoder_create(AUDIO_DECODER_START_SAMPLE_RATE, AUDIO_DECODER_START_CHANNEL_COUNT, &status); if (status != OPUS_OK) { @@ -482,7 +482,7 @@ static bool reconfigure_audio_decoder(ACSession *ac, uint32_t sampling_rate, uin return false; } - int status; + int status = 0; OpusDecoder *new_dec = opus_decoder_create(sampling_rate, channels, &status); if (status != OPUS_OK) { diff --git a/toxav/bwcontroller.c b/toxav/bwcontroller.c index be2cd6b9941..cb59e7e9011 100644 --- a/toxav/bwcontroller.c +++ b/toxav/bwcontroller.c @@ -196,7 +196,7 @@ static int on_update(BWController *bwc, const struct BWCMessage *msg) */ static int bwc_send_custom_lossy_packet(Tox *tox, int32_t friendnumber, const uint8_t *data, uint32_t length) { - Tox_Err_Friend_Custom_Packet error; + Tox_Err_Friend_Custom_Packet error = TOX_ERR_FRIEND_CUSTOM_PACKET_OK; tox_friend_send_lossy_packet(tox, friendnumber, data, (size_t)length, &error); if (error == TOX_ERR_FRIEND_CUSTOM_PACKET_OK) { diff --git a/toxav/groupav.c b/toxav/groupav.c index 4e3ad2cc491..d84d356564d 100644 --- a/toxav/groupav.c +++ b/toxav/groupav.c @@ -302,7 +302,7 @@ static int decode_audio_packet(Group_AV *group_av, Group_Peer_AV *peer_av, uint3 return -1; } - int success; + int success = 0; Group_Audio_Packet *pk = dequeue(peer_av->buffer, &success); if (success == 0) { @@ -333,7 +333,7 @@ static int decode_audio_packet(Group_AV *group_av, Group_Peer_AV *peer_av, uint3 peer_av->audio_decoder = nullptr; } - int rc; + int rc = 0; peer_av->audio_decoder = opus_decoder_create(sample_rate, channels, &rc); if (rc != OPUS_OK) { diff --git a/toxav/ring_buffer.c b/toxav/ring_buffer.c index 703c2a5f7a0..bafbaee9aa9 100644 --- a/toxav/ring_buffer.c +++ b/toxav/ring_buffer.c @@ -105,7 +105,7 @@ uint16_t rb_size(const RingBuffer *b) uint16_t rb_data(const RingBuffer *b, void **dest) { - uint16_t i; + uint16_t i = 0; for (i = 0; i < rb_size(b); ++i) { dest[i] = b->data[(b->start + i) % b->size]; diff --git a/toxav/rtp.c b/toxav/rtp.c index 878a70ca448..ddbd7138d4a 100644 --- a/toxav/rtp.c +++ b/toxav/rtp.c @@ -30,7 +30,7 @@ */ static int rtp_send_custom_lossy_packet(Tox *tox, int32_t friendnumber, const uint8_t *data, uint32_t length) { - Tox_Err_Friend_Custom_Packet error; + Tox_Err_Friend_Custom_Packet error = TOX_ERR_FRIEND_CUSTOM_PACKET_OK; tox_friend_send_lossy_packet(tox, friendnumber, data, (size_t)length, &error); if (error == TOX_ERR_FRIEND_CUSTOM_PACKET_OK) { diff --git a/toxav/toxav.c b/toxav/toxav.c index bdec43b504a..d4e62b994c4 100644 --- a/toxav/toxav.c +++ b/toxav/toxav.c @@ -157,7 +157,7 @@ ToxAV *toxav_new(Tox *tox, Toxav_Err_New *error) } // TODO(iphydf): Don't rely on toxcore internals. - Messenger *m; + Messenger *m = NULL; m = tox->m; if (m->msi_packet != nullptr) { @@ -365,7 +365,7 @@ bool toxav_call(ToxAV *av, uint32_t friend_number, uint32_t audio_bit_rate, uint Toxav_Err_Call *error) { Toxav_Err_Call rc = TOXAV_ERR_CALL_OK; - ToxAVCall *call; + ToxAVCall *call = NULL; pthread_mutex_lock(av->mutex); @@ -419,7 +419,7 @@ bool toxav_answer(ToxAV *av, uint32_t friend_number, uint32_t audio_bit_rate, ui pthread_mutex_lock(av->mutex); Toxav_Err_Answer rc = TOXAV_ERR_ANSWER_OK; - ToxAVCall *call; + ToxAVCall *call = NULL; if (!m_friend_exists(av->m, friend_number)) { rc = TOXAV_ERR_ANSWER_FRIEND_NOT_FOUND; @@ -642,7 +642,7 @@ bool toxav_audio_set_bit_rate(ToxAV *av, uint32_t friend_number, uint32_t bit_ra Toxav_Err_Bit_Rate_Set *error) { Toxav_Err_Bit_Rate_Set rc = TOXAV_ERR_BIT_RATE_SET_OK; - ToxAVCall *call; + ToxAVCall *call = NULL; if (!m_friend_exists(av->m, friend_number)) { rc = TOXAV_ERR_BIT_RATE_SET_FRIEND_NOT_FOUND; @@ -714,7 +714,7 @@ bool toxav_video_set_bit_rate(ToxAV *av, uint32_t friend_number, uint32_t bit_ra Toxav_Err_Bit_Rate_Set *error) { Toxav_Err_Bit_Rate_Set rc = TOXAV_ERR_BIT_RATE_SET_OK; - ToxAVCall *call; + ToxAVCall *call = NULL; if (!m_friend_exists(av->m, friend_number)) { rc = TOXAV_ERR_BIT_RATE_SET_FRIEND_NOT_FOUND; @@ -800,7 +800,7 @@ bool toxav_audio_send_frame(ToxAV *av, uint32_t friend_number, const int16_t *pc uint8_t channels, uint32_t sampling_rate, Toxav_Err_Send_Frame *error) { Toxav_Err_Send_Frame rc = TOXAV_ERR_SEND_FRAME_OK; - ToxAVCall *call; + ToxAVCall *call = NULL; if (!m_friend_exists(av->m, friend_number)) { rc = TOXAV_ERR_SEND_FRAME_FRIEND_NOT_FOUND; @@ -925,7 +925,7 @@ bool toxav_video_send_frame(ToxAV *av, uint32_t friend_number, uint16_t width, u const uint8_t *u, const uint8_t *v, Toxav_Err_Send_Frame *error) { Toxav_Err_Send_Frame rc = TOXAV_ERR_SEND_FRAME_OK; - ToxAVCall *call; + ToxAVCall *call = NULL; int vpx_encode_flags = 0; diff --git a/toxav/video.c b/toxav/video.c index cf5c3867445..e1419b199aa 100644 --- a/toxav/video.c +++ b/toxav/video.c @@ -147,7 +147,7 @@ VCSession *vc_new(Mono_Time *mono_time, const Logger *log, ToxAV *av, uint32_t f toxav_video_receive_frame_cb *cb, void *cb_data) { VCSession *vc = (VCSession *)calloc(1, sizeof(VCSession)); - vpx_codec_err_t rc; + vpx_codec_err_t rc = VPX_CODEC_OK; if (vc == nullptr) { LOGGER_WARNING(log, "Allocation failed! Application might misbehave!"); @@ -275,7 +275,7 @@ void vc_kill(VCSession *vc) vpx_codec_destroy(vc->encoder); vpx_codec_destroy(vc->decoder); - void *p; + void *p = NULL; while (rb_read(vc->vbuf_raw, &p)) { free(p); @@ -295,7 +295,7 @@ void vc_iterate(VCSession *vc) pthread_mutex_lock(vc->queue_mutex); - struct RTPMessage *p; + struct RTPMessage *p = NULL; if (!rb_read(vc->vbuf_raw, (void **)&p)) { LOGGER_TRACE(vc->log, "no Video frame data available"); @@ -307,7 +307,7 @@ void vc_iterate(VCSession *vc) pthread_mutex_unlock(vc->queue_mutex); const struct RTPHeader *const header = &p->header; - uint32_t full_data_len; + uint32_t full_data_len = 0; if ((header->flags & RTP_LARGE_FRAME) != 0) { full_data_len = header->data_length_full; diff --git a/toxcore/DHT.c b/toxcore/DHT.c index ca96dbe37da..d717ff5ace3 100644 --- a/toxcore/DHT.c +++ b/toxcore/DHT.c @@ -233,7 +233,7 @@ int id_closest(const uint8_t *pk, const uint8_t *pk1, const uint8_t *pk2) /** Return index of first unequal bit number between public keys pk1 and pk2. */ unsigned int bit_by_bit_cmp(const uint8_t *pk1, const uint8_t *pk2) { - unsigned int i; + unsigned int i = 0; unsigned int j = 0; for (i = 0; i < CRYPTO_PUBLIC_KEY_SIZE; ++i) { @@ -366,8 +366,8 @@ int pack_ip_port(const Logger *logger, uint8_t *data, uint16_t length, const IP_ return -1; } - bool is_ipv4; - uint8_t family; + bool is_ipv4 = 0; + uint8_t family = 0; if (net_family_is_ipv4(ip_port->ip.family)) { // TODO(irungentoo): use functions to convert endianness @@ -457,7 +457,7 @@ int unpack_ip_port(IP_Port *ip_port, const uint8_t *data, uint16_t length, bool return -1; } - bool is_ipv4; + bool is_ipv4 = 0; Family host_family; if (data[0] == TOX_AF_INET) { @@ -646,8 +646,8 @@ non_null() static void update_client(const Logger *log, const Mono_Time *mono_time, int index, Client_data *client, const IP_Port *ip_port) { - IPPTsPng *assoc; - int ip_version; + IPPTsPng *assoc = NULL; + int ip_version = 0; if (net_family_is_ipv4(ip_port->ip.family)) { assoc = &client->assoc4; @@ -708,8 +708,8 @@ static bool client_or_ip_port_in_list(const Logger *log, const Mono_Time *mono_t return false; } - IPPTsPng *assoc; - int ip_version; + IPPTsPng *assoc = NULL; + int ip_version = 0; if (net_family_is_ipv4(ip_port->ip.family)) { assoc = &list[index].assoc4; @@ -776,7 +776,7 @@ static void get_close_nodes_inner(uint64_t cur_time, const uint8_t *public_key, continue; } - const IPPTsPng *ipptp; + const IPPTsPng *ipptp = NULL; if (net_family_is_ipv4(sa_family)) { ipptp = &client->assoc4; @@ -974,7 +974,7 @@ static int handle_data_search_response(void *object, const IP_Port *source, return 1; } - uint64_t ping_id; + uint64_t ping_id = 0; memcpy(&ping_id, plain + (plain_len - sizeof(uint64_t)), sizeof(ping_id)); uint8_t ping_data[CRYPTO_PUBLIC_KEY_SIZE]; @@ -1319,7 +1319,7 @@ static bool update_client_data(const Mono_Time *mono_time, Client_data *array, s } Client_data *const data = &array[index]; - IPPTsPng *assoc; + IPPTsPng *assoc = NULL; if (net_family_is_ipv4(ip_port->ip.family)) { assoc = &data->assoc4; @@ -1549,7 +1549,7 @@ static bool handle_sendnodes_core(void *object, const IP_Port *source, const uin return false; } - uint64_t ping_id; + uint64_t ping_id = 0; memcpy(&ping_id, plain + 1 + data_size, sizeof(ping_id)); if (!sent_getnode_to_node(dht, packet + 1, source, ping_id)) { @@ -1585,7 +1585,7 @@ static int handle_sendnodes_ipv6(void *object, const IP_Port *source, const uint { DHT *const dht = (DHT *)object; Node_format plain_nodes[MAX_SENT_NODES]; - uint32_t num_nodes; + uint32_t num_nodes = 0; if (!handle_sendnodes_core(object, source, packet, length, plain_nodes, MAX_SENT_NODES, &num_nodes)) { return 1; @@ -1617,7 +1617,7 @@ static uint32_t dht_friend_lock(DHT_Friend *const dht_friend, dht_ip_cb *ip_call void *data, int32_t number) { // find first free slot - uint8_t lock_num; + uint8_t lock_num = 0; uint32_t lock_token = 0; for (lock_num = 0; lock_num < DHT_FRIEND_MAX_LOCKS; ++lock_num) { lock_token = UINT32_C(1) << lock_num; @@ -1648,7 +1648,7 @@ static void dht_friend_unlock(DHT_Friend *const dht_friend, uint32_t lock_token) assert((lock_token & dht_friend->lock_flags) > 0); // find used slot - uint8_t lock_num; + uint8_t lock_num = 0; for (lock_num = 0; lock_num < DHT_FRIEND_MAX_LOCKS; ++lock_num) { if (((UINT32_C(1) << lock_num) & lock_token) > 0) { break; @@ -2252,7 +2252,7 @@ static int handle_nat_ping(void *object, const IP_Port *source, const uint8_t *s } DHT *const dht = (DHT *)object; - uint64_t ping_id; + uint64_t ping_id = 0; memcpy(&ping_id, packet + 1, sizeof(uint64_t)); const uint32_t friendnumber = index_of_friend_pk(dht->friends_list, dht->num_friends, source_pubkey); @@ -2347,7 +2347,7 @@ static void punch_holes(DHT *dht, const IP *ip, const uint16_t *port_list, uint1 } const uint16_t first_port = port_list[0]; - uint16_t port_candidate; + uint16_t port_candidate = 0; for (port_candidate = 0; port_candidate < numports; ++port_candidate) { if (first_port != port_list[port_candidate]) { @@ -2361,7 +2361,7 @@ static void punch_holes(DHT *dht, const IP *ip, const uint16_t *port_list, uint1 pinging.port = net_htons(first_port); ping_send_request(dht->ping, &pinging, dht->friends_list[friend_num].public_key); } else { - uint16_t i; + uint16_t i = 0; for (i = 0; i < MAX_PUNCHING_PORTS; ++i) { /* TODO(irungentoo): Improve port guessing algorithm. */ const uint32_t it = i + dht->friends_list[friend_num].nat.punching_index; @@ -2382,7 +2382,7 @@ static void punch_holes(DHT *dht, const IP *ip, const uint16_t *port_list, uint1 IP_Port pinging; ip_copy(&pinging.ip, ip); - uint16_t i; + uint16_t i = 0; for (i = 0; i < MAX_PUNCHING_PORTS; ++i) { uint32_t it = i + dht->friends_list[friend_num].nat.punching_index2; const uint16_t port = 1024; @@ -2553,7 +2553,7 @@ static int cryptopacket_handle(void *object, const IP_Port *source, const uint8_ if (pk_equal(packet + 1, dht->self_public_key)) { uint8_t public_key[CRYPTO_PUBLIC_KEY_SIZE]; uint8_t data[MAX_CRYPTO_REQUEST_SIZE]; - uint8_t number; + uint8_t number = 0; const int len = handle_request(dht->self_public_key, dht->self_secret_key, public_key, data, &number, packet, length); @@ -2675,7 +2675,7 @@ DHT *new_dht(const Logger *log, const Memory *mem, const Random *rng, const Netw crypto_new_keypair(rng, random_public_key_bytes, random_secret_key_bytes); - uint32_t token; // We don't intend to delete these ever, but need to pass the token + uint32_t token = 0; // We don't intend to delete these ever, but need to pass the token if (dht_addfriend(dht, random_public_key_bytes, nullptr, nullptr, 0, &token) != 0) { kill_dht(dht); return nullptr; @@ -2914,7 +2914,7 @@ int dht_load(DHT *dht, const uint8_t *data, uint32_t length) const uint32_t cookie_len = sizeof(uint32_t); if (length > cookie_len) { - uint32_t data32; + uint32_t data32 = 0; lendian_bytes_to_host32(&data32, data); if (data32 == DHT_STATE_COOKIE_GLOBAL) { diff --git a/toxcore/Messenger.c b/toxcore/Messenger.c index fc28e0c069b..b9cb64bf207 100644 --- a/toxcore/Messenger.c +++ b/toxcore/Messenger.c @@ -241,7 +241,7 @@ int32_t m_addfriend(Messenger *m, const uint8_t *address, const uint8_t *data, u return FAERR_BADCHECKSUM; } - uint16_t check; + uint16_t check = 0; const uint16_t checksum = data_checksum(address, FRIEND_ADDRESS_SIZE - sizeof(checksum)); memcpy(&check, address + CRYPTO_PUBLIC_KEY_SIZE + sizeof(uint32_t), sizeof(check)); @@ -264,7 +264,7 @@ int32_t m_addfriend(Messenger *m, const uint8_t *address, const uint8_t *data, u return FAERR_ALREADYSENT; } - uint32_t nospam; + uint32_t nospam = 0; memcpy(&nospam, address + CRYPTO_PUBLIC_KEY_SIZE, sizeof(nospam)); if (m->friendlist[friend_id].friendrequest_nospam == nospam) { @@ -471,7 +471,7 @@ int m_delfriend(Messenger *m, int32_t friendnumber) kill_friend_connection(m->fr_c, m->friendlist[friendnumber].friendcon_id); m->friendlist[friendnumber] = empty_friend; - uint32_t i; + uint32_t i = 0; for (i = m->numfriends; i != 0; --i) { if (m->friendlist[i - 1].status != NOFRIEND) { @@ -1129,9 +1129,9 @@ int file_get_id(const Messenger *m, int32_t friendnumber, uint32_t filenumber, u return -2; } - uint32_t temp_filenum; - bool inbound; - uint8_t file_number; + uint32_t temp_filenum = 0; + bool inbound = 0; + uint8_t file_number = 0; if (filenumber >= (1 << 16)) { inbound = true; @@ -1211,7 +1211,7 @@ long int new_filesender(const Messenger *m, int32_t friendnumber, uint32_t file_ return -2; } - uint32_t i; + uint32_t i = 0; for (i = 0; i < MAX_CONCURRENT_FILE_PIPES; ++i) { if (m->friendlist[friendnumber].file_sending[i].status == FILESTATUS_NONE) { @@ -1289,9 +1289,9 @@ int file_control(const Messenger *m, int32_t friendnumber, uint32_t filenumber, return -2; } - uint32_t temp_filenum; - bool inbound; - uint8_t file_number; + uint32_t temp_filenum = 0; + bool inbound = 0; + uint8_t file_number = 0; if (filenumber >= (1 << 16)) { inbound = true; @@ -1307,7 +1307,7 @@ int file_control(const Messenger *m, int32_t friendnumber, uint32_t filenumber, file_number = temp_filenum; - struct File_Transfers *ft; + struct File_Transfers *ft = NULL; if (inbound) { ft = &m->friendlist[friendnumber].file_receiving[file_number]; @@ -1684,7 +1684,7 @@ non_null() static struct File_Transfers *get_file_transfer(bool outbound, uint8_t filenumber, uint32_t *real_filenumber, Friend *sender) { - struct File_Transfers *ft; + struct File_Transfers *ft = NULL; if (outbound) { *real_filenumber = filenumber; @@ -1708,7 +1708,7 @@ non_null(1, 6) nullable(8) static int handle_filecontrol(Messenger *m, int32_t friendnumber, bool outbound, uint8_t filenumber, uint8_t control_type, const uint8_t *data, uint16_t length, void *userdata) { - uint32_t real_filenumber; + uint32_t real_filenumber = 0; struct File_Transfers *ft = get_file_transfer(outbound, filenumber, &real_filenumber, &m->friendlist[friendnumber]); if (ft == nullptr) { @@ -1771,7 +1771,7 @@ static int handle_filecontrol(Messenger *m, int32_t friendnumber, bool outbound, } case FILECONTROL_SEEK: { - uint64_t position; + uint64_t position = 0; if (length != sizeof(position)) { LOGGER_DEBUG(m->log, "file control (friend %d, file %d): expected payload of length %d, but got %d", @@ -2169,8 +2169,8 @@ static int m_handle_packet_file_sendrequest(Messenger *m, const int i, const uin #endif - uint64_t filesize; - uint32_t file_type; + uint64_t filesize = 0; + uint32_t file_type = 0; const uint16_t filename_length = data_length - head_length; if (filename_length > MAX_FILENAME_LENGTH) { @@ -2274,7 +2274,7 @@ static int m_handle_packet_file_data(Messenger *m, const int i, const uint8_t *d real_filenumber += 1; real_filenumber <<= 16; uint16_t file_data_length = data_length - 1; - const uint8_t *file_data; + const uint8_t *file_data = NULL; if (file_data_length == 0) { file_data = nullptr; @@ -2656,7 +2656,7 @@ void do_messenger(Messenger *m, void *userdata) if (mono_time_get(m->mono_time) > m->lastdump + DUMPING_CLIENTS_FRIENDS_EVERY_N_SECONDS) { m->lastdump = mono_time_get(m->mono_time); - uint32_t last_pinged; + uint32_t last_pinged = 0; for (uint32_t client = 0; client < LCLIENT_LIST; ++client) { const Client_data *cptr = dht_get_close_client(m->dht, client); @@ -2982,7 +2982,7 @@ static State_Load_Status load_nospam_keys(Messenger *m, const uint8_t *data, uin return STATE_LOAD_STATUS_ERROR; } - uint32_t nospam; + uint32_t nospam = 0; lendian_bytes_to_host32(&nospam, data); set_nospam(m->fr, nospam); load_secret_key(m->net_crypto, data + sizeof(uint32_t) + CRYPTO_PUBLIC_KEY_SIZE); @@ -3205,7 +3205,7 @@ static State_Load_Status groups_load(Messenger *m, const uint8_t *data, uint32_t return STATE_LOAD_STATUS_ERROR; } - uint32_t num_groups; + uint32_t num_groups = 0; if (!bin_unpack_array(bu, &num_groups)) { LOGGER_ERROR(m->log, "msgpack failed to unpack groupchats array: expected array"); bin_unpack_free(bu); diff --git a/toxcore/TCP_client.c b/toxcore/TCP_client.c index aeb722f660e..847dfb8eaaf 100644 --- a/toxcore/TCP_client.c +++ b/toxcore/TCP_client.c @@ -755,7 +755,7 @@ static int handle_tcp_client_ping(const Logger *logger, TCP_Client_Connection *c return -1; } - uint64_t ping_id; + uint64_t ping_id = 0; memcpy(&ping_id, data + 1, sizeof(uint64_t)); conn->ping_response_id = ping_id; tcp_send_ping_response(logger, conn); @@ -769,7 +769,7 @@ static int handle_tcp_client_pong(TCP_Client_Connection *conn, const uint8_t *da return -1; } - uint64_t ping_id; + uint64_t ping_id = 0; memcpy(&ping_id, data + 1, sizeof(uint64_t)); if (ping_id != 0) { diff --git a/toxcore/TCP_common.c b/toxcore/TCP_common.c index 5d0019486c0..3959afef466 100644 --- a/toxcore/TCP_common.c +++ b/toxcore/TCP_common.c @@ -236,7 +236,7 @@ static uint16_t read_tcp_length(const Logger *logger, const Memory *mem, const N return 0; } - uint16_t length; + uint16_t length = 0; net_unpack_u16(length_buf, &length); if (length > MAX_PACKET_SIZE) { diff --git a/toxcore/TCP_connection.c b/toxcore/TCP_connection.c index f274376c1cd..92f72c6873a 100644 --- a/toxcore/TCP_connection.c +++ b/toxcore/TCP_connection.c @@ -211,7 +211,7 @@ static int wipe_connection(TCP_Connections *tcp_c, int connections_number) return -1; } - uint32_t i; + uint32_t i = 0; tcp_c->connections[connections_number] = empty_tcp_connection_to; for (i = tcp_c->connections_length; i != 0; --i) { @@ -244,7 +244,7 @@ static int wipe_tcp_connection(TCP_Connections *tcp_c, int tcp_connections_numbe tcp_c->tcp_connections[tcp_connections_number] = empty_tcp_con; - uint32_t i; + uint32_t i = 0; for (i = tcp_c->tcp_connections_length; i != 0; --i) { if (tcp_c->tcp_connections[i - 1].status != TCP_CONN_NONE) { diff --git a/toxcore/TCP_server.c b/toxcore/TCP_server.c index 905d2bb4341..1881709d332 100644 --- a/toxcore/TCP_server.c +++ b/toxcore/TCP_server.c @@ -601,7 +601,7 @@ non_null() static int handle_onion_recv_1(void *object, const IP_Port *dest, const uint8_t *data, uint16_t length) { TCP_Server *tcp_server = (TCP_Server *)object; - uint32_t index; + uint32_t index = 0; if (!ip_port_to_con_id(tcp_server, dest, &index)) { return 1; @@ -634,8 +634,8 @@ static bool handle_forward_reply_tcp(void *object, const uint8_t *sendback_data, return false; } - uint32_t con_id; - uint64_t identifier; + uint32_t con_id = 0; + uint64_t identifier = 0; net_unpack_u32(sendback_data + 1, &con_id); net_unpack_u64(sendback_data + 1 + sizeof(uint32_t), &identifier); @@ -718,7 +718,7 @@ static int handle_tcp_packet(TCP_Server *tcp_server, uint32_t con_id, const uint LOGGER_TRACE(tcp_server->logger, "handling pong for %d", con_id); - uint64_t ping_id; + uint64_t ping_id = 0; memcpy(&ping_id, data + 1, sizeof(uint64_t)); if (ping_id != 0) { diff --git a/toxcore/announce.c b/toxcore/announce.c index fbbb2350c60..9d91b0a2a2a 100644 --- a/toxcore/announce.c +++ b/toxcore/announce.c @@ -452,7 +452,7 @@ static int create_reply_plain_store_announce_request(Announcements *announce, } const uint8_t *const auth = plain; - uint32_t requested_timeout; + uint32_t requested_timeout = 0; net_unpack_u32(plain + TIMED_AUTH_SIZE, &requested_timeout); const uint32_t timeout = calculate_timeout(announce, requested_timeout); const uint8_t announcement_type = plain[TIMED_AUTH_SIZE + sizeof(uint32_t)]; diff --git a/toxcore/bin_unpack.c b/toxcore/bin_unpack.c index ff591ca87ad..659bbb43464 100644 --- a/toxcore/bin_unpack.c +++ b/toxcore/bin_unpack.c @@ -75,7 +75,7 @@ bool bin_unpack_array(Bin_Unpack *bu, uint32_t *size) bool bin_unpack_array_fixed(Bin_Unpack *bu, uint32_t required_size) { - uint32_t size; + uint32_t size = 0; return cmp_read_array(&bu->ctx, &size) && size == required_size; } @@ -111,7 +111,7 @@ bool bin_unpack_nil(Bin_Unpack *bu) bool bin_unpack_bin(Bin_Unpack *bu, uint8_t **data_ptr, uint32_t *data_length_ptr) { - uint32_t bin_size; + uint32_t bin_size = 0; if (!bin_unpack_bin_size(bu, &bin_size) || bin_size > bu->bytes_size) { // There aren't as many bytes as this bin claims to want to allocate. return false; @@ -130,7 +130,7 @@ bool bin_unpack_bin(Bin_Unpack *bu, uint8_t **data_ptr, uint32_t *data_length_pt bool bin_unpack_bin_fixed(Bin_Unpack *bu, uint8_t *data, uint32_t data_length) { - uint32_t bin_size; + uint32_t bin_size = 0; if (!bin_unpack_bin_size(bu, &bin_size) || bin_size != data_length) { return false; } diff --git a/toxcore/crypto_core.c b/toxcore/crypto_core.c index 14025252c41..b04966f7d17 100644 --- a/toxcore/crypto_core.c +++ b/toxcore/crypto_core.c @@ -217,28 +217,28 @@ bool crypto_sha256_eq(const uint8_t *cksum1, const uint8_t *cksum2) uint8_t random_u08(const Random *rng) { - uint8_t randnum; + uint8_t randnum = 0; random_bytes(rng, &randnum, 1); return randnum; } uint16_t random_u16(const Random *rng) { - uint16_t randnum; + uint16_t randnum = 0; random_bytes(rng, (uint8_t *)&randnum, sizeof(randnum)); return randnum; } uint32_t random_u32(const Random *rng) { - uint32_t randnum; + uint32_t randnum = 0; random_bytes(rng, (uint8_t *)&randnum, sizeof(randnum)); return randnum; } uint64_t random_u64(const Random *rng) { - uint64_t randnum; + uint64_t randnum = 0; random_bytes(rng, (uint8_t *)&randnum, sizeof(randnum)); return randnum; } diff --git a/toxcore/friend_connection.c b/toxcore/friend_connection.c index 49fed514657..c796df5ef98 100644 --- a/toxcore/friend_connection.c +++ b/toxcore/friend_connection.c @@ -172,7 +172,7 @@ static int wipe_friend_conn(Friend_Connections *fr_c, int friendcon_id) fr_c->conns[friendcon_id] = empty_friend_conn; - uint32_t i; + uint32_t i = 0; for (i = fr_c->num_cons; i != 0; --i) { if (fr_c->conns[i - 1].status != FRIENDCONN_STATUS_NONE) { diff --git a/toxcore/group.c b/toxcore/group.c index 0e851b1e348..70c4d230127 100644 --- a/toxcore/group.c +++ b/toxcore/group.c @@ -312,7 +312,7 @@ static bool wipe_group_chat(Group_Chats *g_c, uint32_t groupnumber) wipe_group_c(&g_c->chats[groupnumber]); - uint16_t i; + uint16_t i = 0; for (i = g_c->num_chats; i != 0; --i) { if (g_c->chats[i - 1].status != GROUPCHAT_STATUS_NONE) { @@ -1791,7 +1791,7 @@ static bool send_invite_response(Group_Chats *g_c, int groupnumber, uint32_t fri memcpy(g->id, data + sizeof(uint16_t) + 1, GROUP_ID_LENGTH); } - uint16_t other_groupnum; + uint16_t other_groupnum = 0; net_unpack_u16(data, &other_groupnum); const int friendcon_id = getfriendcon_id(g_c->m, friendnumber); @@ -2151,8 +2151,8 @@ static void handle_friend_invite_packet(Messenger *m, uint32_t friendnumber, con return; } - uint16_t other_groupnum; - uint16_t groupnum; + uint16_t other_groupnum = 0; + uint16_t groupnum = 0; net_unpack_u16(data + 1, &other_groupnum); net_unpack_u16(data + 1 + sizeof(uint16_t), &groupnum); @@ -2170,7 +2170,7 @@ static void handle_friend_invite_packet(Messenger *m, uint32_t friendnumber, con return; } - uint16_t peer_number; + uint16_t peer_number = 0; if (member) { net_unpack_u16(data + 1 + sizeof(uint16_t) * 2 + 1 + GROUP_ID_LENGTH, &peer_number); @@ -2293,7 +2293,7 @@ static int handle_packet_online(const Group_Chats *g_c, int friendcon_id, const return -1; } - uint16_t other_groupnum; + uint16_t other_groupnum = 0; memcpy(&other_groupnum, data, sizeof(uint16_t)); other_groupnum = net_ntohs(other_groupnum); @@ -2360,7 +2360,7 @@ static int handle_packet_rejoin(Group_Chats *g_c, int friendcon_id, const uint8_ uint8_t temp_pk[CRYPTO_PUBLIC_KEY_SIZE]; get_friendcon_public_keys(real_pk, temp_pk, g_c->fr_c, friendcon_id); - uint16_t peer_number; + uint16_t peer_number = 0; if (!get_peer_number(g, real_pk, &peer_number)) { return -1; @@ -2475,7 +2475,7 @@ static int handle_send_peers(Group_Chats *g_c, uint32_t groupnumber, const uint8 const uint8_t *d = data; while ((unsigned int)(length - (d - data)) >= sizeof(uint16_t) + CRYPTO_PUBLIC_KEY_SIZE * 2 + 1) { - uint16_t peer_num; + uint16_t peer_num = 0; memcpy(&peer_num, d, sizeof(peer_num)); peer_num = net_ntohs(peer_num); d += sizeof(uint16_t); @@ -2779,7 +2779,7 @@ static Message_Info *find_message_slot_or_reject(uint32_t message_number, uint8_ { const bool ignore_older = message_id == GROUP_MESSAGE_NAME_ID || message_id == GROUP_MESSAGE_TITLE_ID; - Message_Info *i; + Message_Info *i = NULL; for (i = peer->last_message_infos; i < peer->last_message_infos + peer->num_last_message_infos; ++i) { if (message_number - (i->message_number + 1) <= ((uint32_t)1 << 31)) { @@ -2842,11 +2842,11 @@ static void handle_message_packet_group(Group_Chats *g_c, uint32_t groupnumber, return; } - uint16_t peer_number; + uint16_t peer_number = 0; memcpy(&peer_number, data, sizeof(uint16_t)); peer_number = net_ntohs(peer_number); - uint32_t message_number; + uint32_t message_number = 0; memcpy(&message_number, data + sizeof(uint16_t), sizeof(message_number)); message_number = net_ntohl(message_number); @@ -2912,7 +2912,7 @@ static void handle_message_packet_group(Group_Chats *g_c, uint32_t groupnumber, return; } - uint16_t new_peer_number; + uint16_t new_peer_number = 0; memcpy(&new_peer_number, msg_data, sizeof(uint16_t)); new_peer_number = net_ntohs(new_peer_number); addpeer(g_c, groupnumber, msg_data + sizeof(uint16_t), msg_data + sizeof(uint16_t) + CRYPTO_PUBLIC_KEY_SIZE, @@ -2926,7 +2926,7 @@ static void handle_message_packet_group(Group_Chats *g_c, uint32_t groupnumber, return; } - uint16_t kill_peer_number; + uint16_t kill_peer_number = 0; memcpy(&kill_peer_number, msg_data, sizeof(uint16_t)); kill_peer_number = net_ntohs(kill_peer_number); @@ -3022,7 +3022,7 @@ static int g_handle_packet(void *object, int friendcon_id, const uint8_t *data, return handle_packet_rejoin(g_c, friendcon_id, data + 1, length - 1, userdata); } - uint16_t groupnumber; + uint16_t groupnumber = 0; memcpy(&groupnumber, data + 1, sizeof(uint16_t)); groupnumber = net_ntohs(groupnumber); const Group_c *g = get_group_c(g_c, groupnumber); @@ -3125,9 +3125,9 @@ static int handle_lossy(void *object, int friendcon_id, const uint8_t *data, uin return -1; } - uint16_t groupnumber; - uint16_t peer_number; - uint16_t message_number; + uint16_t groupnumber = 0; + uint16_t peer_number = 0; + uint16_t message_number = 0; memcpy(&groupnumber, data + 1, sizeof(uint16_t)); memcpy(&peer_number, data + 1 + sizeof(uint16_t), sizeof(uint16_t)); memcpy(&message_number, data + 1 + sizeof(uint16_t) * 2, sizeof(uint16_t)); diff --git a/toxcore/group_announce.c b/toxcore/group_announce.c index 896b043dbd1..5c5027e2151 100644 --- a/toxcore/group_announce.c +++ b/toxcore/group_announce.c @@ -211,7 +211,7 @@ static int gca_unpack_announce(const Logger *log, const uint8_t *data, uint16_t offset += ip_port_length; } - uint16_t nodes_length; + uint16_t nodes_length = 0; const int nodes_count = unpack_nodes(announce->tcp_relays, announce->tcp_relays_count, &nodes_length, data + offset, length - offset, true); diff --git a/toxcore/group_chats.c b/toxcore/group_chats.c index 23eca0a909f..2ec4c0f7f1e 100644 --- a/toxcore/group_chats.c +++ b/toxcore/group_chats.c @@ -1241,7 +1241,7 @@ static uint16_t unpack_gc_shared_state(GC_SharedState *shared_state, const uint8 memcpy(shared_state->group_name, data + len_processed, MAX_GC_GROUP_NAME_SIZE); len_processed += MAX_GC_GROUP_NAME_SIZE; - uint8_t privacy_state; + uint8_t privacy_state = 0; memcpy(&privacy_state, data + len_processed, sizeof(uint8_t)); len_processed += sizeof(uint8_t); @@ -1254,7 +1254,7 @@ static uint16_t unpack_gc_shared_state(GC_SharedState *shared_state, const uint8 net_unpack_u32(data + len_processed, &shared_state->topic_lock); len_processed += sizeof(uint32_t); - uint8_t voice_state; + uint8_t voice_state = 0; memcpy(&voice_state, data + len_processed, sizeof(uint8_t)); len_processed += sizeof(uint8_t); @@ -1964,7 +1964,7 @@ static int handle_gc_sync_request(GC_Chat *chat, uint32_t peer_number, const uin return 0; } - uint16_t sync_flags; + uint16_t sync_flags = 0; net_unpack_u16(data, &sync_flags); if (chat_is_password_protected(chat)) { @@ -1972,7 +1972,7 @@ static int handle_gc_sync_request(GC_Chat *chat, uint32_t peer_number, const uin return -2; } - uint16_t password_length; + uint16_t password_length = 0; net_unpack_u16(data + sizeof(uint16_t), &password_length); const uint8_t *password = data + (sizeof(uint16_t) * 2); @@ -2196,7 +2196,7 @@ static int handle_gc_invite_request(GC_Chat *chat, uint32_t peer_number, const u int ret = -1; - uint8_t invite_error; + uint8_t invite_error = 0; if (get_gc_confirmed_numpeers(chat) >= chat->shared_state.maxpeers && !peer_is_founder(chat, peer_number)) { invite_error = GJ_GROUP_FULL; @@ -2211,7 +2211,7 @@ static int handle_gc_invite_request(GC_Chat *chat, uint32_t peer_number, const u goto FAILED_INVITE; } - uint16_t password_length; + uint16_t password_length = 0; net_unpack_u16(data, &password_length); const uint8_t *password = data + sizeof(uint16_t); @@ -2363,13 +2363,13 @@ static bool do_gc_peer_state_sync(GC_Chat *chat, GC_Connection *gconn, const uin return false; } - uint16_t peers_checksum; - uint16_t peer_count; - uint32_t sstate_version; - uint32_t screds_version; - uint16_t roles_checksum; - uint32_t topic_version; - uint16_t topic_checksum; + uint16_t peers_checksum = 0; + uint16_t peer_count = 0; + uint32_t sstate_version = 0; + uint32_t screds_version = 0; + uint16_t roles_checksum = 0; + uint32_t topic_version = 0; + uint16_t topic_checksum = 0; size_t unpacked_len = 0; @@ -2673,7 +2673,7 @@ static int handle_gc_peer_info_response(const GC_Session *c, GC_Chat *chat, uint return -5; } - uint16_t password_length; + uint16_t password_length = 0; net_unpack_u16(data, &password_length); unpacked_len += sizeof(uint16_t); @@ -2910,7 +2910,7 @@ static int handle_gc_shared_state(const GC_Session *c, GC_Chat *chat, GC_Connect return handle_gc_shared_state_error(chat, gconn); } - uint32_t version; + uint32_t version = 0; net_unpack_u32(ss_data, &version); // version is the first 4 bytes of shared state data payload if (version == 0 || version < chat->shared_state.version) { @@ -3003,7 +3003,7 @@ static int handle_gc_mod_list(const GC_Session *c, GC_Chat *chat, const uint8_t return 0; } - uint16_t num_mods; + uint16_t num_mods = 0; net_unpack_u16(data, &num_mods); const int unpack_ret = validate_unpack_mod_list(chat, data + sizeof(uint16_t), length - sizeof(uint16_t), num_mods); @@ -3080,7 +3080,7 @@ static int handle_gc_sanctions_list(const GC_Session *c, GC_Chat *chat, const ui return -2; } - uint16_t num_sanctions; + uint16_t num_sanctions = 0; net_unpack_u16(data, &num_sanctions); if (num_sanctions > MOD_MAX_NUM_SANCTIONS) { @@ -3877,7 +3877,7 @@ static int handle_gc_key_exchange(const GC_Chat *chat, GC_Connection *gconn, con return -1; } - bool is_response; + bool is_response = 0; net_unpack_bool(&data[0], &is_response); const uint8_t *sender_public_session_key = data + 1; @@ -4005,7 +4005,7 @@ non_null() static int validate_unpack_gc_set_mod(GC_Chat *chat, uint32_t peer_number, const uint8_t *data, uint16_t length, bool add_mod) { - int target_peer_number; + int target_peer_number = 0; uint8_t mod_data[MOD_LIST_ENTRY_SIZE]; if (add_mod) { @@ -4078,7 +4078,7 @@ static int handle_gc_set_mod(const GC_Session *c, GC_Chat *chat, uint32_t peer_n return 0; } - bool add_mod; + bool add_mod = 0; net_unpack_bool(&data[0], &add_mod); const int target_peer_number = validate_unpack_gc_set_mod(chat, peer_number, data, length, add_mod); @@ -4259,7 +4259,7 @@ static int handle_gc_set_observer(const GC_Session *c, GC_Chat *chat, uint32_t p return 0; } - bool add_obs; + bool add_obs = 0; net_unpack_bool(&data[0], &add_obs); const uint8_t *public_key = data + 1; @@ -4794,7 +4794,7 @@ static int handle_gc_message(const GC_Session *c, const GC_Chat *chat, const GC_ const uint8_t cb_type = (type == GM_PLAIN_MESSAGE) ? MESSAGE_NORMAL : MESSAGE_ACTION; - uint32_t pseudo_msg_id; + uint32_t pseudo_msg_id = 0; net_unpack_u32(data, &pseudo_msg_id); if (c->message != nullptr) { @@ -4932,7 +4932,7 @@ int gc_send_custom_private_packet(const GC_Chat *chat, bool lossless, uint32_t p return -4; } - bool ret; + bool ret = 0; if (lossless) { ret = send_lossless_group_packet(chat, gconn, message, length, GP_CUSTOM_PRIVATE_PACKET); @@ -5186,7 +5186,7 @@ static int handle_gc_message_ack(const GC_Chat *chat, GC_Connection *gconn, cons return -1; } - uint64_t message_id; + uint64_t message_id = 0; net_unpack_u64(data + 1, &message_id); const Group_Message_Ack_Type type = (Group_Message_Ack_Type) data[0]; @@ -5829,7 +5829,7 @@ static int handle_gc_handshake_packet(GC_Chat *chat, const uint8_t *sender_pk, c const uint8_t *real_data = data + 1; const uint16_t real_len = (uint16_t)plain_len - 1; - int peer_number; + int peer_number = 0; if (handshake_type == GH_REQUEST) { peer_number = handle_gc_handshake_request(chat, ipp, sender_pk, real_data, real_len); @@ -5866,7 +5866,7 @@ bool handle_gc_lossless_helper(const GC_Session *c, GC_Chat *chat, uint32_t peer GC_Connection *gconn = &peer->gconn; - int ret; + int ret = 0; switch (packet_type) { case GP_BROADCAST: { @@ -6042,8 +6042,8 @@ static bool handle_gc_lossless_packet(const GC_Session *c, GC_Chat *chat, const return false; } - uint8_t packet_type; - uint64_t message_id; + uint8_t packet_type = 0; + uint64_t message_id = 0; const int len = group_packet_unwrap(chat->log, gconn, data, &message_id, &packet_type, packet, length); @@ -6163,7 +6163,7 @@ static bool handle_gc_lossy_packet(const GC_Session *c, GC_Chat *chat, const uin return false; } - uint8_t packet_type; + uint8_t packet_type = 0; const int len = group_packet_unwrap(chat->log, gconn, data, nullptr, &packet_type, packet, length); @@ -8134,7 +8134,7 @@ static void group_delete(GC_Session *c, GC_Chat *chat) c->chats[chat->group_number] = empty_gc_chat; - uint32_t i; + uint32_t i = 0; for (i = c->chats_index; i > 0; --i) { if (c->chats[i - 1].connection_state != CS_NONE) { diff --git a/toxcore/net_crypto.c b/toxcore/net_crypto.c index 7fb4b3a8139..198631c2170 100644 --- a/toxcore/net_crypto.c +++ b/toxcore/net_crypto.c @@ -281,7 +281,7 @@ static int open_cookie(const Mono_Time *mono_time, uint8_t *bytes, const uint8_t return -1; } - uint64_t cookie_time; + uint64_t cookie_time = 0; memcpy(&cookie_time, contents, sizeof(cookie_time)); const uint64_t temp_time = mono_time_get(mono_time); @@ -881,7 +881,7 @@ static int clear_buffer_until(const Memory *mem, Packets_Array *array, uint32_t return -1; } - uint32_t i; + uint32_t i = 0; for (i = array->buffer_start; i != number; ++i) { const uint32_t num = i % CRYPTO_PACKET_BUFFER_SIZE; @@ -899,7 +899,7 @@ static int clear_buffer_until(const Memory *mem, Packets_Array *array, uint32_t non_null() static int clear_buffer(const Memory *mem, Packets_Array *array) { - uint32_t i; + uint32_t i = 0; for (i = array->buffer_start; i != array->buffer_end; ++i) { const uint32_t num = i % CRYPTO_PACKET_BUFFER_SIZE; @@ -1237,7 +1237,7 @@ static int64_t send_lossless_packet(Net_Crypto *c, int crypt_connection_id, cons non_null() static uint16_t get_nonce_uint16(const uint8_t *nonce) { - uint16_t num; + uint16_t num = 0; memcpy(&num, nonce + (CRYPTO_NONCE_SIZE - sizeof(uint16_t)), sizeof(uint16_t)); return net_ntohs(num); } @@ -1270,7 +1270,7 @@ static int handle_data_packet(const Net_Crypto *c, int crypt_connection_id, uint uint8_t nonce[CRYPTO_NONCE_SIZE]; memcpy(nonce, conn->recv_nonce, CRYPTO_NONCE_SIZE); const uint16_t num_cur_nonce = get_nonce_uint16(nonce); - uint16_t num; + uint16_t num = 0; net_unpack_u16(packet + 1, &num); const uint16_t diff = num - num_cur_nonce; increment_nonce_number(nonce, diff); @@ -1336,7 +1336,7 @@ static int send_requested_packets(Net_Crypto *c, int crypt_connection_id, uint32 uint32_t num_sent = 0; for (uint32_t i = 0; i < array_size; ++i) { - Packet_Data *dt; + Packet_Data *dt = NULL; const uint32_t packet_num = i + conn->send_array.buffer_start; const int ret = get_data_pointer(&conn->send_array, &dt, packet_num); @@ -1560,8 +1560,8 @@ static int handle_data_packet_core(Net_Crypto *c, int crypt_connection_id, const return -1; } - uint32_t buffer_start; - uint32_t num; + uint32_t buffer_start = 0; + uint32_t num = 0; memcpy(&buffer_start, data, sizeof(uint32_t)); memcpy(&num, data + sizeof(uint32_t), sizeof(uint32_t)); buffer_start = net_ntohl(buffer_start); @@ -1570,7 +1570,7 @@ static int handle_data_packet_core(Net_Crypto *c, int crypt_connection_id, const uint64_t rtt_calc_time = 0; if (buffer_start != conn->send_array.buffer_start) { - Packet_Data *packet_time; + Packet_Data *packet_time = NULL; if (get_data_pointer(&conn->send_array, &packet_time, conn->send_array.buffer_start) == 1) { rtt_calc_time = packet_time->sent_time; @@ -1609,7 +1609,7 @@ static int handle_data_packet_core(Net_Crypto *c, int crypt_connection_id, const } if (real_data[0] == PACKET_ID_REQUEST) { - uint64_t rtt_time; + uint64_t rtt_time = 0; if (udp) { rtt_time = conn->rtt_time; @@ -1694,7 +1694,7 @@ static int handle_packet_cookie_response(Net_Crypto *c, int crypt_connection_id, } uint8_t cookie[COOKIE_LENGTH]; - uint64_t number; + uint64_t number = 0; if (handle_cookie_response(cookie, &number, packet, length, conn->shared_key) != sizeof(cookie)) { return -1; @@ -1911,7 +1911,7 @@ static int wipe_crypto_connection(Net_Crypto *c, int crypt_connection_id) return -1; } - uint32_t i; + uint32_t i = 0; pthread_mutex_destroy(c->crypto_connections[crypt_connection_id].mutex); mem_delete(c->mem, c->crypto_connections[crypt_connection_id].mutex); @@ -1983,7 +1983,7 @@ static int crypto_connection_add_source(Net_Crypto *c, int crypt_connection_id, return 0; } - unsigned int tcp_connections_number; + unsigned int tcp_connections_number = 0; if (ip_port_to_tcp_connections_number(source, &tcp_connections_number)) { if (add_tcp_number_relay_connection(c->tcp_c, conn->connection_number_tcp, tcp_connections_number) == 0) { diff --git a/toxcore/network.c b/toxcore/network.c index 90b3d2d919a..b2760695e94 100644 --- a/toxcore/network.c +++ b/toxcore/network.c @@ -1087,7 +1087,7 @@ void networking_poll(const Networking_Core *net, void *userdata) IP_Port ip_port; uint8_t data[MAX_UDP_PACKET_SIZE]; - uint32_t length; + uint32_t length = 0; while (receivepacket(net->ns, net->mem, net->log, net->sock, &ip_port, data, &length) != -1) { if (length < 1) { @@ -1718,7 +1718,7 @@ bool addr_resolve_or_parse_ip(const Network *ns, const char *address, IP *to, IP bool net_connect(const Memory *mem, const Logger *log, Socket sock, const IP_Port *ip_port) { struct sockaddr_storage addr = {0}; - size_t addrsize; + size_t addrsize = 0; if (net_family_is_ipv4(ip_port->ip.family)) { struct sockaddr_in *addr4 = (struct sockaddr_in *)&addr; @@ -1798,7 +1798,7 @@ int32_t net_getipport(const Memory *mem, const char *node, IP_Port **res, int to #endif // It's not an IP address, so now we try doing a DNS lookup. - struct addrinfo *infos; + struct addrinfo *infos = NULL; const int ret = getaddrinfo(node, nullptr, nullptr, &infos); *res = nullptr; @@ -1981,8 +1981,8 @@ size_t net_unpack_u16(const uint8_t *bytes, uint16_t *v) size_t net_unpack_u32(const uint8_t *bytes, uint32_t *v) { const uint8_t *p = bytes; - uint16_t hi; - uint16_t lo; + uint16_t hi = 0; + uint16_t lo = 0; p += net_unpack_u16(p, &hi); p += net_unpack_u16(p, &lo); *v = ((uint32_t)hi << 16) | lo; @@ -1992,8 +1992,8 @@ size_t net_unpack_u32(const uint8_t *bytes, uint32_t *v) size_t net_unpack_u64(const uint8_t *bytes, uint64_t *v) { const uint8_t *p = bytes; - uint32_t hi; - uint32_t lo; + uint32_t hi = 0; + uint32_t lo = 0; p += net_unpack_u32(p, &hi); p += net_unpack_u32(p, &lo); *v = ((uint64_t)hi << 32) | lo; diff --git a/toxcore/onion_announce.c b/toxcore/onion_announce.c index 551e7b1fae9..417378b30aa 100644 --- a/toxcore/onion_announce.c +++ b/toxcore/onion_announce.c @@ -462,7 +462,7 @@ static int handle_announce_request_common( const uint8_t *data_public_key = plain + ONION_PING_ID_SIZE + CRYPTO_PUBLIC_KEY_SIZE; - int index; + int index = 0; if (check_timed_auth(onion_a->mono_time, PING_ID_TIMEOUT, onion_a->hmac_key, ping_id_data, ping_id_data_len, plain)) { diff --git a/toxcore/onion_client.c b/toxcore/onion_client.c index c15eb555642..8dfe948c2b4 100644 --- a/toxcore/onion_client.c +++ b/toxcore/onion_client.c @@ -489,7 +489,7 @@ static uint32_t set_path_timeouts(Onion_Client *onion_c, uint32_t num, uint32_t return -1; } - Onion_Client_Paths *onion_paths; + Onion_Client_Paths *onion_paths = NULL; if (num == 0) { onion_paths = &onion_c->onion_paths_self; @@ -539,7 +539,7 @@ static int send_onion_packet_tcp_udp(const Onion_Client *onion_c, const Onion_Pa return 0; } - unsigned int tcp_connections_number; + unsigned int tcp_connections_number = 0; if (ip_port_to_tcp_connections_number(&path->ip_port1, &tcp_connections_number)) { uint8_t packet[ONION_MAX_PACKET_SIZE]; @@ -602,7 +602,7 @@ non_null() static uint32_t check_sendback(Onion_Client *onion_c, const uint8_t *sendback, uint8_t *ret_pubkey, IP_Port *ret_ip_port, uint32_t *path_num) { - uint64_t sback; + uint64_t sback = 0; memcpy(&sback, sendback, sizeof(uint64_t)); uint8_t data[sizeof(uint32_t) + CRYPTO_PUBLIC_KEY_SIZE + sizeof(IP_Port) + sizeof(uint32_t)]; @@ -614,7 +614,7 @@ static uint32_t check_sendback(Onion_Client *onion_c, const uint8_t *sendback, u memcpy(ret_ip_port, data + sizeof(uint32_t) + CRYPTO_PUBLIC_KEY_SIZE, sizeof(IP_Port)); memcpy(path_num, data + sizeof(uint32_t) + CRYPTO_PUBLIC_KEY_SIZE + sizeof(IP_Port), sizeof(uint32_t)); - uint32_t num; + uint32_t num = 0; memcpy(&num, data, sizeof(uint32_t)); return num; } @@ -627,7 +627,7 @@ static int client_send_announce_request(Onion_Client *onion_c, uint32_t num, con return -1; } - uint64_t sendback; + uint64_t sendback = 0; Onion_Path path; if (num == 0) { @@ -651,7 +651,7 @@ static int client_send_announce_request(Onion_Client *onion_c, uint32_t num, con } uint8_t request[ONION_ANNOUNCE_REQUEST_MAX_SIZE]; - int len; + int len = 0; if (num == 0) { len = create_announce_request( @@ -768,7 +768,7 @@ static int client_add_to_list(Onion_Client *onion_c, uint32_t num, const uint8_t Onion_Node *node_list = nullptr; const uint8_t *reference_id = nullptr; - unsigned int list_length; + unsigned int list_length = 0; if (num == 0) { node_list = onion_c->clients_announce_list; @@ -867,7 +867,7 @@ static int client_ping_nodes(Onion_Client *onion_c, uint32_t num, const Node_for const Onion_Node *node_list = nullptr; const uint8_t *reference_id = nullptr; - unsigned int list_length; + unsigned int list_length = 0; Last_Pinged *last_pinged = nullptr; uint8_t *last_pinged_index = nullptr; @@ -899,7 +899,7 @@ static int client_ping_nodes(Onion_Client *onion_c, uint32_t num, const Node_for || id_closest(reference_id, node_list[0].public_key, nodes[i].public_key) == 2 || onion_node_timed_out(&node_list[1], onion_c->mono_time) || id_closest(reference_id, node_list[1].public_key, nodes[i].public_key) == 2) { - uint32_t j; + uint32_t j = 0; /* check if node is already in list. */ for (j = 0; j < list_length; ++j) { @@ -939,7 +939,7 @@ static int handle_announce_response(void *object, const IP_Port *source, const u uint8_t public_key[CRYPTO_PUBLIC_KEY_SIZE]; IP_Port ip_port; - uint32_t path_num; + uint32_t path_num = 0; const uint32_t num = check_sendback(onion_c, packet + 1, public_key, &ip_port, &path_num); if (num > onion_c->num_friends) { @@ -948,7 +948,7 @@ static int handle_announce_response(void *object, const IP_Port *source, const u uint8_t plain[1 + ONION_PING_ID_SIZE + ONION_ANNOUNCE_RESPONSE_MAX_SIZE - ONION_ANNOUNCE_RESPONSE_MIN_SIZE]; const int plain_size = 1 + ONION_PING_ID_SIZE + length - ONION_ANNOUNCE_RESPONSE_MIN_SIZE; - int len; + int len = 0; if (num == 0) { len = decrypt_data(public_key, nc_get_self_secret_key(onion_c->c), @@ -1030,7 +1030,7 @@ static int handle_announce_response_old(void *object, const IP_Port *source, con uint8_t public_key[CRYPTO_PUBLIC_KEY_SIZE]; IP_Port ip_port; - uint32_t path_num; + uint32_t path_num = 0; const uint32_t num = check_sendback(onion_c, packet + 1, public_key, &ip_port, &path_num); if (num > onion_c->num_friends) { @@ -1038,7 +1038,7 @@ static int handle_announce_response_old(void *object, const IP_Port *source, con } VLA(uint8_t, plain, 1 + ONION_PING_ID_SIZE + len_nodes); - int len; + int len = 0; if (num == 0) { len = decrypt_data(public_key, nc_get_self_secret_key(onion_c->c), @@ -1148,7 +1148,7 @@ static int handle_dhtpk_announce(void *object, const uint8_t *source_pubkey, con return 1; } - uint64_t no_replay; + uint64_t no_replay = 0; net_unpack_u64(data + 1, &no_replay); if (no_replay <= onion_c->friends_list[friend_num].last_noreplay) { @@ -1539,7 +1539,7 @@ int onion_delfriend(Onion_Client *onion_c, int friend_num) #endif crypto_memzero(&onion_c->friends_list[friend_num], sizeof(Onion_Friend)); - unsigned int i; + unsigned int i = 0; for (i = onion_c->num_friends; i != 0; --i) { if (onion_c->friends_list[i - 1].is_valid) { @@ -1730,7 +1730,7 @@ static void do_friend(Onion_Client *onion_c, uint16_t friendnum) return; } - uint32_t interval; + uint32_t interval = 0; const uint64_t tm = mono_time_get(onion_c->mono_time); const bool friend_is_new = o_friend->run_count <= ANNOUNCE_FRIEND_RUN_COUNT_BEGINNING; @@ -1930,8 +1930,8 @@ static void do_announce(Onion_Client *onion_c) // check if list needs to be re-populated if (count <= MAX_ONION_CLIENTS_ANNOUNCE / 2 || mono_time_is_timeout(onion_c->mono_time, onion_c->last_populated, ANNOUNCE_POPULATE_TIMEOUT)) { - uint16_t num_nodes; - const Node_format *path_nodes; + uint16_t num_nodes = 0; + const Node_format *path_nodes = NULL; if (onion_c->path_nodes_index == 0) { num_nodes = min_u16(onion_c->path_nodes_index_bs, MAX_PATH_NODES); diff --git a/toxcore/ping.c b/toxcore/ping.c index f8a96edfb96..832ce6b24f9 100644 --- a/toxcore/ping.c +++ b/toxcore/ping.c @@ -46,8 +46,8 @@ struct Ping { void ping_send_request(Ping *ping, const IP_Port *ipp, const uint8_t *public_key) { uint8_t pk[DHT_PING_SIZE]; - int rc; - uint64_t ping_id; + int rc = 0; + uint64_t ping_id = 0; if (pk_equal(public_key, dht_get_self_public_key(ping->dht))) { return; @@ -154,7 +154,7 @@ static int handle_ping_request(void *object, const IP_Port *source, const uint8_ return 1; } - uint64_t ping_id; + uint64_t ping_id = 0; memcpy(&ping_id, ping_plain + 1, sizeof(ping_id)); // Send response ping_send_response(ping, source, packet + 1, ping_id, shared_key); @@ -168,7 +168,7 @@ static int handle_ping_response(void *object, const IP_Port *source, const uint8 void *userdata) { DHT *dht = (DHT *)object; - int rc; + int rc = 0; if (length != DHT_PING_SIZE) { return 1; @@ -199,7 +199,7 @@ static int handle_ping_response(void *object, const IP_Port *source, const uint8 return 1; } - uint64_t ping_id; + uint64_t ping_id = 0; memcpy(&ping_id, ping_plain + 1, sizeof(ping_id)); uint8_t data[PING_DATA_SIZE]; @@ -233,7 +233,7 @@ static bool in_list(const Client_data *list, uint16_t length, const Mono_Time *m { for (unsigned int i = 0; i < length; ++i) { if (pk_equal(list[i].public_key, public_key)) { - const IPPTsPng *ipptp; + const IPPTsPng *ipptp = NULL; if (net_family_is_ipv4(ip_port->ip.family)) { ipptp = &list[i].assoc4; @@ -315,7 +315,7 @@ void ping_iterate(Ping *ping) return; } - unsigned int i; + unsigned int i = 0; for (i = 0; i < MAX_TO_PING; ++i) { if (!ip_isset(&ping->to_ping[i].ip_port.ip)) { diff --git a/toxcore/state.c b/toxcore/state.c index 701cf4426be..8e1352f4154 100644 --- a/toxcore/state.c +++ b/toxcore/state.c @@ -21,10 +21,10 @@ int state_load(const Logger *log, state_load_cb *state_load_callback, void *oute const uint32_t size_head = sizeof(uint32_t) * 2; while (length >= size_head) { - uint32_t length_sub; + uint32_t length_sub = 0; lendian_bytes_to_host32(&length_sub, data); - uint32_t cookie_type; + uint32_t cookie_type = 0; lendian_bytes_to_host32(&cookie_type, data + sizeof(uint32_t)); data += size_head; @@ -105,7 +105,7 @@ void host_to_lendian_bytes64(uint8_t *dest, uint64_t num) void lendian_bytes_to_host64(uint64_t *dest, const uint8_t *lendian) { - uint64_t d; + uint64_t d = 0; memcpy(&d, lendian, sizeof(uint64_t)); #ifdef WORDS_BIGENDIAN d = ((d << 8) & 0xFF00FF00FF00FF00) | ((d >> 8) & 0xFF00FF00FF00FF); @@ -126,7 +126,7 @@ void host_to_lendian_bytes32(uint8_t *dest, uint32_t num) void lendian_bytes_to_host32(uint32_t *dest, const uint8_t *lendian) { - uint32_t d; + uint32_t d = 0; memcpy(&d, lendian, sizeof(uint32_t)); #ifdef WORDS_BIGENDIAN d = ((d << 8) & 0xFF00FF00) | ((d >> 8) & 0xFF00FF); @@ -145,7 +145,7 @@ void host_to_lendian_bytes16(uint8_t *dest, uint16_t num) void lendian_bytes_to_host16(uint16_t *dest, const uint8_t *lendian) { - uint16_t d; + uint16_t d = 0; memcpy(&d, lendian, sizeof(uint16_t)); #ifdef WORDS_BIGENDIAN d = (d << 8) | (d >> 8); diff --git a/toxcore/tox.c b/toxcore/tox.c index d17e61b70f2..4ee5888483d 100644 --- a/toxcore/tox.c +++ b/toxcore/tox.c @@ -630,7 +630,7 @@ Tox *tox_new(const struct Tox_Options *options, Tox_Err_New *error) struct Tox_Options *default_options = nullptr; if (options == nullptr) { - Tox_Err_Options_New err; + Tox_Err_Options_New err = TOX_ERR_OPTIONS_NEW_OK; default_options = tox_options_new(&err); switch (err) { @@ -808,7 +808,7 @@ Tox *tox_new(const struct Tox_Options *options, Tox_Err_New *error) tox_lock(tox); - Messenger_Error m_error; + Messenger_Error m_error = MESSENGER_ERROR_NONE; tox->m = new_messenger(tox->mono_time, tox->sys.mem, tox->sys.rng, tox->sys.ns, &m_options, &m_error); if (tox->m == nullptr) { @@ -1014,7 +1014,7 @@ static int32_t resolve_bootstrap_node(Tox *tox, const char *host, uint16_t port, bool tox_bootstrap(Tox *tox, const char *host, uint16_t port, const uint8_t *public_key, Tox_Err_Bootstrap *error) { - IP_Port *root; + IP_Port *root = NULL; const int32_t count = resolve_bootstrap_node(tox, host, port, public_key, &root, error); if (count == -1) { @@ -1066,7 +1066,7 @@ bool tox_bootstrap(Tox *tox, const char *host, uint16_t port, const uint8_t *pub bool tox_add_tcp_relay(Tox *tox, const char *host, uint16_t port, const uint8_t *public_key, Tox_Err_Bootstrap *error) { - IP_Port *root; + IP_Port *root = NULL; const int32_t count = resolve_bootstrap_node(tox, host, port, public_key, &root, error); if (count == -1) { @@ -2642,7 +2642,7 @@ uint32_t tox_conference_by_id(const Tox *tox, const uint8_t *id, Tox_Err_Confere uint32_t tox_conference_by_uid(const Tox *tox, const uint8_t *uid, Tox_Err_Conference_By_Uid *error) { assert(tox != nullptr); - Tox_Err_Conference_By_Id id_error; + Tox_Err_Conference_By_Id id_error = TOX_ERR_CONFERENCE_BY_ID_OK; const uint32_t res = tox_conference_by_id(tox, uid, &id_error); switch (id_error) { diff --git a/toxcore/tox_events.c b/toxcore/tox_events.c index cae662e58ef..c2af7369983 100644 --- a/toxcore/tox_events.c +++ b/toxcore/tox_events.c @@ -117,7 +117,7 @@ bool tox_events_pack(const Tox_Events *events, Bin_Pack *bp) non_null() static bool tox_event_unpack(Tox_Events *events, Bin_Unpack *bu) { - uint32_t size; + uint32_t size = 0; if (!bin_unpack_array(bu, &size)) { return false; } @@ -126,7 +126,7 @@ static bool tox_event_unpack(Tox_Events *events, Bin_Unpack *bu) return false; } - uint8_t type; + uint8_t type = 0; if (!bin_unpack_u08(bu, &type)) { return false; } @@ -204,7 +204,7 @@ static bool tox_event_unpack(Tox_Events *events, Bin_Unpack *bu) bool tox_events_unpack(Tox_Events *events, Bin_Unpack *bu) { - uint32_t size; + uint32_t size = 0; if (!bin_unpack_array(bu, &size)) { return false; } diff --git a/toxcore/tox_private.c b/toxcore/tox_private.c index 72a93358a5b..82ce87cefdb 100644 --- a/toxcore/tox_private.c +++ b/toxcore/tox_private.c @@ -115,7 +115,7 @@ bool tox_dht_get_nodes(const Tox *tox, const uint8_t *public_key, const char *ip return false; } - IP_Port *root; + IP_Port *root = NULL; const int32_t count = net_getipport(tox->sys.mem, ip, &root, TOX_SOCK_DGRAM); diff --git a/toxcore/tox_unpack.c b/toxcore/tox_unpack.c index 6508399e7e8..ddbb7fa5c7c 100644 --- a/toxcore/tox_unpack.c +++ b/toxcore/tox_unpack.c @@ -11,7 +11,7 @@ bool tox_unpack_conference_type(Bin_Unpack *bu, Tox_Conference_Type *val) { - uint32_t u32; + uint32_t u32 = 0; if (!bin_unpack_u32(bu, &u32)) { return false; @@ -23,7 +23,7 @@ bool tox_unpack_conference_type(Bin_Unpack *bu, Tox_Conference_Type *val) bool tox_unpack_connection(Bin_Unpack *bu, Tox_Connection *val) { - uint32_t u32; + uint32_t u32 = 0; if (!bin_unpack_u32(bu, &u32)) { return false; @@ -35,7 +35,7 @@ bool tox_unpack_connection(Bin_Unpack *bu, Tox_Connection *val) bool tox_unpack_file_control(Bin_Unpack *bu, Tox_File_Control *val) { - uint32_t u32; + uint32_t u32 = 0; if (!bin_unpack_u32(bu, &u32)) { return false; @@ -47,7 +47,7 @@ bool tox_unpack_file_control(Bin_Unpack *bu, Tox_File_Control *val) bool tox_unpack_message_type(Bin_Unpack *bu, Tox_Message_Type *val) { - uint32_t u32; + uint32_t u32 = 0; if (!bin_unpack_u32(bu, &u32)) { return false; @@ -59,7 +59,7 @@ bool tox_unpack_message_type(Bin_Unpack *bu, Tox_Message_Type *val) bool tox_unpack_user_status(Bin_Unpack *bu, Tox_User_Status *val) { - uint32_t u32; + uint32_t u32 = 0; if (!bin_unpack_u32(bu, &u32)) { return false; diff --git a/toxcore/util.c b/toxcore/util.c index 3b3779bd7c1..a2d57783d08 100644 --- a/toxcore/util.c +++ b/toxcore/util.c @@ -42,7 +42,7 @@ void free_uint8_t_pointer_array(const Memory *mem, uint8_t **ary, size_t n_items uint16_t data_checksum(const uint8_t *data, uint32_t length) { uint8_t checksum[2] = {0}; - uint16_t check; + uint16_t check = 0; for (uint32_t i = 0; i < length; ++i) { checksum[i % 2] ^= data[i]; diff --git a/toxencryptsave/toxencryptsave.c b/toxencryptsave/toxencryptsave.c index 45003055f42..efff49e9711 100644 --- a/toxencryptsave/toxencryptsave.c +++ b/toxencryptsave/toxencryptsave.c @@ -253,7 +253,7 @@ bool tox_pass_key_encrypt(const Tox_Pass_Key *key, const uint8_t *plaintext, siz bool tox_pass_encrypt(const uint8_t *plaintext, size_t plaintext_len, const uint8_t *passphrase, size_t passphrase_len, uint8_t *ciphertext, Tox_Err_Encryption *error) { - Tox_Err_Key_Derivation err; + Tox_Err_Key_Derivation err = TOX_ERR_KEY_DERIVATION_OK; Tox_Pass_Key *key = tox_pass_key_derive(passphrase, passphrase_len, &err); if (key == nullptr) {