From d3b286cb434ed228e7b62cc70cb293e7a5554bfa Mon Sep 17 00:00:00 2001 From: iphydf Date: Fri, 23 Feb 2018 02:22:38 +0000 Subject: Fix a bunch of compiler warnings and remove suppressions. --- CMakeLists.txt | 57 ++++++++++++++-------------- auto_tests/BUILD.bazel | 10 +---- auto_tests/TCP_test.c | 8 ++-- auto_tests/check_compat.h | 10 ++--- auto_tests/conference_test.c | 2 +- auto_tests/crypto_test.c | 2 +- auto_tests/dht_test.c | 15 ++------ auto_tests/encryptsave_test.c | 2 +- auto_tests/file_transfer_test.c | 14 +++++-- auto_tests/friend_request_test.c | 2 +- auto_tests/helpers.h | 4 +- auto_tests/lossless_packet_test.c | 2 +- auto_tests/lossy_packet_test.c | 2 +- auto_tests/messenger_test.c | 7 ++-- auto_tests/monolith_test.cpp | 35 +++++++++++++++++- auto_tests/onion_test.c | 2 +- auto_tests/resource_leak_test.c | 9 +++-- auto_tests/save_friend_test.c | 7 ++-- 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/simple_conference_test.c | 14 ++++--- auto_tests/skeleton_test.c | 2 +- auto_tests/tox_many_tcp_test.c | 2 +- auto_tests/tox_many_test.c | 2 +- auto_tests/tox_one_test.c | 2 +- auto_tests/tox_strncasecmp_test.c | 4 +- auto_tests/toxav_basic_test.c | 2 +- auto_tests/toxav_many_test.c | 2 +- auto_tests/typing_test.c | 2 +- other/analysis/gen-file.sh | 48 ++++++++++++++++++++++++ other/analysis/run-clang | 7 ++++ other/analysis/run-cppcheck | 7 ++++ other/analysis/run-gcc | 72 ++++++++++++++++++++++++++++++++++++ other/analysis/run-infer | 10 +++++ other/analysis/run-sparse | 9 +++++ testing/Messenger_test.c | 4 +- testing/misc_tools.c | 4 ++ toxav/audio.c | 4 +- toxav/bwcontroller.c | 13 +++---- toxav/msi.c | 35 +++++++----------- toxav/rtp.c | 14 ++----- toxav/toxav.c | 2 +- toxav/video.c | 7 ++-- toxcore/BUILD.bazel | 10 +---- toxcore/DHT.c | 52 ++++++++++++++------------ toxcore/LAN_discovery.c | 4 +- toxcore/Messenger.c | 18 ++++----- toxcore/Messenger.h | 8 ++-- toxcore/TCP_client.c | 4 +- toxcore/TCP_server.c | 2 + toxcore/ccompat.h | 8 +++- toxcore/crypto_core.c | 2 +- toxcore/logger.h | 6 ++- toxcore/net_crypto.c | 2 - toxcore/network.c | 23 +++++++----- toxcore/network.h | 5 ++- toxcore/onion_client.c | 4 +- toxcore/tox.api.h | 14 +++---- toxcore/tox.c | 11 +++--- toxcore/tox.h | 14 +++---- 62 files changed, 417 insertions(+), 236 deletions(-) create mode 100644 other/analysis/gen-file.sh create mode 100755 other/analysis/run-clang create mode 100755 other/analysis/run-cppcheck create mode 100755 other/analysis/run-gcc create mode 100755 other/analysis/run-infer create mode 100755 other/analysis/run-sparse diff --git a/CMakeLists.txt b/CMakeLists.txt index 2f46824d..60e0c47b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -107,54 +107,53 @@ if(NOT MSVC) add_flag("-Weverything") # Disable specific warning flags for both C and C++. + + # TODO(iphydf): Clean these up. Probably all of these are actual bugs. add_flag("-Wno-cast-align") + # Very verbose, not very useful. This warns about things like int -> uint + # conversions that change sign without a cast and narrowing conversions. add_flag("-Wno-conversion") + # TODO(iphydf): Check enum values when received from the user, then assume + # correctness and remove this suppression. add_flag("-Wno-covered-switch-default") - # Due to clang's tolower() macro being recursive https://github.com/TokTok/c-toxcore/pull/481 + # Due to clang's tolower() macro being recursive + # https://github.com/TokTok/c-toxcore/pull/481 add_flag("-Wno-disabled-macro-expansion") + # We don't put __attribute__ on the public API. add_flag("-Wno-documentation-deprecated-sync") + # Bootstrap daemon does this. add_flag("-Wno-format-nonliteral") + # struct Foo foo = {0}; is a common idiom. add_flag("-Wno-missing-field-initializers") - add_flag("-Wno-missing-prototypes") - add_flag("-Wno-packed") + # Useful sometimes, but we accept padding in structs for clarity. + # Reordering fields to avoid padding will reduce readability. add_flag("-Wno-padded") - add_flag("-Wno-parentheses") + # This warns on things like _XOPEN_SOURCE, which we currently need (we + # probably won't need these in the future). add_flag("-Wno-reserved-id-macro") - add_flag("-Wno-return-type") + # TODO(iphydf): Clean these up. They are likely not bugs, but still + # potential issues and probably confusing. add_flag("-Wno-sign-compare") - add_flag("-Wno-sign-conversion") - # Our use of mutexes results in a false positive, see 1bbe446 + # Our use of mutexes results in a false positive, see 1bbe446. add_flag("-Wno-thread-safety-analysis") + # File transfer code has this. add_flag("-Wno-type-limits") - add_flag("-Wno-undef") - add_flag("-Wno-unreachable-code") - add_flag("-Wno-unused-macros") + # Callbacks often don't use all their parameters. add_flag("-Wno-unused-parameter") + # libvpx uses __attribute__((unused)) for "potentially unused" static + # functions to avoid unused static function warnings. + add_flag("-Wno-used-but-marked-unused") + # We use variable length arrays a lot. add_flag("-Wno-vla") - # Disable specific warning flags for C. - add_cflag("-Wno-assign-enum") - add_cflag("-Wno-bad-function-cast") - add_cflag("-Wno-double-promotion") - add_cflag("-Wno-gnu-zero-variadic-macro-arguments") - add_cflag("-Wno-packed") - add_cflag("-Wno-shadow") - add_cflag("-Wno-shorten-64-to-32") - add_cflag("-Wno-unreachable-code-return") - add_cflag("-Wno-unused-but-set-variable") - add_cflag("-Wno-used-but-marked-unused") - # Disable specific warning flags for C++. - add_cxxflag("-Wno-c++98-compat") + + # Comma at end of enum is supported everywhere we run. add_cxxflag("-Wno-c++98-compat-pedantic") + # TODO(iphydf): Stop using flexible array members. add_cxxflag("-Wno-c99-extensions") - add_cxxflag("-Wno-double-promotion") - add_cxxflag("-Wno-narrowing") + # We're C-compatible, so use C style casts. add_cxxflag("-Wno-old-style-cast") - add_cxxflag("-Wno-shadow") - add_cxxflag("-Wno-used-but-marked-unused") - add_cxxflag("-Wno-variadic-macros") - add_cxxflag("-Wno-vla-extension") # Downgrade to warning so we still see it. add_flag("-Wno-error=unused-variable") diff --git a/auto_tests/BUILD.bazel b/auto_tests/BUILD.bazel index 88951f97..af8920b1 100644 --- a/auto_tests/BUILD.bazel +++ b/auto_tests/BUILD.bazel @@ -11,10 +11,7 @@ cc_library( name = src[:-2], size = "small", srcs = [src], - copts = [ - "-Wno-parentheses", - "-Wno-sign-compare", - ], + copts = ["-Wno-sign-compare"], deps = [ ":helpers", "//c-toxcore/other:monolith", @@ -37,10 +34,7 @@ cc_test( name = "monolith_test", size = "small", srcs = ["monolith_test.cpp"], - copts = [ - "-Wno-parentheses", - "-Wno-sign-compare", - ], + copts = ["-Wno-sign-compare"], deps = [ ":helpers", ":monolith", diff --git a/auto_tests/TCP_test.c b/auto_tests/TCP_test.c index b14f53f2..686419a6 100644 --- a/auto_tests/TCP_test.c +++ b/auto_tests/TCP_test.c @@ -28,10 +28,8 @@ #endif #if !USE_IPV6 -# undef TOX_AF_INET6 -# define TOX_AF_INET6 TOX_AF_INET -# define get_ip6_loopback get_ip4_loopback -# define IP6 IP4 +#undef TOX_AF_INET6 +#define TOX_AF_INET6 TOX_AF_INET #endif static inline IP get_loopback() @@ -769,7 +767,7 @@ static Suite *TCP_suite(void) return s; } -int main(int argc, char *argv[]) +int main(void) { setvbuf(stdout, nullptr, _IONBF, 0); diff --git a/auto_tests/check_compat.h b/auto_tests/check_compat.h index 755dea81..badf18c8 100644 --- a/auto_tests/check_compat.h +++ b/auto_tests/check_compat.h @@ -16,26 +16,26 @@ typedef struct Suite Suite; typedef struct SRunner SRunner; enum SRunMode { CK_NORMAL }; -Suite *suite_create(const char *title) +static inline Suite *suite_create(const char *title) { printf("Running test suite: %s\n", title); return nullptr; } -SRunner *srunner_create(Suite *s) +static inline SRunner *srunner_create(Suite *s) { return nullptr; } -void srunner_free(SRunner *s) +static inline void srunner_free(SRunner *s) { } -void srunner_run_all(SRunner *r, int mode) +static inline void srunner_run_all(SRunner *r, int mode) { } -int srunner_ntests_failed(SRunner *r) +static inline int srunner_ntests_failed(SRunner *r) { return 0; } diff --git a/auto_tests/conference_test.c b/auto_tests/conference_test.c index 72c81de3..9e784e85 100644 --- a/auto_tests/conference_test.c +++ b/auto_tests/conference_test.c @@ -252,7 +252,7 @@ static void test_many_group(void) printf("test_many_group succeeded, took %d seconds\n", (int)(time(nullptr) - test_start_time)); } -int main(int argc, char *argv[]) +int main(void) { setvbuf(stdout, nullptr, _IONBF, 0); diff --git a/auto_tests/crypto_test.c b/auto_tests/crypto_test.c index e2c4e307..3b95dcc1 100644 --- a/auto_tests/crypto_test.c +++ b/auto_tests/crypto_test.c @@ -354,7 +354,7 @@ static Suite *crypto_suite(void) return s; } -int main(int argc, char *argv[]) +int main(void) { setvbuf(stdout, nullptr, _IONBF, 0); srand((unsigned int) time(nullptr)); diff --git a/auto_tests/dht_test.c b/auto_tests/dht_test.c index 516e1a8e..fe23a598 100644 --- a/auto_tests/dht_test.c +++ b/auto_tests/dht_test.c @@ -22,13 +22,6 @@ // These tests currently fail. static bool enable_broken_tests = false; -#define swap(x,y) do \ - { unsigned char swap_temp[sizeof(x) == sizeof(y) ? (signed)sizeof(x) : -1]; \ - memcpy(swap_temp,&y,sizeof(x)); \ - memcpy(&y,&x, sizeof(x)); \ - memcpy(&x,swap_temp,sizeof(x)); \ - } while(0) - #ifndef USE_IPV6 #define USE_IPV6 1 #endif @@ -335,7 +328,9 @@ static void test_addto_lists(IP ip) DHT *dht = new_DHT(nullptr, net, true); ck_assert_msg(dht != nullptr, "Failed to create DHT"); - IP_Port ip_port = { .ip = ip, .port = TOX_PORT_DEFAULT }; + IP_Port ip_port; + ip_port.ip = ip; + ip_port.port = TOX_PORT_DEFAULT; uint8_t public_key[CRYPTO_PUBLIC_KEY_SIZE]; int i, used; @@ -413,8 +408,6 @@ END_TEST #define DHT_DEFAULT_PORT (TOX_PORT_DEFAULT + 20) -#define DHT_LIST_LENGTH 128 - static void print_pk(uint8_t *public_key) { uint32_t j; @@ -799,7 +792,7 @@ static Suite *dht_suite(void) return s; } -int main(int argc, char *argv[]) +int main(void) { setvbuf(stdout, nullptr, _IONBF, 0); srand((unsigned int) time(nullptr)); diff --git a/auto_tests/encryptsave_test.c b/auto_tests/encryptsave_test.c index 41769dad..48a43c86 100644 --- a/auto_tests/encryptsave_test.c +++ b/auto_tests/encryptsave_test.c @@ -204,7 +204,7 @@ static Suite *encryptsave_suite(void) return s; } -int main(int argc, char *argv[]) +int main(void) { setvbuf(stdout, nullptr, _IONBF, 0); srand((unsigned int) time(nullptr)); diff --git a/auto_tests/file_transfer_test.c b/auto_tests/file_transfer_test.c index ab66ddd0..7fe780b8 100644 --- a/auto_tests/file_transfer_test.c +++ b/auto_tests/file_transfer_test.c @@ -287,7 +287,11 @@ START_TEST(test_few_clients) printf("Starting file streaming transfer test.\n"); - file_sending_done = file_accepted = file_size = sendf_ok = size_recv = 0; + file_sending_done = 0; + file_accepted = 0; + file_size = 0; + sendf_ok = 0; + size_recv = 0; file_recv = 0; tox_callback_file_recv_chunk(tox3, write_file); tox_callback_file_recv_control(tox2, file_print_control); @@ -335,7 +339,11 @@ START_TEST(test_few_clients) printf("Starting file 0 transfer test.\n"); - file_sending_done = file_accepted = file_size = sendf_ok = size_recv = 0; + file_sending_done = 0; + file_accepted = 0; + file_size = 0; + sendf_ok = 0; + size_recv = 0; file_recv = 0; tox_callback_file_recv_chunk(tox3, write_file); tox_callback_file_recv_control(tox2, file_print_control); @@ -395,7 +403,7 @@ static Suite *tox_suite(void) return s; } -int main(int argc, char *argv[]) +int main(void) { setvbuf(stdout, nullptr, _IONBF, 0); srand((unsigned int) time(nullptr)); diff --git a/auto_tests/friend_request_test.c b/auto_tests/friend_request_test.c index d9987cfc..2fbc2166 100644 --- a/auto_tests/friend_request_test.c +++ b/auto_tests/friend_request_test.c @@ -83,7 +83,7 @@ static void test_friend_request(void) tox_kill(tox2); } -int main(int argc, char *argv[]) +int main(void) { setvbuf(stdout, nullptr, _IONBF, 0); diff --git a/auto_tests/helpers.h b/auto_tests/helpers.h index fbb2ff04..bebde35b 100644 --- a/auto_tests/helpers.h +++ b/auto_tests/helpers.h @@ -19,6 +19,8 @@ #define ITERATION_INTERVAL 200 +Tox *tox_new_log(struct Tox_Options *options, TOX_ERR_NEW *err, void *log_user_data); + static const char *tox_log_level_name(TOX_LOG_LEVEL level) { switch (level) { @@ -54,7 +56,7 @@ static void print_debug_log(Tox *m, TOX_LOG_LEVEL level, const char *path, uint3 fprintf(stderr, "[#%d] %s %s:%d\t%s:\t%s\n", index, tox_log_level_name(level), file, line, func, message); } -Tox *tox_new_log_lan(struct Tox_Options *options, TOX_ERR_NEW *err, void *log_user_data, bool lan_discovery) +static Tox *tox_new_log_lan(struct Tox_Options *options, TOX_ERR_NEW *err, void *log_user_data, bool lan_discovery) { struct Tox_Options *log_options = options; diff --git a/auto_tests/lossless_packet_test.c b/auto_tests/lossless_packet_test.c index b5185757..05d56c4d 100644 --- a/auto_tests/lossless_packet_test.c +++ b/auto_tests/lossless_packet_test.c @@ -103,7 +103,7 @@ static void test_lossless_packet(void) tox_kill(tox2); } -int main(int argc, char *argv[]) +int main(void) { setvbuf(stdout, nullptr, _IONBF, 0); diff --git a/auto_tests/lossy_packet_test.c b/auto_tests/lossy_packet_test.c index d225a62b..c0af148f 100644 --- a/auto_tests/lossy_packet_test.c +++ b/auto_tests/lossy_packet_test.c @@ -100,7 +100,7 @@ static void test_lossy_packet(void) tox_kill(tox2); } -int main(int argc, char *argv[]) +int main(void) { setvbuf(stdout, nullptr, _IONBF, 0); diff --git a/auto_tests/messenger_test.c b/auto_tests/messenger_test.c index 9d797b55..12b00fd7 100644 --- a/auto_tests/messenger_test.c +++ b/auto_tests/messenger_test.c @@ -25,14 +25,13 @@ #include #include -#if VANILLA_NACL +#ifdef VANILLA_NACL #include // crypto_box_PUBLICKEYBYTES and other defines. #else #include #endif #define REALLY_BIG_NUMBER ((1) << (sizeof(uint16_t) * 7)) -#define STRINGS_EQUAL(X, Y) (strcmp(X, Y) == 0) static bool enable_broken_tests = false; @@ -213,7 +212,7 @@ START_TEST(test_m_copy_userstatus) assert(m_copy_userstatus(REALLY_BIG_NUMBER, buf, MAX_USERSTATUS_LENGTH) == -1); m_copy_userstatus(friend_id_num, buf, MAX_USERSTATUS_LENGTH + 6); - assert(STRINGS_EQUAL(name_buf, friend_id_status)); + assert(strcmp(name_buf, friend_id_status) == 0); } END_TEST #endif @@ -346,7 +345,7 @@ static Suite *messenger_suite(void) return s; } -int main(int argc, char *argv[]) +int main(void) { setvbuf(stdout, nullptr, _IONBF, 0); diff --git a/auto_tests/monolith_test.cpp b/auto_tests/monolith_test.cpp index 99703acf..60bafeb5 100644 --- a/auto_tests/monolith_test.cpp +++ b/auto_tests/monolith_test.cpp @@ -8,8 +8,9 @@ #include #endif +#ifdef __APPLE__ #define _DARWIN_C_SOURCE -#define _XOPEN_SOURCE 600 +#endif #ifdef HAVE_CONFIG_H #include "config.h" @@ -26,130 +27,162 @@ namespace TCP_test { +int main(void); #include "TCP_test.c" } namespace bootstrap_test { +int main(void); #include "bootstrap_test.c" } namespace conference_test { +int main(void); #include "conference_test.c" } namespace crypto_test { +int main(void); #include "crypto_test.c" } namespace dht_test { +int main(void); #include "dht_test.c" } namespace encryptsave_test { +int main(void); #include "encryptsave_test.c" } namespace file_saving_test { +int main(void); #include "file_saving_test.c" } namespace friend_request_test { +int main(void); #include "friend_request_test.c" } namespace lan_discovery_test { +int main(void); #include "lan_discovery_test.c" } namespace lossless_packet_test { +int main(void); #include "lossless_packet_test.c" } namespace lossy_packet_test { +int main(void); #include "lossy_packet_test.c" } namespace messenger_test { +int main(void); #include "messenger_test.c" } namespace network_test { +int main(void); #include "network_test.c" } namespace onion_test { +int main(void); #include "onion_test.c" } namespace resource_leak_test { +int main(void); #include "resource_leak_test.c" } namespace save_friend_test { +int main(void); #include "save_friend_test.c" } namespace save_load_test { +int main(void); #include "save_load_test.c" } namespace selfname_change_conference_test { +int main(void); #include "selfname_change_conference_test.c" } namespace self_conference_title_change_test { +int main(void); #include "self_conference_title_change_test.c" } namespace send_message_test { +int main(void); #include "send_message_test.c" } namespace set_name_test { +int main(void); #include "set_name_test.c" } namespace set_status_message_test { +int main(void); #include "set_status_message_test.c" } namespace simple_conference_test { +int main(void); #include "simple_conference_test.c" } namespace skeleton_test { +int main(void); #include "skeleton_test.c" } namespace toxav_basic_test { +int main(void); #include "toxav_basic_test.c" } namespace toxav_many_test { +int main(void); #include "toxav_many_test.c" } namespace tox_many_tcp_test { +int main(void); #include "tox_many_tcp_test.c" } namespace tox_many_test { +int main(void); #include "tox_many_test.c" } namespace tox_one_test { +int main(void); #include "tox_one_test.c" } namespace tox_strncasecmp_test { +int main(void); #include "tox_strncasecmp_test.c" } namespace typing_test { +int main(void); #include "typing_test.c" } namespace version_test { +int main(void); #include "version_test.c" } diff --git a/auto_tests/onion_test.c b/auto_tests/onion_test.c index 760a7800..e3eb3e5e 100644 --- a/auto_tests/onion_test.c +++ b/auto_tests/onion_test.c @@ -536,7 +536,7 @@ static Suite *onion_suite(void) return s; } -int main(int argc, char *argv[]) +int main(void) { setvbuf(stdout, nullptr, _IONBF, 0); srand((unsigned int) time(nullptr)); diff --git a/auto_tests/resource_leak_test.c b/auto_tests/resource_leak_test.c index cf451ebd..55998b72 100644 --- a/auto_tests/resource_leak_test.c +++ b/auto_tests/resource_leak_test.c @@ -5,11 +5,12 @@ #include "helpers.h" // See man 2 sbrk. -#if _BSD_SOURCE || _SVID_SOURCE || \ - (_XOPEN_SOURCE >= 500 || \ - _XOPEN_SOURCE && _XOPEN_SOURCE_EXTENDED) && \ - !(_POSIX_C_SOURCE >= 200112L || _XOPEN_SOURCE >= 600) +#if defined(_BSD_SOURCE) || defined(_SVID_SOURCE) || \ + defined(_XOPEN_SOURCE) && (_XOPEN_SOURCE >= 500 || defined(_XOPEN_SOURCE_EXTENDED)) && \ + !(defined(_POSIX_C_SOURCE) && _POSIX_C_SOURCE >= 200112L || _XOPEN_SOURCE >= 600) #define HAVE_SBRK 1 +#else +#define HAVE_SBRK 0 #endif #if HAVE_SBRK diff --git a/auto_tests/save_friend_test.c b/auto_tests/save_friend_test.c index ad4bd338..a7b41f52 100644 --- a/auto_tests/save_friend_test.c +++ b/auto_tests/save_friend_test.c @@ -33,21 +33,22 @@ static void set_random(Tox *m, bool (*setter)(Tox *, const uint8_t *, size_t, TO setter(m, text, SIZEOF_VLA(text), nullptr); } -void namechange_callback(Tox *tox, uint32_t friend_number, const uint8_t *name, size_t length, void *user_data) +static void namechange_callback(Tox *tox, uint32_t friend_number, const uint8_t *name, size_t length, void *user_data) { struct test_data *to_compare = (struct test_data *)user_data; memcpy(to_compare->name, name, length); to_compare->received_name = true; } -void statuschange_callback(Tox *tox, uint32_t friend_number, const uint8_t *message, size_t length, void *user_data) +static void statuschange_callback(Tox *tox, uint32_t friend_number, const uint8_t *message, size_t length, + void *user_data) { struct test_data *to_compare = (struct test_data *)user_data; memcpy(to_compare->status_message, message, length); to_compare->received_status_message = true; } -int main(int argc, char *argv[]) +int main(void) { setvbuf(stdout, nullptr, _IONBF, 0); diff --git a/auto_tests/save_load_test.c b/auto_tests/save_load_test.c index ab4e0a8c..50facb2c 100644 --- a/auto_tests/save_load_test.c +++ b/auto_tests/save_load_test.c @@ -140,7 +140,7 @@ static void test_few_clients(void) tox_kill(tox3); } -int main(int argc, char *argv[]) +int main(void) { setvbuf(stdout, nullptr, _IONBF, 0); diff --git a/auto_tests/send_message_test.c b/auto_tests/send_message_test.c index 3a5088f3..35ef5a62 100644 --- a/auto_tests/send_message_test.c +++ b/auto_tests/send_message_test.c @@ -111,7 +111,7 @@ static void test_send_message(void) tox_kill(tox2); } -int main(int argc, char *argv[]) +int main(void) { setvbuf(stdout, nullptr, _IONBF, 0); diff --git a/auto_tests/set_name_test.c b/auto_tests/set_name_test.c index a7f01ec7..20fb0a67 100644 --- a/auto_tests/set_name_test.c +++ b/auto_tests/set_name_test.c @@ -97,7 +97,7 @@ static void test_set_name(void) tox_kill(tox2); } -int main(int argc, char *argv[]) +int main(void) { setvbuf(stdout, nullptr, _IONBF, 0); diff --git a/auto_tests/set_status_message_test.c b/auto_tests/set_status_message_test.c index f1508720..fd6c3558 100644 --- a/auto_tests/set_status_message_test.c +++ b/auto_tests/set_status_message_test.c @@ -104,7 +104,7 @@ static void test_set_status_message(void) tox_kill(tox2); } -int main(int argc, char *argv[]) +int main(void) { setvbuf(stdout, nullptr, _IONBF, 0); diff --git a/auto_tests/simple_conference_test.c b/auto_tests/simple_conference_test.c index ad17d02e..7e07c45a 100644 --- a/auto_tests/simple_conference_test.c +++ b/auto_tests/simple_conference_test.c @@ -47,11 +47,13 @@ static void handle_conference_invite(Tox *tox, uint32_t friend_number, TOX_CONFE fprintf(stderr, "\nhandle_conference_invite(#%d, %d, %d, uint8_t[%zd], _)\n", state->id, friend_number, type, length); fprintf(stderr, "tox%d joining conference\n", state->id); - TOX_ERR_CONFERENCE_JOIN err; - state->conference = tox_conference_join(tox, friend_number, cookie, length, &err); - assert(err == TOX_ERR_CONFERENCE_JOIN_OK); - fprintf(stderr, "tox%d Joined conference %d\n", state->id, state->conference); - state->joined = true; + { + TOX_ERR_CONFERENCE_JOIN err; + state->conference = tox_conference_join(tox, friend_number, cookie, length, &err); + assert(err == TOX_ERR_CONFERENCE_JOIN_OK); + fprintf(stderr, "tox%d Joined conference %d\n", state->id, state->conference); + state->joined = true; + } // We're tox2, so now we invite tox3. if (state->id == 2) { @@ -101,7 +103,7 @@ static void handle_conference_namelist_change(Tox *tox, uint32_t conference_numb } } -int main() +int main(void) { setvbuf(stdout, nullptr, _IONBF, 0); diff --git a/auto_tests/skeleton_test.c b/auto_tests/skeleton_test.c index ac9291d0..1d391a86 100644 --- a/auto_tests/skeleton_test.c +++ b/auto_tests/skeleton_test.c @@ -29,7 +29,7 @@ static Suite *creativesuitenamegoeshere_suite(void) return s; } -int main(int argc, char *argv[]) +int main(void) { setvbuf(stdout, nullptr, _IONBF, 0); diff --git a/auto_tests/tox_many_tcp_test.c b/auto_tests/tox_many_tcp_test.c index 682e23a6..6c3f2350 100644 --- a/auto_tests/tox_many_tcp_test.c +++ b/auto_tests/tox_many_tcp_test.c @@ -250,7 +250,7 @@ static Suite *tox_suite(void) return s; } -int main(int argc, char *argv[]) +int main(void) { setvbuf(stdout, nullptr, _IONBF, 0); diff --git a/auto_tests/tox_many_test.c b/auto_tests/tox_many_test.c index a797d99c..29f3af68 100644 --- a/auto_tests/tox_many_test.c +++ b/auto_tests/tox_many_test.c @@ -130,7 +130,7 @@ loop_top: printf("test_many_clients succeeded, took %ld seconds\n", time(nullptr) - cur_time); } -int main(int argc, char *argv[]) +int main(void) { setvbuf(stdout, nullptr, _IONBF, 0); diff --git a/auto_tests/tox_one_test.c b/auto_tests/tox_one_test.c index 4ac30326..f3323bc9 100644 --- a/auto_tests/tox_one_test.c +++ b/auto_tests/tox_one_test.c @@ -141,7 +141,7 @@ static Suite *tox_suite(void) return s; } -int main(int argc, char *argv[]) +int main(void) { setvbuf(stdout, nullptr, _IONBF, 0); diff --git a/auto_tests/tox_strncasecmp_test.c b/auto_tests/tox_strncasecmp_test.c index 27105eca..377ec2e3 100644 --- a/auto_tests/tox_strncasecmp_test.c +++ b/auto_tests/tox_strncasecmp_test.c @@ -22,7 +22,7 @@ typedef enum { static const char *Comparison_Str[] = { "NEGATIVE", "ZERO", "POSITIVE" }; -void verify(const char *s1, const char *s2, size_t n, Comparison expected) +static void verify(const char *s1, const char *s2, size_t n, Comparison expected) { int r = tox_strncasecmp(s1, s2, n); Comparison actual = r < 0 ? NEGATIVE : r == 0 ? ZERO : POSITIVE; @@ -177,7 +177,7 @@ static Suite *tox_strncasecmp_suite(void) return s; } -int main(int argc, char *argv[]) +int main(void) { setvbuf(stdout, nullptr, _IONBF, 0); diff --git a/auto_tests/toxav_basic_test.c b/auto_tests/toxav_basic_test.c index 5c27e11f..b2b92255 100644 --- a/auto_tests/toxav_basic_test.c +++ b/auto_tests/toxav_basic_test.c @@ -559,7 +559,7 @@ static void test_av_flows(void) printf("\nTest successful!\n"); } -int main(int argc, char *argv[]) +int main(void) { setvbuf(stdout, nullptr, _IONBF, 0); diff --git a/auto_tests/toxav_many_test.c b/auto_tests/toxav_many_test.c index 4de1a867..ed4aa211 100644 --- a/auto_tests/toxav_many_test.c +++ b/auto_tests/toxav_many_test.c @@ -326,7 +326,7 @@ static void test_av_three_calls(void) printf("\nTest successful!\n"); } -int main(int argc, char *argv[]) +int main(void) { setvbuf(stdout, nullptr, _IONBF, 0); diff --git a/auto_tests/typing_test.c b/auto_tests/typing_test.c index 837ed757..1262fa3d 100644 --- a/auto_tests/typing_test.c +++ b/auto_tests/typing_test.c @@ -102,7 +102,7 @@ static void test_typing(void) tox_kill(tox2); } -int main(int argc, char *argv[]) +int main(void) { setvbuf(stdout, nullptr, _IONBF, 0); diff --git a/other/analysis/gen-file.sh b/other/analysis/gen-file.sh new file mode 100644 index 00000000..710e20d7 --- /dev/null +++ b/other/analysis/gen-file.sh @@ -0,0 +1,48 @@ +CPPFLAGS="-DMIN_LOGGER_LEVEL=LOG_TRACE -Iauto_tests -Itoxcore -Itoxav -Itoxencryptsave `pkg-config --cflags libsodium opus vpx`" + +put() { + if [ "$SKIP_LINES" = "" ]; then + echo "#line 1 \"$1\"" >> test.c + fi + cat $1 >> test.c +} + +:> test.c + +put toxcore/tox.c + +put toxcore/DHT.c +put toxcore/LAN_discovery.c +put toxcore/Messenger.c +put toxcore/TCP_client.c +put toxcore/TCP_connection.c +put toxcore/TCP_server.c +put toxcore/crypto_core.c +put toxcore/crypto_core_mem.c +put toxcore/friend_connection.c +put toxcore/friend_requests.c +put toxcore/group.c +put toxcore/list.c +put toxcore/logger.c +put toxcore/network.c +put toxcore/net_crypto.c +put toxcore/onion.c +put toxcore/onion_announce.c +put toxcore/onion_client.c +put toxcore/ping.c +put toxcore/ping_array.c +put toxcore/tox_api.c +put toxcore/util.c + +# Not included yet, since there are too many issues with this code. +#put toxav/audio.c +#put toxav/bwcontroller.c +#put toxav/groupav.c +#put toxav/msi.c +#put toxav/ring_buffer.c +#put toxav/rtp.c +#put toxav/toxav.c +#put toxav/toxav_old.c +#put toxav/video.c + +put toxencryptsave/toxencryptsave.c diff --git a/other/analysis/run-clang b/other/analysis/run-clang new file mode 100755 index 00000000..1c8da7ea --- /dev/null +++ b/other/analysis/run-clang @@ -0,0 +1,7 @@ +#!/bin/sh + +. other/analysis/gen-file.sh + +put auto_tests/lan_discovery_test.c + +clang --analyze test.c $CPPFLAGS diff --git a/other/analysis/run-cppcheck b/other/analysis/run-cppcheck new file mode 100755 index 00000000..9e928c9a --- /dev/null +++ b/other/analysis/run-cppcheck @@ -0,0 +1,7 @@ +#!/bin/sh + +. other/analysis/gen-file.sh + +put auto_tests/lan_discovery_test.c + +cppcheck test.c $CPPFLAGS diff --git a/other/analysis/run-gcc b/other/analysis/run-gcc new file mode 100755 index 00000000..ffd42f4e --- /dev/null +++ b/other/analysis/run-gcc @@ -0,0 +1,72 @@ +#!/bin/sh + +. other/analysis/gen-file.sh + +put auto_tests/lan_discovery_test.c + +# TODO(iphydf): Get rid of all VLAs, then enable -fstack-protector -Wstack-protector +gcc -O3 -c -o /dev/null test.c $CPPFLAGS \ + -std=c99 \ + -pedantic \ + -Wall \ + -Wextra \ + -Wno-aggregate-return \ + -Wno-aggressive-loop-optimizations \ + -Wno-float-conversion \ + -Wno-format-signedness \ + -Wno-missing-field-initializers \ + -Wno-padded \ + -Wno-sign-compare \ + -Wno-sign-conversion \ + -Wno-switch-default \ + -Wno-unused-parameter \ + -Wstrict-aliasing=0 \ + -Wstrict-overflow=1 \ + \ + -Wbad-function-cast \ + -Wmissing-declarations \ + -Wmissing-parameter-type \ + -Wmissing-prototypes \ + -Wnested-externs \ + -Wold-style-declaration \ + -Wold-style-definition \ + -Wstrict-prototypes \ + -Wbool-compare \ + -Wc99-c11-compat \ + -Wc++-compat \ + -Wcast-align \ + -Wcast-qual \ + -Wchar-subscripts \ + -Wdouble-promotion \ + -Wduplicated-cond \ + -Wempty-body \ + -Wenum-compare \ + -Wfloat-equal \ + -Wformat=2 \ + -Wframe-address \ + -Wframe-larger-than=133168 \ + -Wjump-misses-init \ + -Wignored-qualifiers \ + -Wignored-attributes \ + -Wincompatible-pointer-types \ + -Winit-self \ + -Winline \ + -Wlarger-than=133120 \ + -Wmaybe-uninitialized \ + -Wmemset-transposed-args \ + -Wmisleading-indentation \ + -Wnonnull \ + -Wnonnull-compare \ + -Wnull-dereference \ + -Wodr \ + -Wredundant-decls \ + -Wreturn-type \ + -Wshadow \ + -Wsuggest-attribute=format \ + -Wundef \ + -Wunsafe-loop-optimizations \ + -Wunused-label \ + -Wunused-local-typedefs \ + -Wunused-value \ + -Wunused-but-set-parameter \ + -Wunused-but-set-variable \ diff --git a/other/analysis/run-infer b/other/analysis/run-infer new file mode 100755 index 00000000..942d0cfd --- /dev/null +++ b/other/analysis/run-infer @@ -0,0 +1,10 @@ +#!/bin/sh + +# Infer ignores everything that's not in the "current file". +SKIP_LINES=1 + +. other/analysis/gen-file.sh + +put auto_tests/lan_discovery_test.c + +infer -- clang -fsyntax-only test.c $CPPFLAGS diff --git a/other/analysis/run-sparse b/other/analysis/run-sparse new file mode 100755 index 00000000..b4d0f736 --- /dev/null +++ b/other/analysis/run-sparse @@ -0,0 +1,9 @@ +#!/bin/sh + +. other/analysis/gen-file.sh + +put auto_tests/lan_discovery_test.c + +sparse test.c $CPPFLAGS \ + -Wsparse-all \ + -Wno-declaration-after-statement diff --git a/testing/Messenger_test.c b/testing/Messenger_test.c index 50e0fa57..daf2d125 100644 --- a/testing/Messenger_test.c +++ b/testing/Messenger_test.c @@ -190,6 +190,7 @@ int main(int argc, char *argv[]) FILE *file = fopen("Save.bak", "wb"); if (file == nullptr) { + kill_messenger(m); return 1; } @@ -198,12 +199,11 @@ int main(int argc, char *argv[]) size_t write_result = fwrite(buffer, 1, messenger_size(m), file); if (write_result < messenger_size(m)) { + kill_messenger(m); return 1; } free(buffer); fclose(file); } - - kill_messenger(m); } diff --git a/testing/misc_tools.c b/testing/misc_tools.c index 14e0ba7e..3a6a3333 100644 --- a/testing/misc_tools.c +++ b/testing/misc_tools.c @@ -47,6 +47,10 @@ #include "../toxcore/ccompat.h" +uint8_t *hex_string_to_bin(const char *hex_string); +int tox_strncasecmp(const char *s1, const char *s2, size_t n); +int cmdline_parsefor_ipv46(int argc, char **argv, uint8_t *ipv6enabled); + // You are responsible for freeing the return value! uint8_t *hex_string_to_bin(const char *hex_string) { diff --git a/toxav/audio.c b/toxav/audio.c index b97560fd..58a93add 100644 --- a/toxav/audio.c +++ b/toxav/audio.c @@ -121,7 +121,7 @@ void ac_kill(ACSession *ac) pthread_mutex_destroy(ac->queue_mutex); - LOGGER_DEBUG(ac->log, "Terminated audio handler: %p", ac); + LOGGER_DEBUG(ac->log, "Terminated audio handler: %p", (void *)ac); free(ac); } @@ -315,7 +315,7 @@ static int jbuf_write(Logger *log, struct JitterBuffer *q, struct RTPMessage *m) unsigned int num = sequnum % q->size; if ((uint32_t)(sequnum - q->bottom) > q->size) { - LOGGER_DEBUG(log, "Clearing filled jitter buffer: %p", q); + LOGGER_DEBUG(log, "Clearing filled jitter buffer: %p", (void *)q); jbuf_clear(q); q->bottom = sequnum - q->capacity; diff --git a/toxav/bwcontroller.c b/toxav/bwcontroller.c index defb3fde..6464a437 100644 --- a/toxav/bwcontroller.c +++ b/toxav/bwcontroller.c @@ -33,7 +33,6 @@ #define BWC_PACKET_ID 196 #define BWC_SEND_INTERVAL_MS 950 /* 0.95s */ -#define BWC_REFRESH_INTERVAL_MS 2000 /* 2.00s */ #define BWC_AVG_PKT_COUNT 20 #define BWC_AVG_LOSS_OVER_CYCLES_COUNT 30 @@ -137,8 +136,8 @@ void send_update(BWController *bwc) if (bwc->cycle.lost) { LOGGER_DEBUG(bwc->m->log, "%p Sent update rcv: %u lost: %u percent: %f %%", - bwc, bwc->cycle.recv, bwc->cycle.lost, - (((float) bwc->cycle.lost / (bwc->cycle.recv + bwc->cycle.lost)) * 100.0f)); + (void *)bwc, bwc->cycle.recv, bwc->cycle.lost, + (((double) bwc->cycle.lost / (bwc->cycle.recv + bwc->cycle.lost)) * 100.0)); uint8_t bwc_packet[sizeof(struct BWCMessage) + 1]; struct BWCMessage *msg = (struct BWCMessage *)(bwc_packet + 1); bwc_packet[0] = BWC_PACKET_ID; // set packet ID @@ -146,7 +145,7 @@ void send_update(BWController *bwc) msg->recv = net_htonl(bwc->cycle.recv); if (-1 == m_send_custom_lossy_packet(bwc->m, bwc->friend_number, bwc_packet, sizeof(bwc_packet))) { - LOGGER_WARNING(bwc->m->log, "BWC send failed (len: %d)! std error: %s", sizeof(bwc_packet), strerror(errno)); + LOGGER_WARNING(bwc->m->log, "BWC send failed (len: %zu)! std error: %s", sizeof(bwc_packet), strerror(errno)); } } @@ -158,11 +157,11 @@ void send_update(BWController *bwc) static int on_update(BWController *bwc, const struct BWCMessage *msg) { - LOGGER_DEBUG(bwc->m->log, "%p Got update from peer", bwc); + LOGGER_DEBUG(bwc->m->log, "%p Got update from peer", (void *)bwc); /* Peers sent update too soon */ if (bwc->cycle.last_recv_timestamp + BWC_SEND_INTERVAL_MS > current_time_monotonic()) { - LOGGER_INFO(bwc->m->log, "%p Rejecting extra update", bwc); + LOGGER_INFO(bwc->m->log, "%p Rejecting extra update", (void *)bwc); return -1; } @@ -173,7 +172,7 @@ static int on_update(BWController *bwc, const struct BWCMessage *msg) if (lost && bwc->mcb) { LOGGER_DEBUG(bwc->m->log, "recved: %u lost: %u percentage: %f %%", recv, lost, - (((float) lost / (recv + lost)) * 100.0f)); + (((double) lost / (recv + lost)) * 100.0)); bwc->mcb(bwc, bwc->friend_number, ((float) lost / (recv + lost)), bwc->mcb_data); diff --git a/toxav/msi.c b/toxav/msi.c index 94b7b537..47f76fb7 100644 --- a/toxav/msi.c +++ b/toxav/msi.c @@ -128,7 +128,7 @@ MSISession *msi_new(Messenger *m) /* This is called when remote terminates session */ m_callback_connectionstatus_internal_av(m, on_peer_status, retu); - LOGGER_DEBUG(m->log, "New msi session: %p ", retu); + LOGGER_DEBUG(m->log, "New msi session: %p ", (void *)retu); return retu; } int msi_kill(MSISession *session, Logger *log) @@ -162,7 +162,7 @@ int msi_kill(MSISession *session, Logger *log) pthread_mutex_unlock(session->mutex); pthread_mutex_destroy(session->mutex); - LOGGER_DEBUG(session->messenger->log, "Terminated session: %p", session); + LOGGER_DEBUG(session->messenger->log, "Terminated session: %p", (void *)session); free(session); return 0; } @@ -172,7 +172,7 @@ int msi_invite(MSISession *session, MSICall **call, uint32_t friend_number, uint return -1; } - LOGGER_DEBUG(session->messenger->log, "Session: %p Inviting friend: %u", session, friend_number); + LOGGER_DEBUG(session->messenger->log, "Session: %p Inviting friend: %u", (void *)session, friend_number); if (pthread_mutex_trylock(session->mutex) != 0) { LOGGER_ERROR(session->messenger->log, "Failed to acquire lock on msi mutex"); @@ -216,7 +216,7 @@ int msi_hangup(MSICall *call) MSISession *session = call->session; - LOGGER_DEBUG(session->messenger->log, "Session: %p Hanging up call with friend: %u", call->session, + LOGGER_DEBUG(session->messenger->log, "Session: %p Hanging up call with friend: %u", (void *)call->session, call->friend_number); if (pthread_mutex_trylock(session->mutex) != 0) { @@ -247,7 +247,8 @@ int msi_answer(MSICall *call, uint8_t capabilities) MSISession *session = call->session; - LOGGER_DEBUG(session->messenger->log, "Session: %p Answering call from: %u", call->session, call->friend_number); + LOGGER_DEBUG(session->messenger->log, "Session: %p Answering call from: %u", (void *)call->session, + call->friend_number); if (pthread_mutex_trylock(session->mutex) != 0) { LOGGER_ERROR(session->messenger->log, "Failed to acquire lock on msi mutex"); @@ -285,7 +286,7 @@ int msi_change_capabilities(MSICall *call, uint8_t capabilities) MSISession *session = call->session; - LOGGER_DEBUG(session->messenger->log, "Session: %p Trying to change capabilities to friend %u", call->session, + LOGGER_DEBUG(session->messenger->log, "Session: %p Trying to change capabilities to friend %u", (void *)call->session, call->friend_number); if (pthread_mutex_trylock(session->mutex) != 0) { @@ -340,13 +341,6 @@ int msg_parse_in(Logger *log, MSIMessage *dest, const uint8_t *data, uint16_t le bytes += 3; \ } while(0) -#define SET_UINT16(bytes, header) do { \ - memcpy(&header.value, bytes + 2, 2);\ - header.exists = true; \ - bytes += 4; \ - } while(0) - - assert(dest); if (length == 0 || data[length - 1]) { /* End byte must have value 0 */ @@ -394,7 +388,6 @@ int msg_parse_in(Logger *log, MSIMessage *dest, const uint8_t *data, uint16_t le #undef CHECK_SIZE #undef CHECK_ENUM_HIGH #undef SET_UINT8 -#undef SET_UINT16 } uint8_t *msg_parse_header_out(MSIHeaderID id, uint8_t *dest, const void *value, uint8_t value_len, uint16_t *length) { @@ -573,7 +566,7 @@ void kill_call(MSICall *call) MSISession *session = call->session; - LOGGER_DEBUG(session->messenger->log, "Killing call: %p", call); + LOGGER_DEBUG(session->messenger->log, "Killing call: %p", (void *)call); MSICall *prev = call->prev; MSICall *next = call->next; @@ -635,10 +628,10 @@ void handle_init(MSICall *call, const MSIMessage *msg) { assert(call); LOGGER_DEBUG(call->session->messenger->log, - "Session: %p Handling 'init' friend: %d", call->session, call->friend_number); + "Session: %p Handling 'init' friend: %d", (void *)call->session, call->friend_number); if (!msg->capabilities.exists) { - LOGGER_WARNING(call->session->messenger->log, "Session: %p Invalid capabilities on 'init'"); + LOGGER_WARNING(call->session->messenger->log, "Session: %p Invalid capabilities on 'init'", (void *)call->session); call->error = msi_EInvalidMessage; goto FAILURE; } @@ -681,7 +674,7 @@ void handle_init(MSICall *call, const MSIMessage *msg) case msi_CallRequested: // fall-through case msi_CallRequesting: { - LOGGER_WARNING(call->session->messenger->log, "Session: %p Invalid state on 'init'"); + LOGGER_WARNING(call->session->messenger->log, "Session: %p Invalid state on 'init'", (void *)call->session); call->error = msi_EInvalidState; goto FAILURE; } @@ -696,11 +689,11 @@ void handle_push(MSICall *call, const MSIMessage *msg) { assert(call); - LOGGER_DEBUG(call->session->messenger->log, "Session: %p Handling 'push' friend: %d", call->session, + LOGGER_DEBUG(call->session->messenger->log, "Session: %p Handling 'push' friend: %d", (void *)call->session, call->friend_number); if (!msg->capabilities.exists) { - LOGGER_WARNING(call->session->messenger->log, "Session: %p Invalid capabilities on 'push'"); + LOGGER_WARNING(call->session->messenger->log, "Session: %p Invalid capabilities on 'push'", (void *)call->session); call->error = msi_EInvalidMessage; goto FAILURE; } @@ -751,7 +744,7 @@ void handle_pop(MSICall *call, const MSIMessage *msg) { assert(call); - LOGGER_DEBUG(call->session->messenger->log, "Session: %p Handling 'pop', friend id: %d", call->session, + LOGGER_DEBUG(call->session->messenger->log, "Session: %p Handling 'pop', friend id: %d", (void *)call->session, call->friend_number); /* callback errors are ignored */ diff --git a/toxav/rtp.c b/toxav/rtp.c index c5d940e2..575b1502 100644 --- a/toxav/rtp.c +++ b/toxav/rtp.c @@ -694,7 +694,7 @@ void rtp_kill(RTPSession *session) return; } - LOGGER_DEBUG(session->m->log, "Terminated RTP session: %p", session); + LOGGER_DEBUG(session->m->log, "Terminated RTP session: %p", (void *)session); rtp_stop_receiving(session); LOGGER_DEBUG(session->m->log, "Terminated RTP session V3 work_buffer_list->next_free_entry: %d", @@ -716,7 +716,7 @@ int rtp_allow_receiving(RTPSession *session) return -1; } - LOGGER_DEBUG(session->m->log, "Started receiving on session: %p", session); + LOGGER_DEBUG(session->m->log, "Started receiving on session: %p", (void *)session); return 0; } @@ -728,7 +728,7 @@ int rtp_stop_receiving(RTPSession *session) m_callback_rtp_packet(session->m, session->friend_number, session->payload_type, nullptr, nullptr); - LOGGER_DEBUG(session->m->log, "Stopped receiving on session: %p", session); + LOGGER_DEBUG(session->m->log, "Stopped receiving on session: %p", (void *)session); return 0; } @@ -744,12 +744,6 @@ int rtp_send_data(RTPSession *session, const uint8_t *data, uint32_t length, return -1; } - uint8_t is_video_payload = 0; - - if (session->payload_type == rtp_TypeVideo) { - is_video_payload = 1; - } - struct RTPHeader header = {0}; header.ve = 2; // this is unused in toxav @@ -805,7 +799,7 @@ int rtp_send_data(RTPSession *session, const uint8_t *data, uint32_t length, memcpy(rdata + 1 + RTP_HEADER_SIZE, data, length); if (-1 == m_send_custom_lossy_packet(session->m, session->friend_number, rdata, SIZEOF_VLA(rdata))) { - LOGGER_WARNING(session->m->log, "RTP send failed (len: %d)! std error: %s", SIZEOF_VLA(rdata), strerror(errno)); + LOGGER_WARNING(session->m->log, "RTP send failed (len: %zu)! std error: %s", SIZEOF_VLA(rdata), strerror(errno)); } } else { /** diff --git a/toxav/toxav.c b/toxav/toxav.c index 4e45b747..36bf9cc2 100644 --- a/toxav/toxav.c +++ b/toxav/toxav.c @@ -950,7 +950,7 @@ void callback_bwc(BWController *bwc, uint32_t friend_number, float loss, void *u ToxAVCall *call = (ToxAVCall *)user_data; assert(call); - LOGGER_DEBUG(call->av->m->log, "Reported loss of %f%%", loss * 100); + LOGGER_DEBUG(call->av->m->log, "Reported loss of %f%%", (double)loss * 100); /* if less than 10% data loss we do nothing! */ if (loss < 0.1f) { diff --git a/toxav/video.c b/toxav/video.c index 0014dbb6..1d01d08a 100644 --- a/toxav/video.c +++ b/toxav/video.c @@ -76,14 +76,13 @@ #define VIDEO_CODEC_DECODER_MAX_WIDTH 800 // its a dummy value, because the struct needs a value there #define VIDEO_CODEC_DECODER_MAX_HEIGHT 600 // its a dummy value, because the struct needs a value there -#define VPX_MAX_DIST_NORMAL 40 #define VPX_MAX_DIST_START 40 #define VPX_MAX_ENCODER_THREADS 4 #define VPX_MAX_DECODER_THREADS 4 #define VIDEO__VP8_DECODER_POST_PROCESSING_ENABLED 0 -void vc_init_encoder_cfg(Logger *log, vpx_codec_enc_cfg_t *cfg, int16_t kf_max_dist) +static void vc_init_encoder_cfg(Logger *log, vpx_codec_enc_cfg_t *cfg, int16_t kf_max_dist) { vpx_codec_err_t rc = vpx_codec_enc_config_default(VIDEO_CODEC_ENCODER_INTERFACE, cfg, 0); @@ -288,7 +287,7 @@ void vc_kill(VCSession *vc) rb_kill((RingBuffer *)vc->vbuf_raw); pthread_mutex_destroy(vc->queue_mutex); - LOGGER_DEBUG(vc->log, "Terminated video handler: %p", vc); + LOGGER_DEBUG(vc->log, "Terminated video handler: %p", (void *)vc); free(vc); } @@ -417,7 +416,7 @@ int vc_reconfigure_encoder(VCSession *vc, uint32_t bit_rate, uint16_t width, uin /* Resolution is changed, must reinitialize encoder since libvpx v1.4 doesn't support * reconfiguring encoder to use resolutions greater than initially set. */ - LOGGER_DEBUG(vc->log, "Have to reinitialize vpx encoder on session %p", vc); + LOGGER_DEBUG(vc->log, "Have to reinitialize vpx encoder on session %p", (void *)vc); vpx_codec_ctx_t new_c; vpx_codec_enc_cfg_t cfg; vc_init_encoder_cfg(vc->log, &cfg, kf_max_dist); diff --git a/toxcore/BUILD.bazel b/toxcore/BUILD.bazel index d6c3693e..3dfa1648 100644 --- a/toxcore/BUILD.bazel +++ b/toxcore/BUILD.bazel @@ -48,6 +48,7 @@ cc_library( name = "logger", srcs = ["logger.c"], hdrs = ["logger.h"], + deps = [":ccompat"], ) cc_library( @@ -100,9 +101,6 @@ cc_library( "LAN_discovery.h", "ping.h", ], - copts = [ - "-Wno-parentheses", - ], visibility = ["//c-toxcore/other/bootstrap_daemon:__pkg__"], deps = [ ":crypto_core", @@ -205,9 +203,6 @@ cc_library( "tox.h", "tox_api.c", ], - copts = [ - "-Wno-parentheses", - ], visibility = ["//c-toxcore:__subpackages__"], deps = [ ":group", @@ -221,9 +216,6 @@ cc_library( "*.c", "*.h", ]), - copts = [ - "-Wno-parentheses", - ], linkopts = ["-lpthread"], visibility = ["//c-toxcore/other:__pkg__"], deps = [ diff --git a/toxcore/DHT.c b/toxcore/DHT.c index 10ea659e..4acfa161 100644 --- a/toxcore/DHT.c +++ b/toxcore/DHT.c @@ -615,8 +615,8 @@ static uint32_t index_of_node_pk(const Node_format *array, uint32_t size, const static uint32_t index_of_client_ip_port(const Client_data *array, uint32_t size, const IP_Port *ip_port) { for (uint32_t i = 0; i < size; ++i) { - if (ip_port->ip.family == TOX_AF_INET && ipport_equal(&array[i].assoc4.ip_port, ip_port) || - ip_port->ip.family == TOX_AF_INET6 && ipport_equal(&array[i].assoc6.ip_port, ip_port)) { + if ((ip_port->ip.family == TOX_AF_INET && ipport_equal(&array[i].assoc4.ip_port, ip_port)) || + (ip_port->ip.family == TOX_AF_INET6 && ipport_equal(&array[i].assoc6.ip_port, ip_port))) { return i; } } @@ -1084,18 +1084,20 @@ static bool ping_node_from_getnodes_ok(DHT *dht, const uint8_t *public_key, IP_P ret = true; } - unsigned int *const num = &dht->num_to_bootstrap; - const uint32_t index = index_of_node_pk(dht->to_bootstrap, *num, public_key); - const bool in_close_list = is_pk_in_close_list(dht, public_key, ip_port); + { + unsigned int *const num = &dht->num_to_bootstrap; + const uint32_t index = index_of_node_pk(dht->to_bootstrap, *num, public_key); + const bool in_close_list = is_pk_in_close_list(dht, public_key, ip_port); - if (ret && index == UINT32_MAX && !in_close_list) { - if (*num < MAX_CLOSE_TO_BOOTSTRAP_NODES) { - memcpy(dht->to_bootstrap[*num].public_key, public_key, CRYPTO_PUBLIC_KEY_SIZE); - dht->to_bootstrap[*num].ip_port = ip_port; - ++*num; - } else { - // TODO(irungentoo): ipv6 vs v4 - add_to_list(dht->to_bootstrap, MAX_CLOSE_TO_BOOTSTRAP_NODES, public_key, ip_port, dht->self_public_key); + if (ret && index == UINT32_MAX && !in_close_list) { + if (*num < MAX_CLOSE_TO_BOOTSTRAP_NODES) { + memcpy(dht->to_bootstrap[*num].public_key, public_key, CRYPTO_PUBLIC_KEY_SIZE); + dht->to_bootstrap[*num].ip_port = ip_port; + ++*num; + } else { + // TODO(irungentoo): ipv6 vs v4 + add_to_list(dht->to_bootstrap, MAX_CLOSE_TO_BOOTSTRAP_NODES, public_key, ip_port, dht->self_public_key); + } } } @@ -1655,8 +1657,8 @@ static uint8_t do_ping_and_sendnode_requests(DHT *dht, uint64_t *lastgetnode, co IPPTsPng *assocs[ASSOC_COUNT] = { &client->assoc6, &client->assoc4 }; - for (size_t i = 0; i < ASSOC_COUNT; i++) { - IPPTsPng *assoc = assocs[i]; + for (size_t j = 0; j < ASSOC_COUNT; j++) { + IPPTsPng *assoc = assocs[j]; if (!is_timeout(assoc->timestamp, KILL_NODE_TIMEOUT)) { sort = 0; @@ -1677,7 +1679,7 @@ static uint8_t do_ping_and_sendnode_requests(DHT *dht, uint64_t *lastgetnode, co ++sort; /* Timed out should be at beginning, if they are not, sort the list. */ - if (sort > 1 && sort < (((i + 1) * 2) - 1)) { + if (sort > 1 && sort < (((j + 1) * 2) - 1)) { sort_ok = true; } } @@ -2237,14 +2239,17 @@ static void do_NAT(DHT *dht) /*----------------------------------------------------------------------------------*/ /*-----------------------END OF NAT PUNCHING FUNCTIONS------------------------------*/ +#define DHT_HARDENING 0 #define HARDREQ_DATA_SIZE 384 /* Attempt to prevent amplification/other attacks*/ -#define CHECK_TYPE_ROUTE_REQ 0 -#define CHECK_TYPE_ROUTE_RES 1 -#define CHECK_TYPE_GETNODE_REQ 2 -#define CHECK_TYPE_GETNODE_RES 3 -#define CHECK_TYPE_TEST_REQ 4 -#define CHECK_TYPE_TEST_RES 5 +enum { + CHECK_TYPE_ROUTE_REQ = 0, + CHECK_TYPE_ROUTE_RES = 1, + CHECK_TYPE_GETNODE_REQ = 2, + CHECK_TYPE_GETNODE_RES = 3, + CHECK_TYPE_TEST_REQ = 4, + CHECK_TYPE_TEST_RES = 5, +}; #if DHT_HARDENING static int send_hardening_req(DHT *dht, Node_format *sendto, uint8_t type, uint8_t *contents, uint16_t length) @@ -2350,7 +2355,6 @@ static uint32_t have_nodes_closelist(DHT *dht, Node_format *nodes, uint16_t num) /* Interval in seconds between hardening checks */ #define HARDENING_INTERVAL 120 -#define HARDEN_TIMEOUT 1200 /* Handle a received hardening packet */ static int handle_hardening(void *object, IP_Port source, const uint8_t *source_pubkey, const uint8_t *packet, @@ -2429,6 +2433,8 @@ static int handle_hardening(void *object, IP_Port source, const uint8_t *source_ } #if DHT_HARDENING +#define HARDEN_TIMEOUT 1200 + /* Return a random node from all the nodes we are connected to. * TODO(irungentoo): improve this function. */ diff --git a/toxcore/LAN_discovery.c b/toxcore/LAN_discovery.c index f5883060..70b71fea 100644 --- a/toxcore/LAN_discovery.c +++ b/toxcore/LAN_discovery.c @@ -156,9 +156,9 @@ static void fetch_broadcast_info(uint16_t port) * a larger array, not done (640kB and 16 interfaces shall be * enough, for everybody!) */ - int i, n = ifconf.ifc_len / sizeof(struct ifreq); + int n = ifconf.ifc_len / sizeof(struct ifreq); - for (i = 0; i < n; i++) { + for (int i = 0; i < n; i++) { /* there are interfaces with are incapable of broadcast */ if (ioctl(sock, SIOCGIFBRDADDR, &i_faces[i]) < 0) { continue; diff --git a/toxcore/Messenger.c b/toxcore/Messenger.c index 5542ee1b..2bebae92 100644 --- a/toxcore/Messenger.c +++ b/toxcore/Messenger.c @@ -33,7 +33,6 @@ #include -static void set_friend_status(Messenger *m, int32_t friendnumber, uint8_t status, void *userdata); static int write_cryptpacket_id(const Messenger *m, int32_t friendnumber, uint8_t packet_id, const uint8_t *data, uint32_t length, uint8_t congestion_control); @@ -949,7 +948,7 @@ static void check_friend_connectionstatus(Messenger *m, int32_t friendnumber, ui } } -void set_friend_status(Messenger *m, int32_t friendnumber, uint8_t status, void *userdata) +static void set_friend_status(Messenger *m, int32_t friendnumber, uint8_t status, void *userdata) { check_friend_connectionstatus(m, friendnumber, status, userdata); m->friendlist[friendnumber].status = status; @@ -1825,13 +1824,13 @@ static int m_handle_custom_lossy_packet(void *object, int friend_num, const uint return 1; } -void custom_lossy_packet_registerhandler(Messenger *m, void (*packet_handler_callback)(Messenger *m, +void custom_lossy_packet_registerhandler(Messenger *m, void (*lossy_packethandler)(Messenger *m, uint32_t friendnumber, const uint8_t *data, size_t len, void *object)) { - m->lossy_packethandler = packet_handler_callback; + m->lossy_packethandler = lossy_packethandler; } -int m_callback_rtp_packet(Messenger *m, int32_t friendnumber, uint8_t byte, int (*packet_handler_callback)(Messenger *m, +int m_callback_rtp_packet(Messenger *m, int32_t friendnumber, uint8_t byte, int (*function)(Messenger *m, uint32_t friendnumber, const uint8_t *data, uint16_t len, void *object), void *object) { if (friend_not_valid(m, friendnumber)) { @@ -1846,8 +1845,7 @@ int m_callback_rtp_packet(Messenger *m, int32_t friendnumber, uint8_t byte, int return -1; } - m->friendlist[friendnumber].lossy_rtp_packethandlers[byte % PACKET_LOSSY_AV_RESERVED].function = - packet_handler_callback; + m->friendlist[friendnumber].lossy_rtp_packethandlers[byte % PACKET_LOSSY_AV_RESERVED].function = function; m->friendlist[friendnumber].lossy_rtp_packethandlers[byte % PACKET_LOSSY_AV_RESERVED].object = object; return 0; } @@ -1907,10 +1905,10 @@ static int handle_custom_lossless_packet(void *object, int friend_num, const uin return 1; } -void custom_lossless_packet_registerhandler(Messenger *m, void (*packet_handler_callback)(Messenger *m, +void custom_lossless_packet_registerhandler(Messenger *m, void (*lossless_packethandler)(Messenger *m, uint32_t friendnumber, const uint8_t *data, size_t len, void *object)) { - m->lossless_packethandler = packet_handler_callback; + m->lossless_packethandler = lossless_packethandler; } int send_custom_lossless_packet(const Messenger *m, int32_t friendnumber, const uint8_t *data, uint32_t length) @@ -2765,7 +2763,7 @@ struct SAVED_FRIEND { uint64_t last_seen_time; }; -static uint32_t friend_size() +static uint32_t friend_size(void) { uint32_t data = 0; const struct SAVED_FRIEND *const temp = nullptr; diff --git a/toxcore/Messenger.h b/toxcore/Messenger.h index 956f8ac5..402eb916 100644 --- a/toxcore/Messenger.h +++ b/toxcore/Messenger.h @@ -37,7 +37,7 @@ /* This cannot be bigger than 256 */ #define MAX_CONCURRENT_FILE_PIPES 256 -#if MAX_CONCURRENT_FILE_PIPES > UINT8_MAX + 1 +#if !defined(__SPLINT__) && MAX_CONCURRENT_FILE_PIPES > UINT8_MAX + 1 #error "uint8_t cannot represent all file transfer numbers" #endif @@ -74,13 +74,13 @@ enum { #define PACKET_LOSSY_AV_RESERVED 8 /* Number of lossy packet types at start of range reserved for A/V. */ typedef struct { - uint8_t ipv6enabled; - uint8_t udp_disabled; + bool ipv6enabled; + bool udp_disabled; TCP_Proxy_Info proxy_info; uint16_t port_range[2]; uint16_t tcp_server_port; - uint8_t hole_punching_enabled; + bool hole_punching_enabled; bool local_discovery_enabled; logger_cb *log_callback; diff --git a/toxcore/TCP_client.c b/toxcore/TCP_client.c index e3f55a73..a6c32f9c 100644 --- a/toxcore/TCP_client.c +++ b/toxcore/TCP_client.c @@ -110,9 +110,9 @@ void tcp_con_set_custom_object(TCP_Client_Connection *con, void *object) { con->custom_object = object; } -void tcp_con_set_custom_uint(TCP_Client_Connection *con, uint32_t uint) +void tcp_con_set_custom_uint(TCP_Client_Connection *con, uint32_t value) { - con->custom_uint = uint; + con->custom_uint = value; } /* return 1 on success diff --git a/toxcore/TCP_server.c b/toxcore/TCP_server.c index ae73b804..4541fce0 100644 --- a/toxcore/TCP_server.c +++ b/toxcore/TCP_server.c @@ -98,9 +98,11 @@ size_t tcp_server_listen_count(const TCP_Server *tcp_server) /* This is needed to compile on Android below API 21 */ +#ifdef TCP_SERVER_USE_EPOLL #ifndef EPOLLRDHUP #define EPOLLRDHUP 0x2000 #endif +#endif /* Set the size of the connection list to numfriends. * diff --git a/toxcore/ccompat.h b/toxcore/ccompat.h index 90db8bc6..1ceb5a5a 100644 --- a/toxcore/ccompat.h +++ b/toxcore/ccompat.h @@ -13,7 +13,7 @@ // "function") is used. Note the semantic difference: alloca'd memory does not // get freed at the end of the declaration's scope. Do not use VLA() in loops or // you may run out of stack space. -#if !defined(_MSC_VER) && __STDC_VERSION__ >= 199901L +#if !defined(_MSC_VER) && defined(__STDC_VERSION__) && __STDC_VERSION__ >= 199901L // C99 VLAs. #define VLA(type, name, size) type name[size] #define SIZEOF_VLA sizeof @@ -42,4 +42,10 @@ #define nullptr NULL #endif +#ifdef __GNUC__ +#define GNU_PRINTF __attribute__((__format__(__printf__, 6, 7))) +#else +#define GNU_PRINTF +#endif + #endif /* CCOMPAT_H */ diff --git a/toxcore/crypto_core.c b/toxcore/crypto_core.c index d5333e67..26589219 100644 --- a/toxcore/crypto_core.c +++ b/toxcore/crypto_core.c @@ -219,7 +219,7 @@ void increment_nonce(uint8_t *nonce) static uint32_t host_to_network(uint32_t x) { -#if BYTE_ORDER == LITTLE_ENDIAN +#if !defined(BYTE_ORDER) || BYTE_ORDER == LITTLE_ENDIAN return ((x >> 24) & 0x000000FF) | // move byte 3 to byte 0 ((x >> 8) & 0x0000FF00) | // move byte 2 to byte 1 diff --git a/toxcore/logger.h b/toxcore/logger.h index 8c8a639b..b3a8f7dc 100644 --- a/toxcore/logger.h +++ b/toxcore/logger.h @@ -26,6 +26,8 @@ #include +#include "ccompat.h" + #ifndef MIN_LOGGER_LEVEL #define MIN_LOGGER_LEVEL LOG_INFO #endif @@ -59,8 +61,8 @@ void logger_callback_log(Logger *log, logger_cb *function, void *context, void * /** * Main write function. If logging disabled does nothing. */ -void logger_write(Logger *log, LOGGER_LEVEL level, const char *file, int line, const char *func, const char *format, - ...); +void logger_write( + Logger *log, LOGGER_LEVEL level, const char *file, int line, const char *func, const char *format, ...) GNU_PRINTF; #define LOGGER_WRITE(log, level, ...) \ diff --git a/toxcore/net_crypto.c b/toxcore/net_crypto.c index fbdbaab8..65c81d92 100644 --- a/toxcore/net_crypto.c +++ b/toxcore/net_crypto.c @@ -1542,8 +1542,6 @@ static int handle_data_packet_core(Net_Crypto *c, int crypt_connection_id, const return -1; } - // else { /* TODO(irungentoo): ? */ } - set_buffer_end(&conn->recv_array, num); } else if (real_data[0] >= CRYPTO_RESERVED_PACKETS && real_data[0] < PACKET_ID_LOSSY_RANGE_START) { Packet_Data dt; diff --git a/toxcore/network.c b/toxcore/network.c index 99768829..6090b6e3 100644 --- a/toxcore/network.c +++ b/toxcore/network.c @@ -25,7 +25,10 @@ #include "config.h" #endif +#ifdef __APPLE__ #define _DARWIN_C_SOURCE +#endif + #ifndef _XOPEN_SOURCE #define _XOPEN_SOURCE 600 #endif @@ -185,14 +188,14 @@ const IP6 IP6_BROADCAST = { { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff } }; -IP4 get_ip4_loopback() +IP4 get_ip4_loopback(void) { IP4 loopback; loopback.uint32 = htonl(INADDR_LOOPBACK); return loopback; } -IP6 get_ip6_loopback() +IP6 get_ip6_loopback(void) { IP6 loopback; get_ip6(&loopback, &in6addr_loopback); @@ -374,18 +377,18 @@ static void loglogdata(Logger *log, const char *message, const uint8_t *buffer, char ip_str[IP_NTOA_LEN]; if (res < 0) { /* Windows doesn't necessarily know %zu */ - LOGGER_TRACE(log, "[%2u] %s %3hu%c %s:%hu (%u: %s) | %04x%04x", - buffer[0], message, (buflen < 999 ? (uint16_t)buflen : 999), 'E', + LOGGER_TRACE(log, "[%2u] %s %3u%c %s:%u (%u: %s) | %04x%04x", + buffer[0], message, (buflen < 999 ? buflen : 999), 'E', ip_ntoa(&ip_port.ip, ip_str, sizeof(ip_str)), net_ntohs(ip_port.port), errno, strerror(errno), data_0(buflen, buffer), data_1(buflen, buffer)); } else if ((res > 0) && ((size_t)res <= buflen)) { - LOGGER_TRACE(log, "[%2u] %s %3zu%c %s:%hu (%u: %s) | %04x%04x", - buffer[0], message, (res < 999 ? (size_t)res : 999), ((size_t)res < buflen ? '<' : '='), + LOGGER_TRACE(log, "[%2u] %s %3u%c %s:%u (%u: %s) | %04x%04x", + buffer[0], message, (res < 999 ? res : 999), ((size_t)res < buflen ? '<' : '='), ip_ntoa(&ip_port.ip, ip_str, sizeof(ip_str)), net_ntohs(ip_port.port), 0, "OK", data_0(buflen, buffer), data_1(buflen, buffer)); } else { /* empty or overwrite */ - LOGGER_TRACE(log, "[%2u] %s %zu%c%zu %s:%hu (%u: %s) | %04x%04x", - buffer[0], message, (size_t)res, (!res ? '!' : '>'), buflen, + LOGGER_TRACE(log, "[%2u] %s %u%c%u %s:%u (%u: %s) | %04x%04x", + buffer[0], message, res, (!res ? '!' : '>'), buflen, ip_ntoa(&ip_port.ip, ip_str, sizeof(ip_str)), net_ntohs(ip_port.port), 0, "OK", data_0(buflen, buffer), data_1(buflen, buffer)); } @@ -951,7 +954,7 @@ void ip_reset(IP *ip) } /* nulls out ip, sets family according to flag */ -void ip_init(IP *ip, uint8_t ipv6enabled) +void ip_init(IP *ip, bool ipv6enabled) { if (!ip) { return; @@ -1298,7 +1301,7 @@ int32_t net_getipport(const char *node, IP_Port **res, int tox_type) const size_t MAX_COUNT = MIN(SIZE_MAX, INT32_MAX) / sizeof(IP_Port); int type = make_socktype(tox_type); struct addrinfo *cur; - int32_t count = 0; + size_t count = 0; for (cur = infos; count < MAX_COUNT && cur != nullptr; cur = cur->ai_next) { if (cur->ai_socktype && type > 0 && cur->ai_socktype != type) { diff --git a/toxcore/network.h b/toxcore/network.h index 8b5af47c..405721b2 100644 --- a/toxcore/network.h +++ b/toxcore/network.h @@ -33,6 +33,7 @@ #include "ccompat.h" #include "logger.h" +#include #include #include #include @@ -187,7 +188,7 @@ size_t net_unpack_u64(const uint8_t *bytes, uint64_t *v); #define SIZE_PORT 2 #define SIZE_IPPORT (SIZE_IP + SIZE_PORT) -#define TOX_ENABLE_IPV6_DEFAULT 1 +#define TOX_ENABLE_IPV6_DEFAULT true /* addr_resolve return values */ #define TOX_ADDR_RESOLVE_INET 1 @@ -260,7 +261,7 @@ int ipport_equal(const IP_Port *a, const IP_Port *b); /* nulls out ip */ void ip_reset(IP *ip); /* nulls out ip, sets family according to flag */ -void ip_init(IP *ip, uint8_t ipv6enabled); +void ip_init(IP *ip, bool ipv6enabled); /* checks if ip is valid */ int ip_isset(const IP *ip); /* checks if ip is valid */ diff --git a/toxcore/onion_client.c b/toxcore/onion_client.c index e6743559..c4eb3fc1 100644 --- a/toxcore/onion_client.c +++ b/toxcore/onion_client.c @@ -1351,14 +1351,14 @@ int onion_delfriend(Onion_Client *onion_c, int friend_num) * return -1 on failure. * return 0 on success. */ -int recv_tcp_relay_handler(Onion_Client *onion_c, int friend_num, int (*tcp_relay_node_callback)(void *object, +int recv_tcp_relay_handler(Onion_Client *onion_c, int friend_num, int (*callback)(void *object, uint32_t number, IP_Port ip_port, const uint8_t *public_key), void *object, uint32_t number) { if ((uint32_t)friend_num >= onion_c->num_friends) { return -1; } - onion_c->friends_list[friend_num].tcp_relay_node_callback = tcp_relay_node_callback; + onion_c->friends_list[friend_num].tcp_relay_node_callback = callback; onion_c->friends_list[friend_num].tcp_relay_node_callback_object = object; onion_c->friends_list[friend_num].tcp_relay_node_callback_number = number; return 0; diff --git a/toxcore/tox.api.h b/toxcore/tox.api.h index 493307e9..fc5d5593 100644 --- a/toxcore/tox.api.h +++ b/toxcore/tox.api.h @@ -188,19 +188,19 @@ const VERSION_PATCH = 0; * features, but can't break the API. */ #define TOX_VERSION_IS_API_COMPATIBLE(MAJOR, MINOR, PATCH) \ - (TOX_VERSION_MAJOR > 0 && TOX_VERSION_MAJOR == MAJOR) && ( \ + ((TOX_VERSION_MAJOR > 0 && TOX_VERSION_MAJOR == MAJOR) && ( \ /* 1.x.x, 2.x.x, etc. with matching major version. */ \ TOX_VERSION_MINOR > MINOR || \ - TOX_VERSION_MINOR == MINOR && TOX_VERSION_PATCH >= PATCH \ - ) || (TOX_VERSION_MAJOR == 0 && MAJOR == 0) && ( \ + (TOX_VERSION_MINOR == MINOR && TOX_VERSION_PATCH >= PATCH) \ + )) || ((TOX_VERSION_MAJOR == 0 && MAJOR == 0) && ( \ /* 0.x.x makes minor behave like major above. */ \ - (TOX_VERSION_MINOR > 0 && TOX_VERSION_MINOR == MINOR) && ( \ + ((TOX_VERSION_MINOR > 0 && TOX_VERSION_MINOR == MINOR) && ( \ TOX_VERSION_PATCH >= PATCH \ - ) || (TOX_VERSION_MINOR == 0 && MINOR == 0) && ( \ + )) || ((TOX_VERSION_MINOR == 0 && MINOR == 0) && ( \ /* 0.0.x and 0.0.y are only compatible if x == y. */ \ TOX_VERSION_PATCH == PATCH \ - ) \ - ) + )) \ + )) static namespace version { diff --git a/toxcore/tox.c b/toxcore/tox.c index 747411f1..caaaedba 100644 --- a/toxcore/tox.c +++ b/toxcore/tox.c @@ -82,7 +82,7 @@ Tox *tox_new(const struct Tox_Options *options, TOX_ERR_NEW *error) { Messenger_Options m_options = {0}; - bool load_savedata_sk = 0, load_savedata_tox = 0; + bool load_savedata_sk = false, load_savedata_tox = false; if (options == nullptr) { m_options.ipv6enabled = TOX_ENABLE_IPV6_DEFAULT; @@ -100,7 +100,7 @@ Tox *tox_new(const struct Tox_Options *options, TOX_ERR_NEW *error) return nullptr; } - load_savedata_sk = 1; + load_savedata_sk = true; } else if (tox_options_get_savedata_type(options) == TOX_SAVEDATA_TYPE_TOX_SAVE) { if (tox_options_get_savedata_length(options) < TOX_ENC_SAVE_MAGIC_LENGTH) { SET_ERROR_PARAMETER(error, TOX_ERR_NEW_LOAD_BAD_FORMAT); @@ -112,7 +112,7 @@ Tox *tox_new(const struct Tox_Options *options, TOX_ERR_NEW *error) return nullptr; } - load_savedata_tox = 1; + load_savedata_tox = true; } m_options.ipv6enabled = tox_options_get_ipv6_enabled(options); @@ -156,7 +156,7 @@ Tox *tox_new(const struct Tox_Options *options, TOX_ERR_NEW *error) m_options.proxy_info.ip_port.ip.family = TOX_AF_UNSPEC; } - if (!addr_resolve_or_parse_ip(tox_options_get_proxy_host(options), &m_options.proxy_info.ip_port.ip, nullptr)) { + if (addr_resolve_or_parse_ip(tox_options_get_proxy_host(options), &m_options.proxy_info.ip_port.ip, nullptr) == 0) { SET_ERROR_PARAMETER(error, TOX_ERR_NEW_PROXY_BAD_HOST); // TODO(irungentoo): TOX_ERR_NEW_PROXY_NOT_FOUND if domain. return nullptr; @@ -457,7 +457,8 @@ void tox_self_set_status(Tox *tox, TOX_USER_STATUS status) TOX_USER_STATUS tox_self_get_status(const Tox *tox) { const Messenger *m = tox; - return (TOX_USER_STATUS)m_get_self_userstatus(m); + const uint8_t status = m_get_self_userstatus(m); + return (TOX_USER_STATUS)status; } static void set_friend_error(int32_t ret, TOX_ERR_FRIEND_ADD *error) diff --git a/toxcore/tox.h b/toxcore/tox.h index f2e746c8..cf5b2c28 100644 --- a/toxcore/tox.h +++ b/toxcore/tox.h @@ -191,19 +191,19 @@ uint32_t tox_version_patch(void); * features, but can't break the API. */ #define TOX_VERSION_IS_API_COMPATIBLE(MAJOR, MINOR, PATCH) \ - (TOX_VERSION_MAJOR > 0 && TOX_VERSION_MAJOR == MAJOR) && ( \ + ((TOX_VERSION_MAJOR > 0 && TOX_VERSION_MAJOR == MAJOR) && ( \ /* 1.x.x, 2.x.x, etc. with matching major version. */ \ TOX_VERSION_MINOR > MINOR || \ - TOX_VERSION_MINOR == MINOR && TOX_VERSION_PATCH >= PATCH \ - ) || (TOX_VERSION_MAJOR == 0 && MAJOR == 0) && ( \ + (TOX_VERSION_MINOR == MINOR && TOX_VERSION_PATCH >= PATCH) \ + )) || ((TOX_VERSION_MAJOR == 0 && MAJOR == 0) && ( \ /* 0.x.x makes minor behave like major above. */ \ - (TOX_VERSION_MINOR > 0 && TOX_VERSION_MINOR == MINOR) && ( \ + ((TOX_VERSION_MINOR > 0 && TOX_VERSION_MINOR == MINOR) && ( \ TOX_VERSION_PATCH >= PATCH \ - ) || (TOX_VERSION_MINOR == 0 && MINOR == 0) && ( \ + )) || ((TOX_VERSION_MINOR == 0 && MINOR == 0) && ( \ /* 0.0.x and 0.0.y are only compatible if x == y. */ \ TOX_VERSION_PATCH == PATCH \ - ) \ - ) + )) \ + )) /** * Return whether the compiled library version is compatible with the passed -- cgit v1.2.3