diff options
62 files changed, 417 insertions, 236 deletions
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) | |||
107 | add_flag("-Weverything") | 107 | add_flag("-Weverything") |
108 | 108 | ||
109 | # Disable specific warning flags for both C and C++. | 109 | # Disable specific warning flags for both C and C++. |
110 | |||
111 | # TODO(iphydf): Clean these up. Probably all of these are actual bugs. | ||
110 | add_flag("-Wno-cast-align") | 112 | add_flag("-Wno-cast-align") |
113 | # Very verbose, not very useful. This warns about things like int -> uint | ||
114 | # conversions that change sign without a cast and narrowing conversions. | ||
111 | add_flag("-Wno-conversion") | 115 | add_flag("-Wno-conversion") |
116 | # TODO(iphydf): Check enum values when received from the user, then assume | ||
117 | # correctness and remove this suppression. | ||
112 | add_flag("-Wno-covered-switch-default") | 118 | add_flag("-Wno-covered-switch-default") |
113 | # Due to clang's tolower() macro being recursive https://github.com/TokTok/c-toxcore/pull/481 | 119 | # Due to clang's tolower() macro being recursive |
120 | # https://github.com/TokTok/c-toxcore/pull/481 | ||
114 | add_flag("-Wno-disabled-macro-expansion") | 121 | add_flag("-Wno-disabled-macro-expansion") |
122 | # We don't put __attribute__ on the public API. | ||
115 | add_flag("-Wno-documentation-deprecated-sync") | 123 | add_flag("-Wno-documentation-deprecated-sync") |
124 | # Bootstrap daemon does this. | ||
116 | add_flag("-Wno-format-nonliteral") | 125 | add_flag("-Wno-format-nonliteral") |
126 | # struct Foo foo = {0}; is a common idiom. | ||
117 | add_flag("-Wno-missing-field-initializers") | 127 | add_flag("-Wno-missing-field-initializers") |
118 | add_flag("-Wno-missing-prototypes") | 128 | # Useful sometimes, but we accept padding in structs for clarity. |
119 | add_flag("-Wno-packed") | 129 | # Reordering fields to avoid padding will reduce readability. |
120 | add_flag("-Wno-padded") | 130 | add_flag("-Wno-padded") |
121 | add_flag("-Wno-parentheses") | 131 | # This warns on things like _XOPEN_SOURCE, which we currently need (we |
132 | # probably won't need these in the future). | ||
122 | add_flag("-Wno-reserved-id-macro") | 133 | add_flag("-Wno-reserved-id-macro") |
123 | add_flag("-Wno-return-type") | 134 | # TODO(iphydf): Clean these up. They are likely not bugs, but still |
135 | # potential issues and probably confusing. | ||
124 | add_flag("-Wno-sign-compare") | 136 | add_flag("-Wno-sign-compare") |
125 | add_flag("-Wno-sign-conversion") | 137 | # Our use of mutexes results in a false positive, see 1bbe446. |
126 | # Our use of mutexes results in a false positive, see 1bbe446 | ||
127 | add_flag("-Wno-thread-safety-analysis") | 138 | add_flag("-Wno-thread-safety-analysis") |
139 | # File transfer code has this. | ||
128 | add_flag("-Wno-type-limits") | 140 | add_flag("-Wno-type-limits") |
129 | add_flag("-Wno-undef") | 141 | # Callbacks often don't use all their parameters. |
130 | add_flag("-Wno-unreachable-code") | ||
131 | add_flag("-Wno-unused-macros") | ||
132 | add_flag("-Wno-unused-parameter") | 142 | add_flag("-Wno-unused-parameter") |
143 | # libvpx uses __attribute__((unused)) for "potentially unused" static | ||
144 | # functions to avoid unused static function warnings. | ||
145 | add_flag("-Wno-used-but-marked-unused") | ||
146 | # We use variable length arrays a lot. | ||
133 | add_flag("-Wno-vla") | 147 | add_flag("-Wno-vla") |
134 | 148 | ||
135 | # Disable specific warning flags for C. | ||
136 | add_cflag("-Wno-assign-enum") | ||
137 | add_cflag("-Wno-bad-function-cast") | ||
138 | add_cflag("-Wno-double-promotion") | ||
139 | add_cflag("-Wno-gnu-zero-variadic-macro-arguments") | ||
140 | add_cflag("-Wno-packed") | ||
141 | add_cflag("-Wno-shadow") | ||
142 | add_cflag("-Wno-shorten-64-to-32") | ||
143 | add_cflag("-Wno-unreachable-code-return") | ||
144 | add_cflag("-Wno-unused-but-set-variable") | ||
145 | add_cflag("-Wno-used-but-marked-unused") | ||
146 | |||
147 | # Disable specific warning flags for C++. | 149 | # Disable specific warning flags for C++. |
148 | add_cxxflag("-Wno-c++98-compat") | 150 | |
151 | # Comma at end of enum is supported everywhere we run. | ||
149 | add_cxxflag("-Wno-c++98-compat-pedantic") | 152 | add_cxxflag("-Wno-c++98-compat-pedantic") |
153 | # TODO(iphydf): Stop using flexible array members. | ||
150 | add_cxxflag("-Wno-c99-extensions") | 154 | add_cxxflag("-Wno-c99-extensions") |
151 | add_cxxflag("-Wno-double-promotion") | 155 | # We're C-compatible, so use C style casts. |
152 | add_cxxflag("-Wno-narrowing") | ||
153 | add_cxxflag("-Wno-old-style-cast") | 156 | add_cxxflag("-Wno-old-style-cast") |
154 | add_cxxflag("-Wno-shadow") | ||
155 | add_cxxflag("-Wno-used-but-marked-unused") | ||
156 | add_cxxflag("-Wno-variadic-macros") | ||
157 | add_cxxflag("-Wno-vla-extension") | ||
158 | 157 | ||
159 | # Downgrade to warning so we still see it. | 158 | # Downgrade to warning so we still see it. |
160 | add_flag("-Wno-error=unused-variable") | 159 | 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( | |||
11 | name = src[:-2], | 11 | name = src[:-2], |
12 | size = "small", | 12 | size = "small", |
13 | srcs = [src], | 13 | srcs = [src], |
14 | copts = [ | 14 | copts = ["-Wno-sign-compare"], |
15 | "-Wno-parentheses", | ||
16 | "-Wno-sign-compare", | ||
17 | ], | ||
18 | deps = [ | 15 | deps = [ |
19 | ":helpers", | 16 | ":helpers", |
20 | "//c-toxcore/other:monolith", | 17 | "//c-toxcore/other:monolith", |
@@ -37,10 +34,7 @@ cc_test( | |||
37 | name = "monolith_test", | 34 | name = "monolith_test", |
38 | size = "small", | 35 | size = "small", |
39 | srcs = ["monolith_test.cpp"], | 36 | srcs = ["monolith_test.cpp"], |
40 | copts = [ | 37 | copts = ["-Wno-sign-compare"], |
41 | "-Wno-parentheses", | ||
42 | "-Wno-sign-compare", | ||
43 | ], | ||
44 | deps = [ | 38 | deps = [ |
45 | ":helpers", | 39 | ":helpers", |
46 | ":monolith", | 40 | ":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 @@ | |||
28 | #endif | 28 | #endif |
29 | 29 | ||
30 | #if !USE_IPV6 | 30 | #if !USE_IPV6 |
31 | # undef TOX_AF_INET6 | 31 | #undef TOX_AF_INET6 |
32 | # define TOX_AF_INET6 TOX_AF_INET | 32 | #define TOX_AF_INET6 TOX_AF_INET |
33 | # define get_ip6_loopback get_ip4_loopback | ||
34 | # define IP6 IP4 | ||
35 | #endif | 33 | #endif |
36 | 34 | ||
37 | static inline IP get_loopback() | 35 | static inline IP get_loopback() |
@@ -769,7 +767,7 @@ static Suite *TCP_suite(void) | |||
769 | return s; | 767 | return s; |
770 | } | 768 | } |
771 | 769 | ||
772 | int main(int argc, char *argv[]) | 770 | int main(void) |
773 | { | 771 | { |
774 | setvbuf(stdout, nullptr, _IONBF, 0); | 772 | setvbuf(stdout, nullptr, _IONBF, 0); |
775 | 773 | ||
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; | |||
16 | typedef struct SRunner SRunner; | 16 | typedef struct SRunner SRunner; |
17 | enum SRunMode { CK_NORMAL }; | 17 | enum SRunMode { CK_NORMAL }; |
18 | 18 | ||
19 | Suite *suite_create(const char *title) | 19 | static inline Suite *suite_create(const char *title) |
20 | { | 20 | { |
21 | printf("Running test suite: %s\n", title); | 21 | printf("Running test suite: %s\n", title); |
22 | return nullptr; | 22 | return nullptr; |
23 | } | 23 | } |
24 | 24 | ||
25 | SRunner *srunner_create(Suite *s) | 25 | static inline SRunner *srunner_create(Suite *s) |
26 | { | 26 | { |
27 | return nullptr; | 27 | return nullptr; |
28 | } | 28 | } |
29 | 29 | ||
30 | void srunner_free(SRunner *s) | 30 | static inline void srunner_free(SRunner *s) |
31 | { | 31 | { |
32 | } | 32 | } |
33 | 33 | ||
34 | void srunner_run_all(SRunner *r, int mode) | 34 | static inline void srunner_run_all(SRunner *r, int mode) |
35 | { | 35 | { |
36 | } | 36 | } |
37 | 37 | ||
38 | int srunner_ntests_failed(SRunner *r) | 38 | static inline int srunner_ntests_failed(SRunner *r) |
39 | { | 39 | { |
40 | return 0; | 40 | return 0; |
41 | } | 41 | } |
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) | |||
252 | printf("test_many_group succeeded, took %d seconds\n", (int)(time(nullptr) - test_start_time)); | 252 | printf("test_many_group succeeded, took %d seconds\n", (int)(time(nullptr) - test_start_time)); |
253 | } | 253 | } |
254 | 254 | ||
255 | int main(int argc, char *argv[]) | 255 | int main(void) |
256 | { | 256 | { |
257 | setvbuf(stdout, nullptr, _IONBF, 0); | 257 | setvbuf(stdout, nullptr, _IONBF, 0); |
258 | 258 | ||
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) | |||
354 | return s; | 354 | return s; |
355 | } | 355 | } |
356 | 356 | ||
357 | int main(int argc, char *argv[]) | 357 | int main(void) |
358 | { | 358 | { |
359 | setvbuf(stdout, nullptr, _IONBF, 0); | 359 | setvbuf(stdout, nullptr, _IONBF, 0); |
360 | srand((unsigned int) time(nullptr)); | 360 | 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 @@ | |||
22 | // These tests currently fail. | 22 | // These tests currently fail. |
23 | static bool enable_broken_tests = false; | 23 | static bool enable_broken_tests = false; |
24 | 24 | ||
25 | #define swap(x,y) do \ | ||
26 | { unsigned char swap_temp[sizeof(x) == sizeof(y) ? (signed)sizeof(x) : -1]; \ | ||
27 | memcpy(swap_temp,&y,sizeof(x)); \ | ||
28 | memcpy(&y,&x, sizeof(x)); \ | ||
29 | memcpy(&x,swap_temp,sizeof(x)); \ | ||
30 | } while(0) | ||
31 | |||
32 | #ifndef USE_IPV6 | 25 | #ifndef USE_IPV6 |
33 | #define USE_IPV6 1 | 26 | #define USE_IPV6 1 |
34 | #endif | 27 | #endif |
@@ -335,7 +328,9 @@ static void test_addto_lists(IP ip) | |||
335 | DHT *dht = new_DHT(nullptr, net, true); | 328 | DHT *dht = new_DHT(nullptr, net, true); |
336 | ck_assert_msg(dht != nullptr, "Failed to create DHT"); | 329 | ck_assert_msg(dht != nullptr, "Failed to create DHT"); |
337 | 330 | ||
338 | IP_Port ip_port = { .ip = ip, .port = TOX_PORT_DEFAULT }; | 331 | IP_Port ip_port; |
332 | ip_port.ip = ip; | ||
333 | ip_port.port = TOX_PORT_DEFAULT; | ||
339 | uint8_t public_key[CRYPTO_PUBLIC_KEY_SIZE]; | 334 | uint8_t public_key[CRYPTO_PUBLIC_KEY_SIZE]; |
340 | int i, used; | 335 | int i, used; |
341 | 336 | ||
@@ -413,8 +408,6 @@ END_TEST | |||
413 | 408 | ||
414 | #define DHT_DEFAULT_PORT (TOX_PORT_DEFAULT + 20) | 409 | #define DHT_DEFAULT_PORT (TOX_PORT_DEFAULT + 20) |
415 | 410 | ||
416 | #define DHT_LIST_LENGTH 128 | ||
417 | |||
418 | static void print_pk(uint8_t *public_key) | 411 | static void print_pk(uint8_t *public_key) |
419 | { | 412 | { |
420 | uint32_t j; | 413 | uint32_t j; |
@@ -799,7 +792,7 @@ static Suite *dht_suite(void) | |||
799 | return s; | 792 | return s; |
800 | } | 793 | } |
801 | 794 | ||
802 | int main(int argc, char *argv[]) | 795 | int main(void) |
803 | { | 796 | { |
804 | setvbuf(stdout, nullptr, _IONBF, 0); | 797 | setvbuf(stdout, nullptr, _IONBF, 0); |
805 | srand((unsigned int) time(nullptr)); | 798 | 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) | |||
204 | return s; | 204 | return s; |
205 | } | 205 | } |
206 | 206 | ||
207 | int main(int argc, char *argv[]) | 207 | int main(void) |
208 | { | 208 | { |
209 | setvbuf(stdout, nullptr, _IONBF, 0); | 209 | setvbuf(stdout, nullptr, _IONBF, 0); |
210 | srand((unsigned int) time(nullptr)); | 210 | 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) | |||
287 | 287 | ||
288 | printf("Starting file streaming transfer test.\n"); | 288 | printf("Starting file streaming transfer test.\n"); |
289 | 289 | ||
290 | file_sending_done = file_accepted = file_size = sendf_ok = size_recv = 0; | 290 | file_sending_done = 0; |
291 | file_accepted = 0; | ||
292 | file_size = 0; | ||
293 | sendf_ok = 0; | ||
294 | size_recv = 0; | ||
291 | file_recv = 0; | 295 | file_recv = 0; |
292 | tox_callback_file_recv_chunk(tox3, write_file); | 296 | tox_callback_file_recv_chunk(tox3, write_file); |
293 | tox_callback_file_recv_control(tox2, file_print_control); | 297 | tox_callback_file_recv_control(tox2, file_print_control); |
@@ -335,7 +339,11 @@ START_TEST(test_few_clients) | |||
335 | 339 | ||
336 | printf("Starting file 0 transfer test.\n"); | 340 | printf("Starting file 0 transfer test.\n"); |
337 | 341 | ||
338 | file_sending_done = file_accepted = file_size = sendf_ok = size_recv = 0; | 342 | file_sending_done = 0; |
343 | file_accepted = 0; | ||
344 | file_size = 0; | ||
345 | sendf_ok = 0; | ||
346 | size_recv = 0; | ||
339 | file_recv = 0; | 347 | file_recv = 0; |
340 | tox_callback_file_recv_chunk(tox3, write_file); | 348 | tox_callback_file_recv_chunk(tox3, write_file); |
341 | tox_callback_file_recv_control(tox2, file_print_control); | 349 | tox_callback_file_recv_control(tox2, file_print_control); |
@@ -395,7 +403,7 @@ static Suite *tox_suite(void) | |||
395 | return s; | 403 | return s; |
396 | } | 404 | } |
397 | 405 | ||
398 | int main(int argc, char *argv[]) | 406 | int main(void) |
399 | { | 407 | { |
400 | setvbuf(stdout, nullptr, _IONBF, 0); | 408 | setvbuf(stdout, nullptr, _IONBF, 0); |
401 | srand((unsigned int) time(nullptr)); | 409 | 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) | |||
83 | tox_kill(tox2); | 83 | tox_kill(tox2); |
84 | } | 84 | } |
85 | 85 | ||
86 | int main(int argc, char *argv[]) | 86 | int main(void) |
87 | { | 87 | { |
88 | setvbuf(stdout, nullptr, _IONBF, 0); | 88 | setvbuf(stdout, nullptr, _IONBF, 0); |
89 | 89 | ||
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 @@ | |||
19 | 19 | ||
20 | #define ITERATION_INTERVAL 200 | 20 | #define ITERATION_INTERVAL 200 |
21 | 21 | ||
22 | Tox *tox_new_log(struct Tox_Options *options, TOX_ERR_NEW *err, void *log_user_data); | ||
23 | |||
22 | static const char *tox_log_level_name(TOX_LOG_LEVEL level) | 24 | static const char *tox_log_level_name(TOX_LOG_LEVEL level) |
23 | { | 25 | { |
24 | switch (level) { | 26 | switch (level) { |
@@ -54,7 +56,7 @@ static void print_debug_log(Tox *m, TOX_LOG_LEVEL level, const char *path, uint3 | |||
54 | fprintf(stderr, "[#%d] %s %s:%d\t%s:\t%s\n", index, tox_log_level_name(level), file, line, func, message); | 56 | fprintf(stderr, "[#%d] %s %s:%d\t%s:\t%s\n", index, tox_log_level_name(level), file, line, func, message); |
55 | } | 57 | } |
56 | 58 | ||
57 | Tox *tox_new_log_lan(struct Tox_Options *options, TOX_ERR_NEW *err, void *log_user_data, bool lan_discovery) | 59 | static Tox *tox_new_log_lan(struct Tox_Options *options, TOX_ERR_NEW *err, void *log_user_data, bool lan_discovery) |
58 | { | 60 | { |
59 | struct Tox_Options *log_options = options; | 61 | struct Tox_Options *log_options = options; |
60 | 62 | ||
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) | |||
103 | tox_kill(tox2); | 103 | tox_kill(tox2); |
104 | } | 104 | } |
105 | 105 | ||
106 | int main(int argc, char *argv[]) | 106 | int main(void) |
107 | { | 107 | { |
108 | setvbuf(stdout, nullptr, _IONBF, 0); | 108 | setvbuf(stdout, nullptr, _IONBF, 0); |
109 | 109 | ||
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) | |||
100 | tox_kill(tox2); | 100 | tox_kill(tox2); |
101 | } | 101 | } |
102 | 102 | ||
103 | int main(int argc, char *argv[]) | 103 | int main(void) |
104 | { | 104 | { |
105 | setvbuf(stdout, nullptr, _IONBF, 0); | 105 | setvbuf(stdout, nullptr, _IONBF, 0); |
106 | 106 | ||
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 @@ | |||
25 | #include <string.h> | 25 | #include <string.h> |
26 | #include <sys/types.h> | 26 | #include <sys/types.h> |
27 | 27 | ||
28 | #if VANILLA_NACL | 28 | #ifdef VANILLA_NACL |
29 | #include <crypto_box.h> // crypto_box_PUBLICKEYBYTES and other defines. | 29 | #include <crypto_box.h> // crypto_box_PUBLICKEYBYTES and other defines. |
30 | #else | 30 | #else |
31 | #include <sodium.h> | 31 | #include <sodium.h> |
32 | #endif | 32 | #endif |
33 | 33 | ||
34 | #define REALLY_BIG_NUMBER ((1) << (sizeof(uint16_t) * 7)) | 34 | #define REALLY_BIG_NUMBER ((1) << (sizeof(uint16_t) * 7)) |
35 | #define STRINGS_EQUAL(X, Y) (strcmp(X, Y) == 0) | ||
36 | 35 | ||
37 | static bool enable_broken_tests = false; | 36 | static bool enable_broken_tests = false; |
38 | 37 | ||
@@ -213,7 +212,7 @@ START_TEST(test_m_copy_userstatus) | |||
213 | assert(m_copy_userstatus(REALLY_BIG_NUMBER, buf, MAX_USERSTATUS_LENGTH) == -1); | 212 | assert(m_copy_userstatus(REALLY_BIG_NUMBER, buf, MAX_USERSTATUS_LENGTH) == -1); |
214 | m_copy_userstatus(friend_id_num, buf, MAX_USERSTATUS_LENGTH + 6); | 213 | m_copy_userstatus(friend_id_num, buf, MAX_USERSTATUS_LENGTH + 6); |
215 | 214 | ||
216 | assert(STRINGS_EQUAL(name_buf, friend_id_status)); | 215 | assert(strcmp(name_buf, friend_id_status) == 0); |
217 | } | 216 | } |
218 | END_TEST | 217 | END_TEST |
219 | #endif | 218 | #endif |
@@ -346,7 +345,7 @@ static Suite *messenger_suite(void) | |||
346 | return s; | 345 | return s; |
347 | } | 346 | } |
348 | 347 | ||
349 | int main(int argc, char *argv[]) | 348 | int main(void) |
350 | { | 349 | { |
351 | setvbuf(stdout, nullptr, _IONBF, 0); | 350 | setvbuf(stdout, nullptr, _IONBF, 0); |
352 | 351 | ||
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 @@ | |||
8 | #include <net/if.h> | 8 | #include <net/if.h> |
9 | #endif | 9 | #endif |
10 | 10 | ||
11 | #ifdef __APPLE__ | ||
11 | #define _DARWIN_C_SOURCE | 12 | #define _DARWIN_C_SOURCE |
12 | #define _XOPEN_SOURCE 600 | 13 | #endif |
13 | 14 | ||
14 | #ifdef HAVE_CONFIG_H | 15 | #ifdef HAVE_CONFIG_H |
15 | #include "config.h" | 16 | #include "config.h" |
@@ -26,130 +27,162 @@ | |||
26 | 27 | ||
27 | namespace TCP_test | 28 | namespace TCP_test |
28 | { | 29 | { |
30 | int main(void); | ||
29 | #include "TCP_test.c" | 31 | #include "TCP_test.c" |
30 | } | 32 | } |
31 | namespace bootstrap_test | 33 | namespace bootstrap_test |
32 | { | 34 | { |
35 | int main(void); | ||
33 | #include "bootstrap_test.c" | 36 | #include "bootstrap_test.c" |
34 | } | 37 | } |
35 | namespace conference_test | 38 | namespace conference_test |
36 | { | 39 | { |
40 | int main(void); | ||
37 | #include "conference_test.c" | 41 | #include "conference_test.c" |
38 | } | 42 | } |
39 | namespace crypto_test | 43 | namespace crypto_test |
40 | { | 44 | { |
45 | int main(void); | ||
41 | #include "crypto_test.c" | 46 | #include "crypto_test.c" |
42 | } | 47 | } |
43 | namespace dht_test | 48 | namespace dht_test |
44 | { | 49 | { |
50 | int main(void); | ||
45 | #include "dht_test.c" | 51 | #include "dht_test.c" |
46 | } | 52 | } |
47 | namespace encryptsave_test | 53 | namespace encryptsave_test |
48 | { | 54 | { |
55 | int main(void); | ||
49 | #include "encryptsave_test.c" | 56 | #include "encryptsave_test.c" |
50 | } | 57 | } |
51 | namespace file_saving_test | 58 | namespace file_saving_test |
52 | { | 59 | { |
60 | int main(void); | ||
53 | #include "file_saving_test.c" | 61 | #include "file_saving_test.c" |
54 | } | 62 | } |
55 | namespace friend_request_test | 63 | namespace friend_request_test |
56 | { | 64 | { |
65 | int main(void); | ||
57 | #include "friend_request_test.c" | 66 | #include "friend_request_test.c" |
58 | } | 67 | } |
59 | namespace lan_discovery_test | 68 | namespace lan_discovery_test |
60 | { | 69 | { |
70 | int main(void); | ||
61 | #include "lan_discovery_test.c" | 71 | #include "lan_discovery_test.c" |
62 | } | 72 | } |
63 | namespace lossless_packet_test | 73 | namespace lossless_packet_test |
64 | { | 74 | { |
75 | int main(void); | ||
65 | #include "lossless_packet_test.c" | 76 | #include "lossless_packet_test.c" |
66 | } | 77 | } |
67 | namespace lossy_packet_test | 78 | namespace lossy_packet_test |
68 | { | 79 | { |
80 | int main(void); | ||
69 | #include "lossy_packet_test.c" | 81 | #include "lossy_packet_test.c" |
70 | } | 82 | } |
71 | namespace messenger_test | 83 | namespace messenger_test |
72 | { | 84 | { |
85 | int main(void); | ||
73 | #include "messenger_test.c" | 86 | #include "messenger_test.c" |
74 | } | 87 | } |
75 | namespace network_test | 88 | namespace network_test |
76 | { | 89 | { |
90 | int main(void); | ||
77 | #include "network_test.c" | 91 | #include "network_test.c" |
78 | } | 92 | } |
79 | namespace onion_test | 93 | namespace onion_test |
80 | { | 94 | { |
95 | int main(void); | ||
81 | #include "onion_test.c" | 96 | #include "onion_test.c" |
82 | } | 97 | } |
83 | namespace resource_leak_test | 98 | namespace resource_leak_test |
84 | { | 99 | { |
100 | int main(void); | ||
85 | #include "resource_leak_test.c" | 101 | #include "resource_leak_test.c" |
86 | } | 102 | } |
87 | namespace save_friend_test | 103 | namespace save_friend_test |
88 | { | 104 | { |
105 | int main(void); | ||
89 | #include "save_friend_test.c" | 106 | #include "save_friend_test.c" |
90 | } | 107 | } |
91 | namespace save_load_test | 108 | namespace save_load_test |
92 | { | 109 | { |
110 | int main(void); | ||
93 | #include "save_load_test.c" | 111 | #include "save_load_test.c" |
94 | } | 112 | } |
95 | namespace selfname_change_conference_test | 113 | namespace selfname_change_conference_test |
96 | { | 114 | { |
115 | int main(void); | ||
97 | #include "selfname_change_conference_test.c" | 116 | #include "selfname_change_conference_test.c" |
98 | } | 117 | } |
99 | namespace self_conference_title_change_test | 118 | namespace self_conference_title_change_test |
100 | { | 119 | { |
120 | int main(void); | ||
101 | #include "self_conference_title_change_test.c" | 121 | #include "self_conference_title_change_test.c" |
102 | } | 122 | } |
103 | namespace send_message_test | 123 | namespace send_message_test |
104 | { | 124 | { |
125 | int main(void); | ||
105 | #include "send_message_test.c" | 126 | #include "send_message_test.c" |
106 | } | 127 | } |
107 | namespace set_name_test | 128 | namespace set_name_test |
108 | { | 129 | { |
130 | int main(void); | ||
109 | #include "set_name_test.c" | 131 | #include "set_name_test.c" |
110 | } | 132 | } |
111 | namespace set_status_message_test | 133 | namespace set_status_message_test |
112 | { | 134 | { |
135 | int main(void); | ||
113 | #include "set_status_message_test.c" | 136 | #include "set_status_message_test.c" |
114 | } | 137 | } |
115 | namespace simple_conference_test | 138 | namespace simple_conference_test |
116 | { | 139 | { |
140 | int main(void); | ||
117 | #include "simple_conference_test.c" | 141 | #include "simple_conference_test.c" |
118 | } | 142 | } |
119 | namespace skeleton_test | 143 | namespace skeleton_test |
120 | { | 144 | { |
145 | int main(void); | ||
121 | #include "skeleton_test.c" | 146 | #include "skeleton_test.c" |
122 | } | 147 | } |
123 | namespace toxav_basic_test | 148 | namespace toxav_basic_test |
124 | { | 149 | { |
150 | int main(void); | ||
125 | #include "toxav_basic_test.c" | 151 | #include "toxav_basic_test.c" |
126 | } | 152 | } |
127 | namespace toxav_many_test | 153 | namespace toxav_many_test |
128 | { | 154 | { |
155 | int main(void); | ||
129 | #include "toxav_many_test.c" | 156 | #include "toxav_many_test.c" |
130 | } | 157 | } |
131 | namespace tox_many_tcp_test | 158 | namespace tox_many_tcp_test |
132 | { | 159 | { |
160 | int main(void); | ||
133 | #include "tox_many_tcp_test.c" | 161 | #include "tox_many_tcp_test.c" |
134 | } | 162 | } |
135 | namespace tox_many_test | 163 | namespace tox_many_test |
136 | { | 164 | { |
165 | int main(void); | ||
137 | #include "tox_many_test.c" | 166 | #include "tox_many_test.c" |
138 | } | 167 | } |
139 | namespace tox_one_test | 168 | namespace tox_one_test |
140 | { | 169 | { |
170 | int main(void); | ||
141 | #include "tox_one_test.c" | 171 | #include "tox_one_test.c" |
142 | } | 172 | } |
143 | namespace tox_strncasecmp_test | 173 | namespace tox_strncasecmp_test |
144 | { | 174 | { |
175 | int main(void); | ||
145 | #include "tox_strncasecmp_test.c" | 176 | #include "tox_strncasecmp_test.c" |
146 | } | 177 | } |
147 | namespace typing_test | 178 | namespace typing_test |
148 | { | 179 | { |
180 | int main(void); | ||
149 | #include "typing_test.c" | 181 | #include "typing_test.c" |
150 | } | 182 | } |
151 | namespace version_test | 183 | namespace version_test |
152 | { | 184 | { |
185 | int main(void); | ||
153 | #include "version_test.c" | 186 | #include "version_test.c" |
154 | } | 187 | } |
155 | 188 | ||
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) | |||
536 | return s; | 536 | return s; |
537 | } | 537 | } |
538 | 538 | ||
539 | int main(int argc, char *argv[]) | 539 | int main(void) |
540 | { | 540 | { |
541 | setvbuf(stdout, nullptr, _IONBF, 0); | 541 | setvbuf(stdout, nullptr, _IONBF, 0); |
542 | srand((unsigned int) time(nullptr)); | 542 | 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 @@ | |||
5 | #include "helpers.h" | 5 | #include "helpers.h" |
6 | 6 | ||
7 | // See man 2 sbrk. | 7 | // See man 2 sbrk. |
8 | #if _BSD_SOURCE || _SVID_SOURCE || \ | 8 | #if defined(_BSD_SOURCE) || defined(_SVID_SOURCE) || \ |
9 | (_XOPEN_SOURCE >= 500 || \ | 9 | defined(_XOPEN_SOURCE) && (_XOPEN_SOURCE >= 500 || defined(_XOPEN_SOURCE_EXTENDED)) && \ |
10 | _XOPEN_SOURCE && _XOPEN_SOURCE_EXTENDED) && \ | 10 | !(defined(_POSIX_C_SOURCE) && _POSIX_C_SOURCE >= 200112L || _XOPEN_SOURCE >= 600) |
11 | !(_POSIX_C_SOURCE >= 200112L || _XOPEN_SOURCE >= 600) | ||
12 | #define HAVE_SBRK 1 | 11 | #define HAVE_SBRK 1 |
12 | #else | ||
13 | #define HAVE_SBRK 0 | ||
13 | #endif | 14 | #endif |
14 | 15 | ||
15 | #if HAVE_SBRK | 16 | #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 | |||
33 | setter(m, text, SIZEOF_VLA(text), nullptr); | 33 | setter(m, text, SIZEOF_VLA(text), nullptr); |
34 | } | 34 | } |
35 | 35 | ||
36 | void namechange_callback(Tox *tox, uint32_t friend_number, const uint8_t *name, size_t length, void *user_data) | 36 | static void namechange_callback(Tox *tox, uint32_t friend_number, const uint8_t *name, size_t length, void *user_data) |
37 | { | 37 | { |
38 | struct test_data *to_compare = (struct test_data *)user_data; | 38 | struct test_data *to_compare = (struct test_data *)user_data; |
39 | memcpy(to_compare->name, name, length); | 39 | memcpy(to_compare->name, name, length); |
40 | to_compare->received_name = true; | 40 | to_compare->received_name = true; |
41 | } | 41 | } |
42 | 42 | ||
43 | void statuschange_callback(Tox *tox, uint32_t friend_number, const uint8_t *message, size_t length, void *user_data) | 43 | static void statuschange_callback(Tox *tox, uint32_t friend_number, const uint8_t *message, size_t length, |
44 | void *user_data) | ||
44 | { | 45 | { |
45 | struct test_data *to_compare = (struct test_data *)user_data; | 46 | struct test_data *to_compare = (struct test_data *)user_data; |
46 | memcpy(to_compare->status_message, message, length); | 47 | memcpy(to_compare->status_message, message, length); |
47 | to_compare->received_status_message = true; | 48 | to_compare->received_status_message = true; |
48 | } | 49 | } |
49 | 50 | ||
50 | int main(int argc, char *argv[]) | 51 | int main(void) |
51 | { | 52 | { |
52 | setvbuf(stdout, nullptr, _IONBF, 0); | 53 | setvbuf(stdout, nullptr, _IONBF, 0); |
53 | 54 | ||
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) | |||
140 | tox_kill(tox3); | 140 | tox_kill(tox3); |
141 | } | 141 | } |
142 | 142 | ||
143 | int main(int argc, char *argv[]) | 143 | int main(void) |
144 | { | 144 | { |
145 | setvbuf(stdout, nullptr, _IONBF, 0); | 145 | setvbuf(stdout, nullptr, _IONBF, 0); |
146 | 146 | ||
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) | |||
111 | tox_kill(tox2); | 111 | tox_kill(tox2); |
112 | } | 112 | } |
113 | 113 | ||
114 | int main(int argc, char *argv[]) | 114 | int main(void) |
115 | { | 115 | { |
116 | setvbuf(stdout, nullptr, _IONBF, 0); | 116 | setvbuf(stdout, nullptr, _IONBF, 0); |
117 | 117 | ||
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) | |||
97 | tox_kill(tox2); | 97 | tox_kill(tox2); |
98 | } | 98 | } |
99 | 99 | ||
100 | int main(int argc, char *argv[]) | 100 | int main(void) |
101 | { | 101 | { |
102 | setvbuf(stdout, nullptr, _IONBF, 0); | 102 | setvbuf(stdout, nullptr, _IONBF, 0); |
103 | 103 | ||
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) | |||
104 | tox_kill(tox2); | 104 | tox_kill(tox2); |
105 | } | 105 | } |
106 | 106 | ||
107 | int main(int argc, char *argv[]) | 107 | int main(void) |
108 | { | 108 | { |
109 | setvbuf(stdout, nullptr, _IONBF, 0); | 109 | setvbuf(stdout, nullptr, _IONBF, 0); |
110 | 110 | ||
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 | |||
47 | fprintf(stderr, "\nhandle_conference_invite(#%d, %d, %d, uint8_t[%zd], _)\n", state->id, friend_number, type, length); | 47 | fprintf(stderr, "\nhandle_conference_invite(#%d, %d, %d, uint8_t[%zd], _)\n", state->id, friend_number, type, length); |
48 | fprintf(stderr, "tox%d joining conference\n", state->id); | 48 | fprintf(stderr, "tox%d joining conference\n", state->id); |
49 | 49 | ||
50 | TOX_ERR_CONFERENCE_JOIN err; | 50 | { |
51 | state->conference = tox_conference_join(tox, friend_number, cookie, length, &err); | 51 | TOX_ERR_CONFERENCE_JOIN err; |
52 | assert(err == TOX_ERR_CONFERENCE_JOIN_OK); | 52 | state->conference = tox_conference_join(tox, friend_number, cookie, length, &err); |
53 | fprintf(stderr, "tox%d Joined conference %d\n", state->id, state->conference); | 53 | assert(err == TOX_ERR_CONFERENCE_JOIN_OK); |
54 | state->joined = true; | 54 | fprintf(stderr, "tox%d Joined conference %d\n", state->id, state->conference); |
55 | state->joined = true; | ||
56 | } | ||
55 | 57 | ||
56 | // We're tox2, so now we invite tox3. | 58 | // We're tox2, so now we invite tox3. |
57 | if (state->id == 2) { | 59 | if (state->id == 2) { |
@@ -101,7 +103,7 @@ static void handle_conference_namelist_change(Tox *tox, uint32_t conference_numb | |||
101 | } | 103 | } |
102 | } | 104 | } |
103 | 105 | ||
104 | int main() | 106 | int main(void) |
105 | { | 107 | { |
106 | setvbuf(stdout, nullptr, _IONBF, 0); | 108 | setvbuf(stdout, nullptr, _IONBF, 0); |
107 | 109 | ||
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) | |||
29 | return s; | 29 | return s; |
30 | } | 30 | } |
31 | 31 | ||
32 | int main(int argc, char *argv[]) | 32 | int main(void) |
33 | { | 33 | { |
34 | setvbuf(stdout, nullptr, _IONBF, 0); | 34 | setvbuf(stdout, nullptr, _IONBF, 0); |
35 | 35 | ||
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) | |||
250 | return s; | 250 | return s; |
251 | } | 251 | } |
252 | 252 | ||
253 | int main(int argc, char *argv[]) | 253 | int main(void) |
254 | { | 254 | { |
255 | setvbuf(stdout, nullptr, _IONBF, 0); | 255 | setvbuf(stdout, nullptr, _IONBF, 0); |
256 | 256 | ||
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: | |||
130 | printf("test_many_clients succeeded, took %ld seconds\n", time(nullptr) - cur_time); | 130 | printf("test_many_clients succeeded, took %ld seconds\n", time(nullptr) - cur_time); |
131 | } | 131 | } |
132 | 132 | ||
133 | int main(int argc, char *argv[]) | 133 | int main(void) |
134 | { | 134 | { |
135 | setvbuf(stdout, nullptr, _IONBF, 0); | 135 | setvbuf(stdout, nullptr, _IONBF, 0); |
136 | 136 | ||
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) | |||
141 | return s; | 141 | return s; |
142 | } | 142 | } |
143 | 143 | ||
144 | int main(int argc, char *argv[]) | 144 | int main(void) |
145 | { | 145 | { |
146 | setvbuf(stdout, nullptr, _IONBF, 0); | 146 | setvbuf(stdout, nullptr, _IONBF, 0); |
147 | 147 | ||
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 { | |||
22 | 22 | ||
23 | static const char *Comparison_Str[] = { "NEGATIVE", "ZERO", "POSITIVE" }; | 23 | static const char *Comparison_Str[] = { "NEGATIVE", "ZERO", "POSITIVE" }; |
24 | 24 | ||
25 | void verify(const char *s1, const char *s2, size_t n, Comparison expected) | 25 | static void verify(const char *s1, const char *s2, size_t n, Comparison expected) |
26 | { | 26 | { |
27 | int r = tox_strncasecmp(s1, s2, n); | 27 | int r = tox_strncasecmp(s1, s2, n); |
28 | Comparison actual = r < 0 ? NEGATIVE : r == 0 ? ZERO : POSITIVE; | 28 | Comparison actual = r < 0 ? NEGATIVE : r == 0 ? ZERO : POSITIVE; |
@@ -177,7 +177,7 @@ static Suite *tox_strncasecmp_suite(void) | |||
177 | return s; | 177 | return s; |
178 | } | 178 | } |
179 | 179 | ||
180 | int main(int argc, char *argv[]) | 180 | int main(void) |
181 | { | 181 | { |
182 | setvbuf(stdout, nullptr, _IONBF, 0); | 182 | setvbuf(stdout, nullptr, _IONBF, 0); |
183 | 183 | ||
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) | |||
559 | printf("\nTest successful!\n"); | 559 | printf("\nTest successful!\n"); |
560 | } | 560 | } |
561 | 561 | ||
562 | int main(int argc, char *argv[]) | 562 | int main(void) |
563 | { | 563 | { |
564 | setvbuf(stdout, nullptr, _IONBF, 0); | 564 | setvbuf(stdout, nullptr, _IONBF, 0); |
565 | 565 | ||
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) | |||
326 | printf("\nTest successful!\n"); | 326 | printf("\nTest successful!\n"); |
327 | } | 327 | } |
328 | 328 | ||
329 | int main(int argc, char *argv[]) | 329 | int main(void) |
330 | { | 330 | { |
331 | setvbuf(stdout, nullptr, _IONBF, 0); | 331 | setvbuf(stdout, nullptr, _IONBF, 0); |
332 | 332 | ||
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) | |||
102 | tox_kill(tox2); | 102 | tox_kill(tox2); |
103 | } | 103 | } |
104 | 104 | ||
105 | int main(int argc, char *argv[]) | 105 | int main(void) |
106 | { | 106 | { |
107 | setvbuf(stdout, nullptr, _IONBF, 0); | 107 | setvbuf(stdout, nullptr, _IONBF, 0); |
108 | 108 | ||
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 @@ | |||
1 | CPPFLAGS="-DMIN_LOGGER_LEVEL=LOG_TRACE -Iauto_tests -Itoxcore -Itoxav -Itoxencryptsave `pkg-config --cflags libsodium opus vpx`" | ||
2 | |||
3 | put() { | ||
4 | if [ "$SKIP_LINES" = "" ]; then | ||
5 | echo "#line 1 \"$1\"" >> test.c | ||
6 | fi | ||
7 | cat $1 >> test.c | ||
8 | } | ||
9 | |||
10 | :> test.c | ||
11 | |||
12 | put toxcore/tox.c | ||
13 | |||
14 | put toxcore/DHT.c | ||
15 | put toxcore/LAN_discovery.c | ||
16 | put toxcore/Messenger.c | ||
17 | put toxcore/TCP_client.c | ||
18 | put toxcore/TCP_connection.c | ||
19 | put toxcore/TCP_server.c | ||
20 | put toxcore/crypto_core.c | ||
21 | put toxcore/crypto_core_mem.c | ||
22 | put toxcore/friend_connection.c | ||
23 | put toxcore/friend_requests.c | ||
24 | put toxcore/group.c | ||
25 | put toxcore/list.c | ||
26 | put toxcore/logger.c | ||
27 | put toxcore/network.c | ||
28 | put toxcore/net_crypto.c | ||
29 | put toxcore/onion.c | ||
30 | put toxcore/onion_announce.c | ||
31 | put toxcore/onion_client.c | ||
32 | put toxcore/ping.c | ||
33 | put toxcore/ping_array.c | ||
34 | put toxcore/tox_api.c | ||
35 | put toxcore/util.c | ||
36 | |||
37 | # Not included yet, since there are too many issues with this code. | ||
38 | #put toxav/audio.c | ||
39 | #put toxav/bwcontroller.c | ||
40 | #put toxav/groupav.c | ||
41 | #put toxav/msi.c | ||
42 | #put toxav/ring_buffer.c | ||
43 | #put toxav/rtp.c | ||
44 | #put toxav/toxav.c | ||
45 | #put toxav/toxav_old.c | ||
46 | #put toxav/video.c | ||
47 | |||
48 | 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 @@ | |||
1 | #!/bin/sh | ||
2 | |||
3 | . other/analysis/gen-file.sh | ||
4 | |||
5 | put auto_tests/lan_discovery_test.c | ||
6 | |||
7 | 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 @@ | |||
1 | #!/bin/sh | ||
2 | |||
3 | . other/analysis/gen-file.sh | ||
4 | |||
5 | put auto_tests/lan_discovery_test.c | ||
6 | |||
7 | 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 @@ | |||
1 | #!/bin/sh | ||
2 | |||
3 | . other/analysis/gen-file.sh | ||
4 | |||
5 | put auto_tests/lan_discovery_test.c | ||
6 | |||
7 | # TODO(iphydf): Get rid of all VLAs, then enable -fstack-protector -Wstack-protector | ||
8 | gcc -O3 -c -o /dev/null test.c $CPPFLAGS \ | ||
9 | -std=c99 \ | ||
10 | -pedantic \ | ||
11 | -Wall \ | ||
12 | -Wextra \ | ||
13 | -Wno-aggregate-return \ | ||
14 | -Wno-aggressive-loop-optimizations \ | ||
15 | -Wno-float-conversion \ | ||
16 | -Wno-format-signedness \ | ||
17 | -Wno-missing-field-initializers \ | ||
18 | -Wno-padded \ | ||
19 | -Wno-sign-compare \ | ||
20 | -Wno-sign-conversion \ | ||
21 | -Wno-switch-default \ | ||
22 | -Wno-unused-parameter \ | ||
23 | -Wstrict-aliasing=0 \ | ||
24 | -Wstrict-overflow=1 \ | ||
25 | \ | ||
26 | -Wbad-function-cast \ | ||
27 | -Wmissing-declarations \ | ||
28 | -Wmissing-parameter-type \ | ||
29 | -Wmissing-prototypes \ | ||
30 | -Wnested-externs \ | ||
31 | -Wold-style-declaration \ | ||
32 | -Wold-style-definition \ | ||
33 | -Wstrict-prototypes \ | ||
34 | -Wbool-compare \ | ||
35 | -Wc99-c11-compat \ | ||
36 | -Wc++-compat \ | ||
37 | -Wcast-align \ | ||
38 | -Wcast-qual \ | ||
39 | -Wchar-subscripts \ | ||
40 | -Wdouble-promotion \ | ||
41 | -Wduplicated-cond \ | ||
42 | -Wempty-body \ | ||
43 | -Wenum-compare \ | ||
44 | -Wfloat-equal \ | ||
45 | -Wformat=2 \ | ||
46 | -Wframe-address \ | ||
47 | -Wframe-larger-than=133168 \ | ||
48 | -Wjump-misses-init \ | ||
49 | -Wignored-qualifiers \ | ||
50 | -Wignored-attributes \ | ||
51 | -Wincompatible-pointer-types \ | ||
52 | -Winit-self \ | ||
53 | -Winline \ | ||
54 | -Wlarger-than=133120 \ | ||
55 | -Wmaybe-uninitialized \ | ||
56 | -Wmemset-transposed-args \ | ||
57 | -Wmisleading-indentation \ | ||
58 | -Wnonnull \ | ||
59 | -Wnonnull-compare \ | ||
60 | -Wnull-dereference \ | ||
61 | -Wodr \ | ||
62 | -Wredundant-decls \ | ||
63 | -Wreturn-type \ | ||
64 | -Wshadow \ | ||
65 | -Wsuggest-attribute=format \ | ||
66 | -Wundef \ | ||
67 | -Wunsafe-loop-optimizations \ | ||
68 | -Wunused-label \ | ||
69 | -Wunused-local-typedefs \ | ||
70 | -Wunused-value \ | ||
71 | -Wunused-but-set-parameter \ | ||
72 | -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 @@ | |||
1 | #!/bin/sh | ||
2 | |||
3 | # Infer ignores everything that's not in the "current file". | ||
4 | SKIP_LINES=1 | ||
5 | |||
6 | . other/analysis/gen-file.sh | ||
7 | |||
8 | put auto_tests/lan_discovery_test.c | ||
9 | |||
10 | 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 @@ | |||
1 | #!/bin/sh | ||
2 | |||
3 | . other/analysis/gen-file.sh | ||
4 | |||
5 | put auto_tests/lan_discovery_test.c | ||
6 | |||
7 | sparse test.c $CPPFLAGS \ | ||
8 | -Wsparse-all \ | ||
9 | -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[]) | |||
190 | FILE *file = fopen("Save.bak", "wb"); | 190 | FILE *file = fopen("Save.bak", "wb"); |
191 | 191 | ||
192 | if (file == nullptr) { | 192 | if (file == nullptr) { |
193 | kill_messenger(m); | ||
193 | return 1; | 194 | return 1; |
194 | } | 195 | } |
195 | 196 | ||
@@ -198,12 +199,11 @@ int main(int argc, char *argv[]) | |||
198 | size_t write_result = fwrite(buffer, 1, messenger_size(m), file); | 199 | size_t write_result = fwrite(buffer, 1, messenger_size(m), file); |
199 | 200 | ||
200 | if (write_result < messenger_size(m)) { | 201 | if (write_result < messenger_size(m)) { |
202 | kill_messenger(m); | ||
201 | return 1; | 203 | return 1; |
202 | } | 204 | } |
203 | 205 | ||
204 | free(buffer); | 206 | free(buffer); |
205 | fclose(file); | 207 | fclose(file); |
206 | } | 208 | } |
207 | |||
208 | kill_messenger(m); | ||
209 | } | 209 | } |
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 @@ | |||
47 | 47 | ||
48 | #include "../toxcore/ccompat.h" | 48 | #include "../toxcore/ccompat.h" |
49 | 49 | ||
50 | uint8_t *hex_string_to_bin(const char *hex_string); | ||
51 | int tox_strncasecmp(const char *s1, const char *s2, size_t n); | ||
52 | int cmdline_parsefor_ipv46(int argc, char **argv, uint8_t *ipv6enabled); | ||
53 | |||
50 | // You are responsible for freeing the return value! | 54 | // You are responsible for freeing the return value! |
51 | uint8_t *hex_string_to_bin(const char *hex_string) | 55 | uint8_t *hex_string_to_bin(const char *hex_string) |
52 | { | 56 | { |
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) | |||
121 | 121 | ||
122 | pthread_mutex_destroy(ac->queue_mutex); | 122 | pthread_mutex_destroy(ac->queue_mutex); |
123 | 123 | ||
124 | LOGGER_DEBUG(ac->log, "Terminated audio handler: %p", ac); | 124 | LOGGER_DEBUG(ac->log, "Terminated audio handler: %p", (void *)ac); |
125 | free(ac); | 125 | free(ac); |
126 | } | 126 | } |
127 | 127 | ||
@@ -315,7 +315,7 @@ static int jbuf_write(Logger *log, struct JitterBuffer *q, struct RTPMessage *m) | |||
315 | unsigned int num = sequnum % q->size; | 315 | unsigned int num = sequnum % q->size; |
316 | 316 | ||
317 | if ((uint32_t)(sequnum - q->bottom) > q->size) { | 317 | if ((uint32_t)(sequnum - q->bottom) > q->size) { |
318 | LOGGER_DEBUG(log, "Clearing filled jitter buffer: %p", q); | 318 | LOGGER_DEBUG(log, "Clearing filled jitter buffer: %p", (void *)q); |
319 | 319 | ||
320 | jbuf_clear(q); | 320 | jbuf_clear(q); |
321 | q->bottom = sequnum - q->capacity; | 321 | 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 @@ | |||
33 | 33 | ||
34 | #define BWC_PACKET_ID 196 | 34 | #define BWC_PACKET_ID 196 |
35 | #define BWC_SEND_INTERVAL_MS 950 /* 0.95s */ | 35 | #define BWC_SEND_INTERVAL_MS 950 /* 0.95s */ |
36 | #define BWC_REFRESH_INTERVAL_MS 2000 /* 2.00s */ | ||
37 | #define BWC_AVG_PKT_COUNT 20 | 36 | #define BWC_AVG_PKT_COUNT 20 |
38 | #define BWC_AVG_LOSS_OVER_CYCLES_COUNT 30 | 37 | #define BWC_AVG_LOSS_OVER_CYCLES_COUNT 30 |
39 | 38 | ||
@@ -137,8 +136,8 @@ void send_update(BWController *bwc) | |||
137 | 136 | ||
138 | if (bwc->cycle.lost) { | 137 | if (bwc->cycle.lost) { |
139 | LOGGER_DEBUG(bwc->m->log, "%p Sent update rcv: %u lost: %u percent: %f %%", | 138 | LOGGER_DEBUG(bwc->m->log, "%p Sent update rcv: %u lost: %u percent: %f %%", |
140 | bwc, bwc->cycle.recv, bwc->cycle.lost, | 139 | (void *)bwc, bwc->cycle.recv, bwc->cycle.lost, |
141 | (((float) bwc->cycle.lost / (bwc->cycle.recv + bwc->cycle.lost)) * 100.0f)); | 140 | (((double) bwc->cycle.lost / (bwc->cycle.recv + bwc->cycle.lost)) * 100.0)); |
142 | uint8_t bwc_packet[sizeof(struct BWCMessage) + 1]; | 141 | uint8_t bwc_packet[sizeof(struct BWCMessage) + 1]; |
143 | struct BWCMessage *msg = (struct BWCMessage *)(bwc_packet + 1); | 142 | struct BWCMessage *msg = (struct BWCMessage *)(bwc_packet + 1); |
144 | bwc_packet[0] = BWC_PACKET_ID; // set packet ID | 143 | bwc_packet[0] = BWC_PACKET_ID; // set packet ID |
@@ -146,7 +145,7 @@ void send_update(BWController *bwc) | |||
146 | msg->recv = net_htonl(bwc->cycle.recv); | 145 | msg->recv = net_htonl(bwc->cycle.recv); |
147 | 146 | ||
148 | if (-1 == m_send_custom_lossy_packet(bwc->m, bwc->friend_number, bwc_packet, sizeof(bwc_packet))) { | 147 | if (-1 == m_send_custom_lossy_packet(bwc->m, bwc->friend_number, bwc_packet, sizeof(bwc_packet))) { |
149 | LOGGER_WARNING(bwc->m->log, "BWC send failed (len: %d)! std error: %s", sizeof(bwc_packet), strerror(errno)); | 148 | LOGGER_WARNING(bwc->m->log, "BWC send failed (len: %zu)! std error: %s", sizeof(bwc_packet), strerror(errno)); |
150 | } | 149 | } |
151 | } | 150 | } |
152 | 151 | ||
@@ -158,11 +157,11 @@ void send_update(BWController *bwc) | |||
158 | 157 | ||
159 | static int on_update(BWController *bwc, const struct BWCMessage *msg) | 158 | static int on_update(BWController *bwc, const struct BWCMessage *msg) |
160 | { | 159 | { |
161 | LOGGER_DEBUG(bwc->m->log, "%p Got update from peer", bwc); | 160 | LOGGER_DEBUG(bwc->m->log, "%p Got update from peer", (void *)bwc); |
162 | 161 | ||
163 | /* Peers sent update too soon */ | 162 | /* Peers sent update too soon */ |
164 | if (bwc->cycle.last_recv_timestamp + BWC_SEND_INTERVAL_MS > current_time_monotonic()) { | 163 | if (bwc->cycle.last_recv_timestamp + BWC_SEND_INTERVAL_MS > current_time_monotonic()) { |
165 | LOGGER_INFO(bwc->m->log, "%p Rejecting extra update", bwc); | 164 | LOGGER_INFO(bwc->m->log, "%p Rejecting extra update", (void *)bwc); |
166 | return -1; | 165 | return -1; |
167 | } | 166 | } |
168 | 167 | ||
@@ -173,7 +172,7 @@ static int on_update(BWController *bwc, const struct BWCMessage *msg) | |||
173 | 172 | ||
174 | if (lost && bwc->mcb) { | 173 | if (lost && bwc->mcb) { |
175 | LOGGER_DEBUG(bwc->m->log, "recved: %u lost: %u percentage: %f %%", recv, lost, | 174 | LOGGER_DEBUG(bwc->m->log, "recved: %u lost: %u percentage: %f %%", recv, lost, |
176 | (((float) lost / (recv + lost)) * 100.0f)); | 175 | (((double) lost / (recv + lost)) * 100.0)); |
177 | bwc->mcb(bwc, bwc->friend_number, | 176 | bwc->mcb(bwc, bwc->friend_number, |
178 | ((float) lost / (recv + lost)), | 177 | ((float) lost / (recv + lost)), |
179 | bwc->mcb_data); | 178 | 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) | |||
128 | /* This is called when remote terminates session */ | 128 | /* This is called when remote terminates session */ |
129 | m_callback_connectionstatus_internal_av(m, on_peer_status, retu); | 129 | m_callback_connectionstatus_internal_av(m, on_peer_status, retu); |
130 | 130 | ||
131 | LOGGER_DEBUG(m->log, "New msi session: %p ", retu); | 131 | LOGGER_DEBUG(m->log, "New msi session: %p ", (void *)retu); |
132 | return retu; | 132 | return retu; |
133 | } | 133 | } |
134 | int msi_kill(MSISession *session, Logger *log) | 134 | int msi_kill(MSISession *session, Logger *log) |
@@ -162,7 +162,7 @@ int msi_kill(MSISession *session, Logger *log) | |||
162 | pthread_mutex_unlock(session->mutex); | 162 | pthread_mutex_unlock(session->mutex); |
163 | pthread_mutex_destroy(session->mutex); | 163 | pthread_mutex_destroy(session->mutex); |
164 | 164 | ||
165 | LOGGER_DEBUG(session->messenger->log, "Terminated session: %p", session); | 165 | LOGGER_DEBUG(session->messenger->log, "Terminated session: %p", (void *)session); |
166 | free(session); | 166 | free(session); |
167 | return 0; | 167 | return 0; |
168 | } | 168 | } |
@@ -172,7 +172,7 @@ int msi_invite(MSISession *session, MSICall **call, uint32_t friend_number, uint | |||
172 | return -1; | 172 | return -1; |
173 | } | 173 | } |
174 | 174 | ||
175 | LOGGER_DEBUG(session->messenger->log, "Session: %p Inviting friend: %u", session, friend_number); | 175 | LOGGER_DEBUG(session->messenger->log, "Session: %p Inviting friend: %u", (void *)session, friend_number); |
176 | 176 | ||
177 | if (pthread_mutex_trylock(session->mutex) != 0) { | 177 | if (pthread_mutex_trylock(session->mutex) != 0) { |
178 | LOGGER_ERROR(session->messenger->log, "Failed to acquire lock on msi mutex"); | 178 | LOGGER_ERROR(session->messenger->log, "Failed to acquire lock on msi mutex"); |
@@ -216,7 +216,7 @@ int msi_hangup(MSICall *call) | |||
216 | 216 | ||
217 | MSISession *session = call->session; | 217 | MSISession *session = call->session; |
218 | 218 | ||
219 | LOGGER_DEBUG(session->messenger->log, "Session: %p Hanging up call with friend: %u", call->session, | 219 | LOGGER_DEBUG(session->messenger->log, "Session: %p Hanging up call with friend: %u", (void *)call->session, |
220 | call->friend_number); | 220 | call->friend_number); |
221 | 221 | ||
222 | if (pthread_mutex_trylock(session->mutex) != 0) { | 222 | if (pthread_mutex_trylock(session->mutex) != 0) { |
@@ -247,7 +247,8 @@ int msi_answer(MSICall *call, uint8_t capabilities) | |||
247 | 247 | ||
248 | MSISession *session = call->session; | 248 | MSISession *session = call->session; |
249 | 249 | ||
250 | LOGGER_DEBUG(session->messenger->log, "Session: %p Answering call from: %u", call->session, call->friend_number); | 250 | LOGGER_DEBUG(session->messenger->log, "Session: %p Answering call from: %u", (void *)call->session, |
251 | call->friend_number); | ||
251 | 252 | ||
252 | if (pthread_mutex_trylock(session->mutex) != 0) { | 253 | if (pthread_mutex_trylock(session->mutex) != 0) { |
253 | LOGGER_ERROR(session->messenger->log, "Failed to acquire lock on msi mutex"); | 254 | 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) | |||
285 | 286 | ||
286 | MSISession *session = call->session; | 287 | MSISession *session = call->session; |
287 | 288 | ||
288 | LOGGER_DEBUG(session->messenger->log, "Session: %p Trying to change capabilities to friend %u", call->session, | 289 | LOGGER_DEBUG(session->messenger->log, "Session: %p Trying to change capabilities to friend %u", (void *)call->session, |
289 | call->friend_number); | 290 | call->friend_number); |
290 | 291 | ||
291 | if (pthread_mutex_trylock(session->mutex) != 0) { | 292 | 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 | |||
340 | bytes += 3; \ | 341 | bytes += 3; \ |
341 | } while(0) | 342 | } while(0) |
342 | 343 | ||
343 | #define SET_UINT16(bytes, header) do { \ | ||
344 | memcpy(&header.value, bytes + 2, 2);\ | ||
345 | header.exists = true; \ | ||
346 | bytes += 4; \ | ||
347 | } while(0) | ||
348 | |||
349 | |||
350 | assert(dest); | 344 | assert(dest); |
351 | 345 | ||
352 | if (length == 0 || data[length - 1]) { /* End byte must have value 0 */ | 346 | 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 | |||
394 | #undef CHECK_SIZE | 388 | #undef CHECK_SIZE |
395 | #undef CHECK_ENUM_HIGH | 389 | #undef CHECK_ENUM_HIGH |
396 | #undef SET_UINT8 | 390 | #undef SET_UINT8 |
397 | #undef SET_UINT16 | ||
398 | } | 391 | } |
399 | uint8_t *msg_parse_header_out(MSIHeaderID id, uint8_t *dest, const void *value, uint8_t value_len, uint16_t *length) | 392 | uint8_t *msg_parse_header_out(MSIHeaderID id, uint8_t *dest, const void *value, uint8_t value_len, uint16_t *length) |
400 | { | 393 | { |
@@ -573,7 +566,7 @@ void kill_call(MSICall *call) | |||
573 | 566 | ||
574 | MSISession *session = call->session; | 567 | MSISession *session = call->session; |
575 | 568 | ||
576 | LOGGER_DEBUG(session->messenger->log, "Killing call: %p", call); | 569 | LOGGER_DEBUG(session->messenger->log, "Killing call: %p", (void *)call); |
577 | 570 | ||
578 | MSICall *prev = call->prev; | 571 | MSICall *prev = call->prev; |
579 | MSICall *next = call->next; | 572 | MSICall *next = call->next; |
@@ -635,10 +628,10 @@ void handle_init(MSICall *call, const MSIMessage *msg) | |||
635 | { | 628 | { |
636 | assert(call); | 629 | assert(call); |
637 | LOGGER_DEBUG(call->session->messenger->log, | 630 | LOGGER_DEBUG(call->session->messenger->log, |
638 | "Session: %p Handling 'init' friend: %d", call->session, call->friend_number); | 631 | "Session: %p Handling 'init' friend: %d", (void *)call->session, call->friend_number); |
639 | 632 | ||
640 | if (!msg->capabilities.exists) { | 633 | if (!msg->capabilities.exists) { |
641 | LOGGER_WARNING(call->session->messenger->log, "Session: %p Invalid capabilities on 'init'"); | 634 | LOGGER_WARNING(call->session->messenger->log, "Session: %p Invalid capabilities on 'init'", (void *)call->session); |
642 | call->error = msi_EInvalidMessage; | 635 | call->error = msi_EInvalidMessage; |
643 | goto FAILURE; | 636 | goto FAILURE; |
644 | } | 637 | } |
@@ -681,7 +674,7 @@ void handle_init(MSICall *call, const MSIMessage *msg) | |||
681 | 674 | ||
682 | case msi_CallRequested: // fall-through | 675 | case msi_CallRequested: // fall-through |
683 | case msi_CallRequesting: { | 676 | case msi_CallRequesting: { |
684 | LOGGER_WARNING(call->session->messenger->log, "Session: %p Invalid state on 'init'"); | 677 | LOGGER_WARNING(call->session->messenger->log, "Session: %p Invalid state on 'init'", (void *)call->session); |
685 | call->error = msi_EInvalidState; | 678 | call->error = msi_EInvalidState; |
686 | goto FAILURE; | 679 | goto FAILURE; |
687 | } | 680 | } |
@@ -696,11 +689,11 @@ void handle_push(MSICall *call, const MSIMessage *msg) | |||
696 | { | 689 | { |
697 | assert(call); | 690 | assert(call); |
698 | 691 | ||
699 | LOGGER_DEBUG(call->session->messenger->log, "Session: %p Handling 'push' friend: %d", call->session, | 692 | LOGGER_DEBUG(call->session->messenger->log, "Session: %p Handling 'push' friend: %d", (void *)call->session, |
700 | call->friend_number); | 693 | call->friend_number); |
701 | 694 | ||
702 | if (!msg->capabilities.exists) { | 695 | if (!msg->capabilities.exists) { |
703 | LOGGER_WARNING(call->session->messenger->log, "Session: %p Invalid capabilities on 'push'"); | 696 | LOGGER_WARNING(call->session->messenger->log, "Session: %p Invalid capabilities on 'push'", (void *)call->session); |
704 | call->error = msi_EInvalidMessage; | 697 | call->error = msi_EInvalidMessage; |
705 | goto FAILURE; | 698 | goto FAILURE; |
706 | } | 699 | } |
@@ -751,7 +744,7 @@ void handle_pop(MSICall *call, const MSIMessage *msg) | |||
751 | { | 744 | { |
752 | assert(call); | 745 | assert(call); |
753 | 746 | ||
754 | LOGGER_DEBUG(call->session->messenger->log, "Session: %p Handling 'pop', friend id: %d", call->session, | 747 | LOGGER_DEBUG(call->session->messenger->log, "Session: %p Handling 'pop', friend id: %d", (void *)call->session, |
755 | call->friend_number); | 748 | call->friend_number); |
756 | 749 | ||
757 | /* callback errors are ignored */ | 750 | /* 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) | |||
694 | return; | 694 | return; |
695 | } | 695 | } |
696 | 696 | ||
697 | LOGGER_DEBUG(session->m->log, "Terminated RTP session: %p", session); | 697 | LOGGER_DEBUG(session->m->log, "Terminated RTP session: %p", (void *)session); |
698 | rtp_stop_receiving(session); | 698 | rtp_stop_receiving(session); |
699 | 699 | ||
700 | LOGGER_DEBUG(session->m->log, "Terminated RTP session V3 work_buffer_list->next_free_entry: %d", | 700 | 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) | |||
716 | return -1; | 716 | return -1; |
717 | } | 717 | } |
718 | 718 | ||
719 | LOGGER_DEBUG(session->m->log, "Started receiving on session: %p", session); | 719 | LOGGER_DEBUG(session->m->log, "Started receiving on session: %p", (void *)session); |
720 | return 0; | 720 | return 0; |
721 | } | 721 | } |
722 | 722 | ||
@@ -728,7 +728,7 @@ int rtp_stop_receiving(RTPSession *session) | |||
728 | 728 | ||
729 | m_callback_rtp_packet(session->m, session->friend_number, session->payload_type, nullptr, nullptr); | 729 | m_callback_rtp_packet(session->m, session->friend_number, session->payload_type, nullptr, nullptr); |
730 | 730 | ||
731 | LOGGER_DEBUG(session->m->log, "Stopped receiving on session: %p", session); | 731 | LOGGER_DEBUG(session->m->log, "Stopped receiving on session: %p", (void *)session); |
732 | return 0; | 732 | return 0; |
733 | } | 733 | } |
734 | 734 | ||
@@ -744,12 +744,6 @@ int rtp_send_data(RTPSession *session, const uint8_t *data, uint32_t length, | |||
744 | return -1; | 744 | return -1; |
745 | } | 745 | } |
746 | 746 | ||
747 | uint8_t is_video_payload = 0; | ||
748 | |||
749 | if (session->payload_type == rtp_TypeVideo) { | ||
750 | is_video_payload = 1; | ||
751 | } | ||
752 | |||
753 | struct RTPHeader header = {0}; | 747 | struct RTPHeader header = {0}; |
754 | 748 | ||
755 | header.ve = 2; // this is unused in toxav | 749 | 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, | |||
805 | memcpy(rdata + 1 + RTP_HEADER_SIZE, data, length); | 799 | memcpy(rdata + 1 + RTP_HEADER_SIZE, data, length); |
806 | 800 | ||
807 | if (-1 == m_send_custom_lossy_packet(session->m, session->friend_number, rdata, SIZEOF_VLA(rdata))) { | 801 | if (-1 == m_send_custom_lossy_packet(session->m, session->friend_number, rdata, SIZEOF_VLA(rdata))) { |
808 | LOGGER_WARNING(session->m->log, "RTP send failed (len: %d)! std error: %s", SIZEOF_VLA(rdata), strerror(errno)); | 802 | LOGGER_WARNING(session->m->log, "RTP send failed (len: %zu)! std error: %s", SIZEOF_VLA(rdata), strerror(errno)); |
809 | } | 803 | } |
810 | } else { | 804 | } else { |
811 | /** | 805 | /** |
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 | |||
950 | ToxAVCall *call = (ToxAVCall *)user_data; | 950 | ToxAVCall *call = (ToxAVCall *)user_data; |
951 | assert(call); | 951 | assert(call); |
952 | 952 | ||
953 | LOGGER_DEBUG(call->av->m->log, "Reported loss of %f%%", loss * 100); | 953 | LOGGER_DEBUG(call->av->m->log, "Reported loss of %f%%", (double)loss * 100); |
954 | 954 | ||
955 | /* if less than 10% data loss we do nothing! */ | 955 | /* if less than 10% data loss we do nothing! */ |
956 | if (loss < 0.1f) { | 956 | 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 @@ | |||
76 | #define VIDEO_CODEC_DECODER_MAX_WIDTH 800 // its a dummy value, because the struct needs a value there | 76 | #define VIDEO_CODEC_DECODER_MAX_WIDTH 800 // its a dummy value, because the struct needs a value there |
77 | #define VIDEO_CODEC_DECODER_MAX_HEIGHT 600 // its a dummy value, because the struct needs a value there | 77 | #define VIDEO_CODEC_DECODER_MAX_HEIGHT 600 // its a dummy value, because the struct needs a value there |
78 | 78 | ||
79 | #define VPX_MAX_DIST_NORMAL 40 | ||
80 | #define VPX_MAX_DIST_START 40 | 79 | #define VPX_MAX_DIST_START 40 |
81 | 80 | ||
82 | #define VPX_MAX_ENCODER_THREADS 4 | 81 | #define VPX_MAX_ENCODER_THREADS 4 |
83 | #define VPX_MAX_DECODER_THREADS 4 | 82 | #define VPX_MAX_DECODER_THREADS 4 |
84 | #define VIDEO__VP8_DECODER_POST_PROCESSING_ENABLED 0 | 83 | #define VIDEO__VP8_DECODER_POST_PROCESSING_ENABLED 0 |
85 | 84 | ||
86 | void vc_init_encoder_cfg(Logger *log, vpx_codec_enc_cfg_t *cfg, int16_t kf_max_dist) | 85 | static void vc_init_encoder_cfg(Logger *log, vpx_codec_enc_cfg_t *cfg, int16_t kf_max_dist) |
87 | { | 86 | { |
88 | vpx_codec_err_t rc = vpx_codec_enc_config_default(VIDEO_CODEC_ENCODER_INTERFACE, cfg, 0); | 87 | vpx_codec_err_t rc = vpx_codec_enc_config_default(VIDEO_CODEC_ENCODER_INTERFACE, cfg, 0); |
89 | 88 | ||
@@ -288,7 +287,7 @@ void vc_kill(VCSession *vc) | |||
288 | 287 | ||
289 | rb_kill((RingBuffer *)vc->vbuf_raw); | 288 | rb_kill((RingBuffer *)vc->vbuf_raw); |
290 | pthread_mutex_destroy(vc->queue_mutex); | 289 | pthread_mutex_destroy(vc->queue_mutex); |
291 | LOGGER_DEBUG(vc->log, "Terminated video handler: %p", vc); | 290 | LOGGER_DEBUG(vc->log, "Terminated video handler: %p", (void *)vc); |
292 | free(vc); | 291 | free(vc); |
293 | } | 292 | } |
294 | 293 | ||
@@ -417,7 +416,7 @@ int vc_reconfigure_encoder(VCSession *vc, uint32_t bit_rate, uint16_t width, uin | |||
417 | /* Resolution is changed, must reinitialize encoder since libvpx v1.4 doesn't support | 416 | /* Resolution is changed, must reinitialize encoder since libvpx v1.4 doesn't support |
418 | * reconfiguring encoder to use resolutions greater than initially set. | 417 | * reconfiguring encoder to use resolutions greater than initially set. |
419 | */ | 418 | */ |
420 | LOGGER_DEBUG(vc->log, "Have to reinitialize vpx encoder on session %p", vc); | 419 | LOGGER_DEBUG(vc->log, "Have to reinitialize vpx encoder on session %p", (void *)vc); |
421 | vpx_codec_ctx_t new_c; | 420 | vpx_codec_ctx_t new_c; |
422 | vpx_codec_enc_cfg_t cfg; | 421 | vpx_codec_enc_cfg_t cfg; |
423 | vc_init_encoder_cfg(vc->log, &cfg, kf_max_dist); | 422 | 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( | |||
48 | name = "logger", | 48 | name = "logger", |
49 | srcs = ["logger.c"], | 49 | srcs = ["logger.c"], |
50 | hdrs = ["logger.h"], | 50 | hdrs = ["logger.h"], |
51 | deps = [":ccompat"], | ||
51 | ) | 52 | ) |
52 | 53 | ||
53 | cc_library( | 54 | cc_library( |
@@ -100,9 +101,6 @@ cc_library( | |||
100 | "LAN_discovery.h", | 101 | "LAN_discovery.h", |
101 | "ping.h", | 102 | "ping.h", |
102 | ], | 103 | ], |
103 | copts = [ | ||
104 | "-Wno-parentheses", | ||
105 | ], | ||
106 | visibility = ["//c-toxcore/other/bootstrap_daemon:__pkg__"], | 104 | visibility = ["//c-toxcore/other/bootstrap_daemon:__pkg__"], |
107 | deps = [ | 105 | deps = [ |
108 | ":crypto_core", | 106 | ":crypto_core", |
@@ -205,9 +203,6 @@ cc_library( | |||
205 | "tox.h", | 203 | "tox.h", |
206 | "tox_api.c", | 204 | "tox_api.c", |
207 | ], | 205 | ], |
208 | copts = [ | ||
209 | "-Wno-parentheses", | ||
210 | ], | ||
211 | visibility = ["//c-toxcore:__subpackages__"], | 206 | visibility = ["//c-toxcore:__subpackages__"], |
212 | deps = [ | 207 | deps = [ |
213 | ":group", | 208 | ":group", |
@@ -221,9 +216,6 @@ cc_library( | |||
221 | "*.c", | 216 | "*.c", |
222 | "*.h", | 217 | "*.h", |
223 | ]), | 218 | ]), |
224 | copts = [ | ||
225 | "-Wno-parentheses", | ||
226 | ], | ||
227 | linkopts = ["-lpthread"], | 219 | linkopts = ["-lpthread"], |
228 | visibility = ["//c-toxcore/other:__pkg__"], | 220 | visibility = ["//c-toxcore/other:__pkg__"], |
229 | deps = [ | 221 | 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 | |||
615 | static uint32_t index_of_client_ip_port(const Client_data *array, uint32_t size, const IP_Port *ip_port) | 615 | static uint32_t index_of_client_ip_port(const Client_data *array, uint32_t size, const IP_Port *ip_port) |
616 | { | 616 | { |
617 | for (uint32_t i = 0; i < size; ++i) { | 617 | for (uint32_t i = 0; i < size; ++i) { |
618 | if (ip_port->ip.family == TOX_AF_INET && ipport_equal(&array[i].assoc4.ip_port, ip_port) || | 618 | if ((ip_port->ip.family == TOX_AF_INET && ipport_equal(&array[i].assoc4.ip_port, ip_port)) || |
619 | ip_port->ip.family == TOX_AF_INET6 && ipport_equal(&array[i].assoc6.ip_port, ip_port)) { | 619 | (ip_port->ip.family == TOX_AF_INET6 && ipport_equal(&array[i].assoc6.ip_port, ip_port))) { |
620 | return i; | 620 | return i; |
621 | } | 621 | } |
622 | } | 622 | } |
@@ -1084,18 +1084,20 @@ static bool ping_node_from_getnodes_ok(DHT *dht, const uint8_t *public_key, IP_P | |||
1084 | ret = true; | 1084 | ret = true; |
1085 | } | 1085 | } |
1086 | 1086 | ||
1087 | unsigned int *const num = &dht->num_to_bootstrap; | 1087 | { |
1088 | const uint32_t index = index_of_node_pk(dht->to_bootstrap, *num, public_key); | 1088 | unsigned int *const num = &dht->num_to_bootstrap; |
1089 | const bool in_close_list = is_pk_in_close_list(dht, public_key, ip_port); | 1089 | const uint32_t index = index_of_node_pk(dht->to_bootstrap, *num, public_key); |
1090 | const bool in_close_list = is_pk_in_close_list(dht, public_key, ip_port); | ||
1090 | 1091 | ||
1091 | if (ret && index == UINT32_MAX && !in_close_list) { | 1092 | if (ret && index == UINT32_MAX && !in_close_list) { |
1092 | if (*num < MAX_CLOSE_TO_BOOTSTRAP_NODES) { | 1093 | if (*num < MAX_CLOSE_TO_BOOTSTRAP_NODES) { |
1093 | memcpy(dht->to_bootstrap[*num].public_key, public_key, CRYPTO_PUBLIC_KEY_SIZE); | 1094 | memcpy(dht->to_bootstrap[*num].public_key, public_key, CRYPTO_PUBLIC_KEY_SIZE); |
1094 | dht->to_bootstrap[*num].ip_port = ip_port; | 1095 | dht->to_bootstrap[*num].ip_port = ip_port; |
1095 | ++*num; | 1096 | ++*num; |
1096 | } else { | 1097 | } else { |
1097 | // TODO(irungentoo): ipv6 vs v4 | 1098 | // TODO(irungentoo): ipv6 vs v4 |
1098 | add_to_list(dht->to_bootstrap, MAX_CLOSE_TO_BOOTSTRAP_NODES, public_key, ip_port, dht->self_public_key); | 1099 | add_to_list(dht->to_bootstrap, MAX_CLOSE_TO_BOOTSTRAP_NODES, public_key, ip_port, dht->self_public_key); |
1100 | } | ||
1099 | } | 1101 | } |
1100 | } | 1102 | } |
1101 | 1103 | ||
@@ -1655,8 +1657,8 @@ static uint8_t do_ping_and_sendnode_requests(DHT *dht, uint64_t *lastgetnode, co | |||
1655 | 1657 | ||
1656 | IPPTsPng *assocs[ASSOC_COUNT] = { &client->assoc6, &client->assoc4 }; | 1658 | IPPTsPng *assocs[ASSOC_COUNT] = { &client->assoc6, &client->assoc4 }; |
1657 | 1659 | ||
1658 | for (size_t i = 0; i < ASSOC_COUNT; i++) { | 1660 | for (size_t j = 0; j < ASSOC_COUNT; j++) { |
1659 | IPPTsPng *assoc = assocs[i]; | 1661 | IPPTsPng *assoc = assocs[j]; |
1660 | 1662 | ||
1661 | if (!is_timeout(assoc->timestamp, KILL_NODE_TIMEOUT)) { | 1663 | if (!is_timeout(assoc->timestamp, KILL_NODE_TIMEOUT)) { |
1662 | sort = 0; | 1664 | sort = 0; |
@@ -1677,7 +1679,7 @@ static uint8_t do_ping_and_sendnode_requests(DHT *dht, uint64_t *lastgetnode, co | |||
1677 | ++sort; | 1679 | ++sort; |
1678 | 1680 | ||
1679 | /* Timed out should be at beginning, if they are not, sort the list. */ | 1681 | /* Timed out should be at beginning, if they are not, sort the list. */ |
1680 | if (sort > 1 && sort < (((i + 1) * 2) - 1)) { | 1682 | if (sort > 1 && sort < (((j + 1) * 2) - 1)) { |
1681 | sort_ok = true; | 1683 | sort_ok = true; |
1682 | } | 1684 | } |
1683 | } | 1685 | } |
@@ -2237,14 +2239,17 @@ static void do_NAT(DHT *dht) | |||
2237 | /*----------------------------------------------------------------------------------*/ | 2239 | /*----------------------------------------------------------------------------------*/ |
2238 | /*-----------------------END OF NAT PUNCHING FUNCTIONS------------------------------*/ | 2240 | /*-----------------------END OF NAT PUNCHING FUNCTIONS------------------------------*/ |
2239 | 2241 | ||
2242 | #define DHT_HARDENING 0 | ||
2240 | #define HARDREQ_DATA_SIZE 384 /* Attempt to prevent amplification/other attacks*/ | 2243 | #define HARDREQ_DATA_SIZE 384 /* Attempt to prevent amplification/other attacks*/ |
2241 | 2244 | ||
2242 | #define CHECK_TYPE_ROUTE_REQ 0 | 2245 | enum { |
2243 | #define CHECK_TYPE_ROUTE_RES 1 | 2246 | CHECK_TYPE_ROUTE_REQ = 0, |
2244 | #define CHECK_TYPE_GETNODE_REQ 2 | 2247 | CHECK_TYPE_ROUTE_RES = 1, |
2245 | #define CHECK_TYPE_GETNODE_RES 3 | 2248 | CHECK_TYPE_GETNODE_REQ = 2, |
2246 | #define CHECK_TYPE_TEST_REQ 4 | 2249 | CHECK_TYPE_GETNODE_RES = 3, |
2247 | #define CHECK_TYPE_TEST_RES 5 | 2250 | CHECK_TYPE_TEST_REQ = 4, |
2251 | CHECK_TYPE_TEST_RES = 5, | ||
2252 | }; | ||
2248 | 2253 | ||
2249 | #if DHT_HARDENING | 2254 | #if DHT_HARDENING |
2250 | static int send_hardening_req(DHT *dht, Node_format *sendto, uint8_t type, uint8_t *contents, uint16_t length) | 2255 | 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) | |||
2350 | 2355 | ||
2351 | /* Interval in seconds between hardening checks */ | 2356 | /* Interval in seconds between hardening checks */ |
2352 | #define HARDENING_INTERVAL 120 | 2357 | #define HARDENING_INTERVAL 120 |
2353 | #define HARDEN_TIMEOUT 1200 | ||
2354 | 2358 | ||
2355 | /* Handle a received hardening packet */ | 2359 | /* Handle a received hardening packet */ |
2356 | static int handle_hardening(void *object, IP_Port source, const uint8_t *source_pubkey, const uint8_t *packet, | 2360 | 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_ | |||
2429 | } | 2433 | } |
2430 | 2434 | ||
2431 | #if DHT_HARDENING | 2435 | #if DHT_HARDENING |
2436 | #define HARDEN_TIMEOUT 1200 | ||
2437 | |||
2432 | /* Return a random node from all the nodes we are connected to. | 2438 | /* Return a random node from all the nodes we are connected to. |
2433 | * TODO(irungentoo): improve this function. | 2439 | * TODO(irungentoo): improve this function. |
2434 | */ | 2440 | */ |
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) | |||
156 | * a larger array, not done (640kB and 16 interfaces shall be | 156 | * a larger array, not done (640kB and 16 interfaces shall be |
157 | * enough, for everybody!) | 157 | * enough, for everybody!) |
158 | */ | 158 | */ |
159 | int i, n = ifconf.ifc_len / sizeof(struct ifreq); | 159 | int n = ifconf.ifc_len / sizeof(struct ifreq); |
160 | 160 | ||
161 | for (i = 0; i < n; i++) { | 161 | for (int i = 0; i < n; i++) { |
162 | /* there are interfaces with are incapable of broadcast */ | 162 | /* there are interfaces with are incapable of broadcast */ |
163 | if (ioctl(sock, SIOCGIFBRDADDR, &i_faces[i]) < 0) { | 163 | if (ioctl(sock, SIOCGIFBRDADDR, &i_faces[i]) < 0) { |
164 | continue; | 164 | 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 @@ | |||
33 | 33 | ||
34 | #include <assert.h> | 34 | #include <assert.h> |
35 | 35 | ||
36 | static void set_friend_status(Messenger *m, int32_t friendnumber, uint8_t status, void *userdata); | ||
37 | static int write_cryptpacket_id(const Messenger *m, int32_t friendnumber, uint8_t packet_id, const uint8_t *data, | 36 | static int write_cryptpacket_id(const Messenger *m, int32_t friendnumber, uint8_t packet_id, const uint8_t *data, |
38 | uint32_t length, uint8_t congestion_control); | 37 | uint32_t length, uint8_t congestion_control); |
39 | 38 | ||
@@ -949,7 +948,7 @@ static void check_friend_connectionstatus(Messenger *m, int32_t friendnumber, ui | |||
949 | } | 948 | } |
950 | } | 949 | } |
951 | 950 | ||
952 | void set_friend_status(Messenger *m, int32_t friendnumber, uint8_t status, void *userdata) | 951 | static void set_friend_status(Messenger *m, int32_t friendnumber, uint8_t status, void *userdata) |
953 | { | 952 | { |
954 | check_friend_connectionstatus(m, friendnumber, status, userdata); | 953 | check_friend_connectionstatus(m, friendnumber, status, userdata); |
955 | m->friendlist[friendnumber].status = status; | 954 | m->friendlist[friendnumber].status = status; |
@@ -1825,13 +1824,13 @@ static int m_handle_custom_lossy_packet(void *object, int friend_num, const uint | |||
1825 | return 1; | 1824 | return 1; |
1826 | } | 1825 | } |
1827 | 1826 | ||
1828 | void custom_lossy_packet_registerhandler(Messenger *m, void (*packet_handler_callback)(Messenger *m, | 1827 | void custom_lossy_packet_registerhandler(Messenger *m, void (*lossy_packethandler)(Messenger *m, |
1829 | uint32_t friendnumber, const uint8_t *data, size_t len, void *object)) | 1828 | uint32_t friendnumber, const uint8_t *data, size_t len, void *object)) |
1830 | { | 1829 | { |
1831 | m->lossy_packethandler = packet_handler_callback; | 1830 | m->lossy_packethandler = lossy_packethandler; |
1832 | } | 1831 | } |
1833 | 1832 | ||
1834 | int m_callback_rtp_packet(Messenger *m, int32_t friendnumber, uint8_t byte, int (*packet_handler_callback)(Messenger *m, | 1833 | int m_callback_rtp_packet(Messenger *m, int32_t friendnumber, uint8_t byte, int (*function)(Messenger *m, |
1835 | uint32_t friendnumber, const uint8_t *data, uint16_t len, void *object), void *object) | 1834 | uint32_t friendnumber, const uint8_t *data, uint16_t len, void *object), void *object) |
1836 | { | 1835 | { |
1837 | if (friend_not_valid(m, friendnumber)) { | 1836 | if (friend_not_valid(m, friendnumber)) { |
@@ -1846,8 +1845,7 @@ int m_callback_rtp_packet(Messenger *m, int32_t friendnumber, uint8_t byte, int | |||
1846 | return -1; | 1845 | return -1; |
1847 | } | 1846 | } |
1848 | 1847 | ||
1849 | m->friendlist[friendnumber].lossy_rtp_packethandlers[byte % PACKET_LOSSY_AV_RESERVED].function = | 1848 | m->friendlist[friendnumber].lossy_rtp_packethandlers[byte % PACKET_LOSSY_AV_RESERVED].function = function; |
1850 | packet_handler_callback; | ||
1851 | m->friendlist[friendnumber].lossy_rtp_packethandlers[byte % PACKET_LOSSY_AV_RESERVED].object = object; | 1849 | m->friendlist[friendnumber].lossy_rtp_packethandlers[byte % PACKET_LOSSY_AV_RESERVED].object = object; |
1852 | return 0; | 1850 | return 0; |
1853 | } | 1851 | } |
@@ -1907,10 +1905,10 @@ static int handle_custom_lossless_packet(void *object, int friend_num, const uin | |||
1907 | return 1; | 1905 | return 1; |
1908 | } | 1906 | } |
1909 | 1907 | ||
1910 | void custom_lossless_packet_registerhandler(Messenger *m, void (*packet_handler_callback)(Messenger *m, | 1908 | void custom_lossless_packet_registerhandler(Messenger *m, void (*lossless_packethandler)(Messenger *m, |
1911 | uint32_t friendnumber, const uint8_t *data, size_t len, void *object)) | 1909 | uint32_t friendnumber, const uint8_t *data, size_t len, void *object)) |
1912 | { | 1910 | { |
1913 | m->lossless_packethandler = packet_handler_callback; | 1911 | m->lossless_packethandler = lossless_packethandler; |
1914 | } | 1912 | } |
1915 | 1913 | ||
1916 | int send_custom_lossless_packet(const Messenger *m, int32_t friendnumber, const uint8_t *data, uint32_t length) | 1914 | 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 { | |||
2765 | uint64_t last_seen_time; | 2763 | uint64_t last_seen_time; |
2766 | }; | 2764 | }; |
2767 | 2765 | ||
2768 | static uint32_t friend_size() | 2766 | static uint32_t friend_size(void) |
2769 | { | 2767 | { |
2770 | uint32_t data = 0; | 2768 | uint32_t data = 0; |
2771 | const struct SAVED_FRIEND *const temp = nullptr; | 2769 | 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 @@ | |||
37 | /* This cannot be bigger than 256 */ | 37 | /* This cannot be bigger than 256 */ |
38 | #define MAX_CONCURRENT_FILE_PIPES 256 | 38 | #define MAX_CONCURRENT_FILE_PIPES 256 |
39 | 39 | ||
40 | #if MAX_CONCURRENT_FILE_PIPES > UINT8_MAX + 1 | 40 | #if !defined(__SPLINT__) && MAX_CONCURRENT_FILE_PIPES > UINT8_MAX + 1 |
41 | #error "uint8_t cannot represent all file transfer numbers" | 41 | #error "uint8_t cannot represent all file transfer numbers" |
42 | #endif | 42 | #endif |
43 | 43 | ||
@@ -74,13 +74,13 @@ enum { | |||
74 | #define PACKET_LOSSY_AV_RESERVED 8 /* Number of lossy packet types at start of range reserved for A/V. */ | 74 | #define PACKET_LOSSY_AV_RESERVED 8 /* Number of lossy packet types at start of range reserved for A/V. */ |
75 | 75 | ||
76 | typedef struct { | 76 | typedef struct { |
77 | uint8_t ipv6enabled; | 77 | bool ipv6enabled; |
78 | uint8_t udp_disabled; | 78 | bool udp_disabled; |
79 | TCP_Proxy_Info proxy_info; | 79 | TCP_Proxy_Info proxy_info; |
80 | uint16_t port_range[2]; | 80 | uint16_t port_range[2]; |
81 | uint16_t tcp_server_port; | 81 | uint16_t tcp_server_port; |
82 | 82 | ||
83 | uint8_t hole_punching_enabled; | 83 | bool hole_punching_enabled; |
84 | bool local_discovery_enabled; | 84 | bool local_discovery_enabled; |
85 | 85 | ||
86 | logger_cb *log_callback; | 86 | 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) | |||
110 | { | 110 | { |
111 | con->custom_object = object; | 111 | con->custom_object = object; |
112 | } | 112 | } |
113 | void tcp_con_set_custom_uint(TCP_Client_Connection *con, uint32_t uint) | 113 | void tcp_con_set_custom_uint(TCP_Client_Connection *con, uint32_t value) |
114 | { | 114 | { |
115 | con->custom_uint = uint; | 115 | con->custom_uint = value; |
116 | } | 116 | } |
117 | 117 | ||
118 | /* return 1 on success | 118 | /* 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) | |||
98 | 98 | ||
99 | /* This is needed to compile on Android below API 21 | 99 | /* This is needed to compile on Android below API 21 |
100 | */ | 100 | */ |
101 | #ifdef TCP_SERVER_USE_EPOLL | ||
101 | #ifndef EPOLLRDHUP | 102 | #ifndef EPOLLRDHUP |
102 | #define EPOLLRDHUP 0x2000 | 103 | #define EPOLLRDHUP 0x2000 |
103 | #endif | 104 | #endif |
105 | #endif | ||
104 | 106 | ||
105 | /* Set the size of the connection list to numfriends. | 107 | /* Set the size of the connection list to numfriends. |
106 | * | 108 | * |
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 @@ | |||
13 | // "function") is used. Note the semantic difference: alloca'd memory does not | 13 | // "function") is used. Note the semantic difference: alloca'd memory does not |
14 | // get freed at the end of the declaration's scope. Do not use VLA() in loops or | 14 | // get freed at the end of the declaration's scope. Do not use VLA() in loops or |
15 | // you may run out of stack space. | 15 | // you may run out of stack space. |
16 | #if !defined(_MSC_VER) && __STDC_VERSION__ >= 199901L | 16 | #if !defined(_MSC_VER) && defined(__STDC_VERSION__) && __STDC_VERSION__ >= 199901L |
17 | // C99 VLAs. | 17 | // C99 VLAs. |
18 | #define VLA(type, name, size) type name[size] | 18 | #define VLA(type, name, size) type name[size] |
19 | #define SIZEOF_VLA sizeof | 19 | #define SIZEOF_VLA sizeof |
@@ -42,4 +42,10 @@ | |||
42 | #define nullptr NULL | 42 | #define nullptr NULL |
43 | #endif | 43 | #endif |
44 | 44 | ||
45 | #ifdef __GNUC__ | ||
46 | #define GNU_PRINTF __attribute__((__format__(__printf__, 6, 7))) | ||
47 | #else | ||
48 | #define GNU_PRINTF | ||
49 | #endif | ||
50 | |||
45 | #endif /* CCOMPAT_H */ | 51 | #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) | |||
219 | 219 | ||
220 | static uint32_t host_to_network(uint32_t x) | 220 | static uint32_t host_to_network(uint32_t x) |
221 | { | 221 | { |
222 | #if BYTE_ORDER == LITTLE_ENDIAN | 222 | #if !defined(BYTE_ORDER) || BYTE_ORDER == LITTLE_ENDIAN |
223 | return | 223 | return |
224 | ((x >> 24) & 0x000000FF) | // move byte 3 to byte 0 | 224 | ((x >> 24) & 0x000000FF) | // move byte 3 to byte 0 |
225 | ((x >> 8) & 0x0000FF00) | // move byte 2 to byte 1 | 225 | ((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 @@ | |||
26 | 26 | ||
27 | #include <stdint.h> | 27 | #include <stdint.h> |
28 | 28 | ||
29 | #include "ccompat.h" | ||
30 | |||
29 | #ifndef MIN_LOGGER_LEVEL | 31 | #ifndef MIN_LOGGER_LEVEL |
30 | #define MIN_LOGGER_LEVEL LOG_INFO | 32 | #define MIN_LOGGER_LEVEL LOG_INFO |
31 | #endif | 33 | #endif |
@@ -59,8 +61,8 @@ void logger_callback_log(Logger *log, logger_cb *function, void *context, void * | |||
59 | /** | 61 | /** |
60 | * Main write function. If logging disabled does nothing. | 62 | * Main write function. If logging disabled does nothing. |
61 | */ | 63 | */ |
62 | void logger_write(Logger *log, LOGGER_LEVEL level, const char *file, int line, const char *func, const char *format, | 64 | void logger_write( |
63 | ...); | 65 | Logger *log, LOGGER_LEVEL level, const char *file, int line, const char *func, const char *format, ...) GNU_PRINTF; |
64 | 66 | ||
65 | 67 | ||
66 | #define LOGGER_WRITE(log, level, ...) \ | 68 | #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 | |||
1542 | return -1; | 1542 | return -1; |
1543 | } | 1543 | } |
1544 | 1544 | ||
1545 | // else { /* TODO(irungentoo): ? */ } | ||
1546 | |||
1547 | set_buffer_end(&conn->recv_array, num); | 1545 | set_buffer_end(&conn->recv_array, num); |
1548 | } else if (real_data[0] >= CRYPTO_RESERVED_PACKETS && real_data[0] < PACKET_ID_LOSSY_RANGE_START) { | 1546 | } else if (real_data[0] >= CRYPTO_RESERVED_PACKETS && real_data[0] < PACKET_ID_LOSSY_RANGE_START) { |
1549 | Packet_Data dt; | 1547 | 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 @@ | |||
25 | #include "config.h" | 25 | #include "config.h" |
26 | #endif | 26 | #endif |
27 | 27 | ||
28 | #ifdef __APPLE__ | ||
28 | #define _DARWIN_C_SOURCE | 29 | #define _DARWIN_C_SOURCE |
30 | #endif | ||
31 | |||
29 | #ifndef _XOPEN_SOURCE | 32 | #ifndef _XOPEN_SOURCE |
30 | #define _XOPEN_SOURCE 600 | 33 | #define _XOPEN_SOURCE 600 |
31 | #endif | 34 | #endif |
@@ -185,14 +188,14 @@ const IP6 IP6_BROADCAST = { | |||
185 | { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff } | 188 | { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff } |
186 | }; | 189 | }; |
187 | 190 | ||
188 | IP4 get_ip4_loopback() | 191 | IP4 get_ip4_loopback(void) |
189 | { | 192 | { |
190 | IP4 loopback; | 193 | IP4 loopback; |
191 | loopback.uint32 = htonl(INADDR_LOOPBACK); | 194 | loopback.uint32 = htonl(INADDR_LOOPBACK); |
192 | return loopback; | 195 | return loopback; |
193 | } | 196 | } |
194 | 197 | ||
195 | IP6 get_ip6_loopback() | 198 | IP6 get_ip6_loopback(void) |
196 | { | 199 | { |
197 | IP6 loopback; | 200 | IP6 loopback; |
198 | get_ip6(&loopback, &in6addr_loopback); | 201 | get_ip6(&loopback, &in6addr_loopback); |
@@ -374,18 +377,18 @@ static void loglogdata(Logger *log, const char *message, const uint8_t *buffer, | |||
374 | char ip_str[IP_NTOA_LEN]; | 377 | char ip_str[IP_NTOA_LEN]; |
375 | 378 | ||
376 | if (res < 0) { /* Windows doesn't necessarily know %zu */ | 379 | if (res < 0) { /* Windows doesn't necessarily know %zu */ |
377 | LOGGER_TRACE(log, "[%2u] %s %3hu%c %s:%hu (%u: %s) | %04x%04x", | 380 | LOGGER_TRACE(log, "[%2u] %s %3u%c %s:%u (%u: %s) | %04x%04x", |
378 | buffer[0], message, (buflen < 999 ? (uint16_t)buflen : 999), 'E', | 381 | buffer[0], message, (buflen < 999 ? buflen : 999), 'E', |
379 | ip_ntoa(&ip_port.ip, ip_str, sizeof(ip_str)), net_ntohs(ip_port.port), errno, | 382 | ip_ntoa(&ip_port.ip, ip_str, sizeof(ip_str)), net_ntohs(ip_port.port), errno, |
380 | strerror(errno), data_0(buflen, buffer), data_1(buflen, buffer)); | 383 | strerror(errno), data_0(buflen, buffer), data_1(buflen, buffer)); |
381 | } else if ((res > 0) && ((size_t)res <= buflen)) { | 384 | } else if ((res > 0) && ((size_t)res <= buflen)) { |
382 | LOGGER_TRACE(log, "[%2u] %s %3zu%c %s:%hu (%u: %s) | %04x%04x", | 385 | LOGGER_TRACE(log, "[%2u] %s %3u%c %s:%u (%u: %s) | %04x%04x", |
383 | buffer[0], message, (res < 999 ? (size_t)res : 999), ((size_t)res < buflen ? '<' : '='), | 386 | buffer[0], message, (res < 999 ? res : 999), ((size_t)res < buflen ? '<' : '='), |
384 | ip_ntoa(&ip_port.ip, ip_str, sizeof(ip_str)), net_ntohs(ip_port.port), 0, "OK", | 387 | ip_ntoa(&ip_port.ip, ip_str, sizeof(ip_str)), net_ntohs(ip_port.port), 0, "OK", |
385 | data_0(buflen, buffer), data_1(buflen, buffer)); | 388 | data_0(buflen, buffer), data_1(buflen, buffer)); |
386 | } else { /* empty or overwrite */ | 389 | } else { /* empty or overwrite */ |
387 | LOGGER_TRACE(log, "[%2u] %s %zu%c%zu %s:%hu (%u: %s) | %04x%04x", | 390 | LOGGER_TRACE(log, "[%2u] %s %u%c%u %s:%u (%u: %s) | %04x%04x", |
388 | buffer[0], message, (size_t)res, (!res ? '!' : '>'), buflen, | 391 | buffer[0], message, res, (!res ? '!' : '>'), buflen, |
389 | ip_ntoa(&ip_port.ip, ip_str, sizeof(ip_str)), net_ntohs(ip_port.port), 0, "OK", | 392 | ip_ntoa(&ip_port.ip, ip_str, sizeof(ip_str)), net_ntohs(ip_port.port), 0, "OK", |
390 | data_0(buflen, buffer), data_1(buflen, buffer)); | 393 | data_0(buflen, buffer), data_1(buflen, buffer)); |
391 | } | 394 | } |
@@ -951,7 +954,7 @@ void ip_reset(IP *ip) | |||
951 | } | 954 | } |
952 | 955 | ||
953 | /* nulls out ip, sets family according to flag */ | 956 | /* nulls out ip, sets family according to flag */ |
954 | void ip_init(IP *ip, uint8_t ipv6enabled) | 957 | void ip_init(IP *ip, bool ipv6enabled) |
955 | { | 958 | { |
956 | if (!ip) { | 959 | if (!ip) { |
957 | return; | 960 | return; |
@@ -1298,7 +1301,7 @@ int32_t net_getipport(const char *node, IP_Port **res, int tox_type) | |||
1298 | const size_t MAX_COUNT = MIN(SIZE_MAX, INT32_MAX) / sizeof(IP_Port); | 1301 | const size_t MAX_COUNT = MIN(SIZE_MAX, INT32_MAX) / sizeof(IP_Port); |
1299 | int type = make_socktype(tox_type); | 1302 | int type = make_socktype(tox_type); |
1300 | struct addrinfo *cur; | 1303 | struct addrinfo *cur; |
1301 | int32_t count = 0; | 1304 | size_t count = 0; |
1302 | 1305 | ||
1303 | for (cur = infos; count < MAX_COUNT && cur != nullptr; cur = cur->ai_next) { | 1306 | for (cur = infos; count < MAX_COUNT && cur != nullptr; cur = cur->ai_next) { |
1304 | if (cur->ai_socktype && type > 0 && cur->ai_socktype != type) { | 1307 | 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 @@ | |||
33 | #include "ccompat.h" | 33 | #include "ccompat.h" |
34 | #include "logger.h" | 34 | #include "logger.h" |
35 | 35 | ||
36 | #include <stdbool.h> | ||
36 | #include <stdint.h> | 37 | #include <stdint.h> |
37 | #include <stdio.h> | 38 | #include <stdio.h> |
38 | #include <stdlib.h> | 39 | #include <stdlib.h> |
@@ -187,7 +188,7 @@ size_t net_unpack_u64(const uint8_t *bytes, uint64_t *v); | |||
187 | #define SIZE_PORT 2 | 188 | #define SIZE_PORT 2 |
188 | #define SIZE_IPPORT (SIZE_IP + SIZE_PORT) | 189 | #define SIZE_IPPORT (SIZE_IP + SIZE_PORT) |
189 | 190 | ||
190 | #define TOX_ENABLE_IPV6_DEFAULT 1 | 191 | #define TOX_ENABLE_IPV6_DEFAULT true |
191 | 192 | ||
192 | /* addr_resolve return values */ | 193 | /* addr_resolve return values */ |
193 | #define TOX_ADDR_RESOLVE_INET 1 | 194 | #define TOX_ADDR_RESOLVE_INET 1 |
@@ -260,7 +261,7 @@ int ipport_equal(const IP_Port *a, const IP_Port *b); | |||
260 | /* nulls out ip */ | 261 | /* nulls out ip */ |
261 | void ip_reset(IP *ip); | 262 | void ip_reset(IP *ip); |
262 | /* nulls out ip, sets family according to flag */ | 263 | /* nulls out ip, sets family according to flag */ |
263 | void ip_init(IP *ip, uint8_t ipv6enabled); | 264 | void ip_init(IP *ip, bool ipv6enabled); |
264 | /* checks if ip is valid */ | 265 | /* checks if ip is valid */ |
265 | int ip_isset(const IP *ip); | 266 | int ip_isset(const IP *ip); |
266 | /* checks if ip is valid */ | 267 | /* 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) | |||
1351 | * return -1 on failure. | 1351 | * return -1 on failure. |
1352 | * return 0 on success. | 1352 | * return 0 on success. |
1353 | */ | 1353 | */ |
1354 | int recv_tcp_relay_handler(Onion_Client *onion_c, int friend_num, int (*tcp_relay_node_callback)(void *object, | 1354 | int recv_tcp_relay_handler(Onion_Client *onion_c, int friend_num, int (*callback)(void *object, |
1355 | uint32_t number, IP_Port ip_port, const uint8_t *public_key), void *object, uint32_t number) | 1355 | uint32_t number, IP_Port ip_port, const uint8_t *public_key), void *object, uint32_t number) |
1356 | { | 1356 | { |
1357 | if ((uint32_t)friend_num >= onion_c->num_friends) { | 1357 | if ((uint32_t)friend_num >= onion_c->num_friends) { |
1358 | return -1; | 1358 | return -1; |
1359 | } | 1359 | } |
1360 | 1360 | ||
1361 | onion_c->friends_list[friend_num].tcp_relay_node_callback = tcp_relay_node_callback; | 1361 | onion_c->friends_list[friend_num].tcp_relay_node_callback = callback; |
1362 | onion_c->friends_list[friend_num].tcp_relay_node_callback_object = object; | 1362 | onion_c->friends_list[friend_num].tcp_relay_node_callback_object = object; |
1363 | onion_c->friends_list[friend_num].tcp_relay_node_callback_number = number; | 1363 | onion_c->friends_list[friend_num].tcp_relay_node_callback_number = number; |
1364 | return 0; | 1364 | 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; | |||
188 | * features, but can't break the API. | 188 | * features, but can't break the API. |
189 | */ | 189 | */ |
190 | #define TOX_VERSION_IS_API_COMPATIBLE(MAJOR, MINOR, PATCH) \ | 190 | #define TOX_VERSION_IS_API_COMPATIBLE(MAJOR, MINOR, PATCH) \ |
191 | (TOX_VERSION_MAJOR > 0 && TOX_VERSION_MAJOR == MAJOR) && ( \ | 191 | ((TOX_VERSION_MAJOR > 0 && TOX_VERSION_MAJOR == MAJOR) && ( \ |
192 | /* 1.x.x, 2.x.x, etc. with matching major version. */ \ | 192 | /* 1.x.x, 2.x.x, etc. with matching major version. */ \ |
193 | TOX_VERSION_MINOR > MINOR || \ | 193 | TOX_VERSION_MINOR > MINOR || \ |
194 | TOX_VERSION_MINOR == MINOR && TOX_VERSION_PATCH >= PATCH \ | 194 | (TOX_VERSION_MINOR == MINOR && TOX_VERSION_PATCH >= PATCH) \ |
195 | ) || (TOX_VERSION_MAJOR == 0 && MAJOR == 0) && ( \ | 195 | )) || ((TOX_VERSION_MAJOR == 0 && MAJOR == 0) && ( \ |
196 | /* 0.x.x makes minor behave like major above. */ \ | 196 | /* 0.x.x makes minor behave like major above. */ \ |
197 | (TOX_VERSION_MINOR > 0 && TOX_VERSION_MINOR == MINOR) && ( \ | 197 | ((TOX_VERSION_MINOR > 0 && TOX_VERSION_MINOR == MINOR) && ( \ |
198 | TOX_VERSION_PATCH >= PATCH \ | 198 | TOX_VERSION_PATCH >= PATCH \ |
199 | ) || (TOX_VERSION_MINOR == 0 && MINOR == 0) && ( \ | 199 | )) || ((TOX_VERSION_MINOR == 0 && MINOR == 0) && ( \ |
200 | /* 0.0.x and 0.0.y are only compatible if x == y. */ \ | 200 | /* 0.0.x and 0.0.y are only compatible if x == y. */ \ |
201 | TOX_VERSION_PATCH == PATCH \ | 201 | TOX_VERSION_PATCH == PATCH \ |
202 | ) \ | 202 | )) \ |
203 | ) | 203 | )) |
204 | 204 | ||
205 | static namespace version { | 205 | static namespace version { |
206 | 206 | ||
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) | |||
82 | { | 82 | { |
83 | Messenger_Options m_options = {0}; | 83 | Messenger_Options m_options = {0}; |
84 | 84 | ||
85 | bool load_savedata_sk = 0, load_savedata_tox = 0; | 85 | bool load_savedata_sk = false, load_savedata_tox = false; |
86 | 86 | ||
87 | if (options == nullptr) { | 87 | if (options == nullptr) { |
88 | m_options.ipv6enabled = TOX_ENABLE_IPV6_DEFAULT; | 88 | m_options.ipv6enabled = TOX_ENABLE_IPV6_DEFAULT; |
@@ -100,7 +100,7 @@ Tox *tox_new(const struct Tox_Options *options, TOX_ERR_NEW *error) | |||
100 | return nullptr; | 100 | return nullptr; |
101 | } | 101 | } |
102 | 102 | ||
103 | load_savedata_sk = 1; | 103 | load_savedata_sk = true; |
104 | } else if (tox_options_get_savedata_type(options) == TOX_SAVEDATA_TYPE_TOX_SAVE) { | 104 | } else if (tox_options_get_savedata_type(options) == TOX_SAVEDATA_TYPE_TOX_SAVE) { |
105 | if (tox_options_get_savedata_length(options) < TOX_ENC_SAVE_MAGIC_LENGTH) { | 105 | if (tox_options_get_savedata_length(options) < TOX_ENC_SAVE_MAGIC_LENGTH) { |
106 | SET_ERROR_PARAMETER(error, TOX_ERR_NEW_LOAD_BAD_FORMAT); | 106 | 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) | |||
112 | return nullptr; | 112 | return nullptr; |
113 | } | 113 | } |
114 | 114 | ||
115 | load_savedata_tox = 1; | 115 | load_savedata_tox = true; |
116 | } | 116 | } |
117 | 117 | ||
118 | m_options.ipv6enabled = tox_options_get_ipv6_enabled(options); | 118 | 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) | |||
156 | m_options.proxy_info.ip_port.ip.family = TOX_AF_UNSPEC; | 156 | m_options.proxy_info.ip_port.ip.family = TOX_AF_UNSPEC; |
157 | } | 157 | } |
158 | 158 | ||
159 | if (!addr_resolve_or_parse_ip(tox_options_get_proxy_host(options), &m_options.proxy_info.ip_port.ip, nullptr)) { | 159 | if (addr_resolve_or_parse_ip(tox_options_get_proxy_host(options), &m_options.proxy_info.ip_port.ip, nullptr) == 0) { |
160 | SET_ERROR_PARAMETER(error, TOX_ERR_NEW_PROXY_BAD_HOST); | 160 | SET_ERROR_PARAMETER(error, TOX_ERR_NEW_PROXY_BAD_HOST); |
161 | // TODO(irungentoo): TOX_ERR_NEW_PROXY_NOT_FOUND if domain. | 161 | // TODO(irungentoo): TOX_ERR_NEW_PROXY_NOT_FOUND if domain. |
162 | return nullptr; | 162 | return nullptr; |
@@ -457,7 +457,8 @@ void tox_self_set_status(Tox *tox, TOX_USER_STATUS status) | |||
457 | TOX_USER_STATUS tox_self_get_status(const Tox *tox) | 457 | TOX_USER_STATUS tox_self_get_status(const Tox *tox) |
458 | { | 458 | { |
459 | const Messenger *m = tox; | 459 | const Messenger *m = tox; |
460 | return (TOX_USER_STATUS)m_get_self_userstatus(m); | 460 | const uint8_t status = m_get_self_userstatus(m); |
461 | return (TOX_USER_STATUS)status; | ||
461 | } | 462 | } |
462 | 463 | ||
463 | static void set_friend_error(int32_t ret, TOX_ERR_FRIEND_ADD *error) | 464 | 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); | |||
191 | * features, but can't break the API. | 191 | * features, but can't break the API. |
192 | */ | 192 | */ |
193 | #define TOX_VERSION_IS_API_COMPATIBLE(MAJOR, MINOR, PATCH) \ | 193 | #define TOX_VERSION_IS_API_COMPATIBLE(MAJOR, MINOR, PATCH) \ |
194 | (TOX_VERSION_MAJOR > 0 && TOX_VERSION_MAJOR == MAJOR) && ( \ | 194 | ((TOX_VERSION_MAJOR > 0 && TOX_VERSION_MAJOR == MAJOR) && ( \ |
195 | /* 1.x.x, 2.x.x, etc. with matching major version. */ \ | 195 | /* 1.x.x, 2.x.x, etc. with matching major version. */ \ |
196 | TOX_VERSION_MINOR > MINOR || \ | 196 | TOX_VERSION_MINOR > MINOR || \ |
197 | TOX_VERSION_MINOR == MINOR && TOX_VERSION_PATCH >= PATCH \ | 197 | (TOX_VERSION_MINOR == MINOR && TOX_VERSION_PATCH >= PATCH) \ |
198 | ) || (TOX_VERSION_MAJOR == 0 && MAJOR == 0) && ( \ | 198 | )) || ((TOX_VERSION_MAJOR == 0 && MAJOR == 0) && ( \ |
199 | /* 0.x.x makes minor behave like major above. */ \ | 199 | /* 0.x.x makes minor behave like major above. */ \ |
200 | (TOX_VERSION_MINOR > 0 && TOX_VERSION_MINOR == MINOR) && ( \ | 200 | ((TOX_VERSION_MINOR > 0 && TOX_VERSION_MINOR == MINOR) && ( \ |
201 | TOX_VERSION_PATCH >= PATCH \ | 201 | TOX_VERSION_PATCH >= PATCH \ |
202 | ) || (TOX_VERSION_MINOR == 0 && MINOR == 0) && ( \ | 202 | )) || ((TOX_VERSION_MINOR == 0 && MINOR == 0) && ( \ |
203 | /* 0.0.x and 0.0.y are only compatible if x == y. */ \ | 203 | /* 0.0.x and 0.0.y are only compatible if x == y. */ \ |
204 | TOX_VERSION_PATCH == PATCH \ | 204 | TOX_VERSION_PATCH == PATCH \ |
205 | ) \ | 205 | )) \ |
206 | ) | 206 | )) |
207 | 207 | ||
208 | /** | 208 | /** |
209 | * Return whether the compiled library version is compatible with the passed | 209 | * Return whether the compiled library version is compatible with the passed |