summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--CMakeLists.txt22
-rw-r--r--auto_tests/TCP_test.c6
-rw-r--r--auto_tests/dht_test.c17
-rw-r--r--auto_tests/onion_test.c10
-rw-r--r--auto_tests/tox_test.c2
-rw-r--r--auto_tests/toxav_many_test.c8
-rw-r--r--cmake/ModulePackage.cmake13
-rw-r--r--other/bootstrap_daemon/src/config.c24
-rw-r--r--other/bootstrap_daemon/src/log.c11
-rw-r--r--other/bootstrap_node_packets.c4
-rw-r--r--testing/Messenger_test.c2
-rw-r--r--testing/av_test.c16
-rw-r--r--testing/misc_tools.c2
-rw-r--r--testing/tox_shell.c2
-rw-r--r--toxav/audio.c20
-rw-r--r--toxav/bwcontroller.c4
-rw-r--r--toxav/group.c28
-rw-r--r--toxav/msi.c22
-rw-r--r--toxav/rtp.c7
-rw-r--r--toxav/toxav.c43
-rw-r--r--toxav/toxav_old.c10
-rw-r--r--toxav/video.c21
-rw-r--r--toxcore/DHT.c141
-rw-r--r--toxcore/LAN_discovery.c2
-rw-r--r--toxcore/Messenger.c74
-rw-r--r--toxcore/TCP_client.c22
-rw-r--r--toxcore/TCP_connection.c37
-rw-r--r--toxcore/TCP_server.c31
-rw-r--r--toxcore/assoc.c11
-rw-r--r--toxcore/friend_connection.c18
-rw-r--r--toxcore/friend_requests.c2
-rw-r--r--toxcore/group.c18
-rw-r--r--toxcore/list.c14
-rw-r--r--toxcore/logger.c2
-rw-r--r--toxcore/net_crypto.c21
-rw-r--r--toxcore/network.c2
-rw-r--r--toxcore/onion.c14
-rw-r--r--toxcore/onion_announce.c6
-rw-r--r--toxcore/onion_client.c12
-rw-r--r--toxcore/ping.c10
-rw-r--r--toxcore/ping_array.c2
-rw-r--r--toxcore/tox.c26
-rw-r--r--toxcore/util.c4
-rw-r--r--toxdns/toxdns.c12
44 files changed, 407 insertions, 368 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt
index f2bd5381..f5ee2770 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -219,7 +219,7 @@ add_test(
219 219
220function(auto_test target) 220function(auto_test target)
221 if(CHECK_FOUND) 221 if(CHECK_FOUND)
222 add_executable(auto_${target} auto_tests/${target}.c) 222 add_c_executable(auto_${target} auto_tests/${target}.c)
223 target_link_modules(auto_${target} 223 target_link_modules(auto_${target}
224 toxcore 224 toxcore
225 toxencryptsave 225 toxencryptsave
@@ -253,13 +253,13 @@ endif()
253# 253#
254################################################################################ 254################################################################################
255 255
256add_executable(DHT_bootstrap 256add_c_executable(DHT_bootstrap
257 other/DHT_bootstrap.c 257 other/DHT_bootstrap.c
258 other/bootstrap_node_packets.c) 258 other/bootstrap_node_packets.c)
259target_link_modules(DHT_bootstrap toxnetcrypto) 259target_link_modules(DHT_bootstrap toxnetcrypto)
260 260
261if(LIBCONFIG_FOUND) 261if(LIBCONFIG_FOUND)
262 add_executable(tox-bootstrapd 262 add_c_executable(tox-bootstrapd
263 other/bootstrap_daemon/src/command_line_arguments.c 263 other/bootstrap_daemon/src/command_line_arguments.c
264 other/bootstrap_daemon/src/command_line_arguments.h 264 other/bootstrap_daemon/src/command_line_arguments.h
265 other/bootstrap_daemon/src/config.c 265 other/bootstrap_daemon/src/config.c
@@ -282,7 +282,7 @@ endif()
282################################################################################ 282################################################################################
283 283
284if(NOT WIN32 AND BUILD_TOXAV AND SNDFILE_FOUND AND PORTAUDIO_FOUND AND OPENCV_FOUND) 284if(NOT WIN32 AND BUILD_TOXAV AND SNDFILE_FOUND AND PORTAUDIO_FOUND AND OPENCV_FOUND)
285 add_executable(av_test testing/av_test.c) 285 add_c_executable(av_test testing/av_test.c)
286 target_link_modules(av_test 286 target_link_modules(av_test
287 toxav 287 toxav
288 ${OPENCV_LIBRARIES} 288 ${OPENCV_LIBRARIES}
@@ -291,31 +291,31 @@ if(NOT WIN32 AND BUILD_TOXAV AND SNDFILE_FOUND AND PORTAUDIO_FOUND AND OPENCV_FO
291endif() 291endif()
292 292
293if(NOT WIN32) 293if(NOT WIN32)
294 add_executable(nTox testing/nTox.c) 294 add_c_executable(nTox testing/nTox.c)
295 target_link_modules(nTox toxcore ${NCURSES_LIBRARIES}) 295 target_link_modules(nTox toxcore ${NCURSES_LIBRARIES})
296endif() 296endif()
297 297
298add_executable(DHT_test testing/DHT_test.c) 298add_c_executable(DHT_test testing/DHT_test.c)
299target_link_modules(DHT_test toxdht) 299target_link_modules(DHT_test toxdht)
300 300
301add_executable(Messenger_test testing/Messenger_test.c) 301add_c_executable(Messenger_test testing/Messenger_test.c)
302target_link_modules(Messenger_test toxmessenger) 302target_link_modules(Messenger_test toxmessenger)
303 303
304add_executable(dns3_test testing/dns3_test.c) 304add_c_executable(dns3_test testing/dns3_test.c)
305target_link_modules(dns3_test toxdns) 305target_link_modules(dns3_test toxdns)
306 306
307if(NOT WIN32) 307if(NOT WIN32)
308 add_executable(tox_sync testing/tox_sync.c) 308 add_c_executable(tox_sync testing/tox_sync.c)
309 target_link_modules(tox_sync toxcore) 309 target_link_modules(tox_sync toxcore)
310endif() 310endif()
311 311
312if(UTIL_LIBRARIES) 312if(UTIL_LIBRARIES)
313 add_executable(tox_shell testing/tox_shell.c) 313 add_c_executable(tox_shell testing/tox_shell.c)
314 target_link_modules(tox_shell toxcore ${UTIL_LIBRARIES}) 314 target_link_modules(tox_shell toxcore ${UTIL_LIBRARIES})
315endif() 315endif()
316 316
317if(NOT WIN32) 317if(NOT WIN32)
318 add_executable(irc_syncbot testing/irc_syncbot.c) 318 add_c_executable(irc_syncbot testing/irc_syncbot.c)
319 target_link_modules(irc_syncbot toxcore) 319 target_link_modules(irc_syncbot toxcore)
320endif() 320endif()
321 321
diff --git a/auto_tests/TCP_test.c b/auto_tests/TCP_test.c
index 05f42a6a..1442dcae 100644
--- a/auto_tests/TCP_test.c
+++ b/auto_tests/TCP_test.c
@@ -132,7 +132,7 @@ struct sec_TCP_con {
132 132
133static struct sec_TCP_con *new_TCP_con(TCP_Server *tcp_s) 133static struct sec_TCP_con *new_TCP_con(TCP_Server *tcp_s)
134{ 134{
135 struct sec_TCP_con *sec_c = malloc(sizeof(struct sec_TCP_con)); 135 struct sec_TCP_con *sec_c = (struct sec_TCP_con *)malloc(sizeof(struct sec_TCP_con));
136 sock_t sock = socket(AF_INET6, SOCK_STREAM, IPPROTO_TCP); 136 sock_t sock = socket(AF_INET6, SOCK_STREAM, IPPROTO_TCP);
137 struct sockaddr_in6 addr6_loopback = {0}; 137 struct sockaddr_in6 addr6_loopback = {0};
138 addr6_loopback.sin6_family = AF_INET6; 138 addr6_loopback.sin6_family = AF_INET6;
@@ -636,6 +636,8 @@ static bool tcp_oobdata_callback_called;
636static int tcp_oobdata_callback(void *object, const uint8_t *public_key, unsigned int id, const uint8_t *data, 636static int tcp_oobdata_callback(void *object, const uint8_t *public_key, unsigned int id, const uint8_t *data,
637 uint16_t length, void *userdata) 637 uint16_t length, void *userdata)
638{ 638{
639 TCP_Connections *tcp_c = (TCP_Connections *)object;
640
639 if (length != 6) { 641 if (length != 6) {
640 return -1; 642 return -1;
641 } 643 }
@@ -644,7 +646,7 @@ static int tcp_oobdata_callback(void *object, const uint8_t *public_key, unsigne
644 return -1; 646 return -1;
645 } 647 }
646 648
647 if (tcp_send_oob_packet(object, id, public_key, data, length) == 0) { 649 if (tcp_send_oob_packet(tcp_c, id, public_key, data, length) == 0) {
648 tcp_oobdata_callback_called = 1; 650 tcp_oobdata_callback_called = 1;
649 } 651 }
650 652
diff --git a/auto_tests/dht_test.c b/auto_tests/dht_test.c
index 08044637..7b22e515 100644
--- a/auto_tests/dht_test.c
+++ b/auto_tests/dht_test.c
@@ -528,11 +528,14 @@ static void test_list_main(void)
528 } 528 }
529 529
530 ck_assert_msg(count == 1, "Nodes in search don't know ip of friend. %u %u %u", i, j, count); 530 ck_assert_msg(count == 1, "Nodes in search don't know ip of friend. %u %u %u", i, j, count);
531 /* 531#if 0
532 for (k = 0; k < MAX_SENT_NODES; ++k) { 532
533 printf("----gn %u----\n", k); 533 for (k = 0; k < MAX_SENT_NODES; ++k) {
534 print_pk(ln[k].public_key); 534 printf("----gn %u----\n", k);
535 }*/ 535 print_pk(ln[k].public_key);
536 }
537
538#endif
536 ++m_count; 539 ++m_count;
537 } 540 }
538 } 541 }
@@ -542,7 +545,7 @@ static void test_list_main(void)
542 (NUM_DHT) * (MAX_FRIEND_CLIENTS)); 545 (NUM_DHT) * (MAX_FRIEND_CLIENTS));
543 546
544 for (i = 0; i < NUM_DHT; ++i) { 547 for (i = 0; i < NUM_DHT; ++i) {
545 void *n = dhts[i]->net; 548 Networking_Core *n = dhts[i]->net;
546 kill_DHT(dhts[i]); 549 kill_DHT(dhts[i]);
547 kill_networking(n); 550 kill_networking(n);
548 } 551 }
@@ -643,7 +646,7 @@ loop_top:
643 } 646 }
644 647
645 for (i = 0; i < NUM_DHT; ++i) { 648 for (i = 0; i < NUM_DHT; ++i) {
646 void *n = dhts[i]->net; 649 Networking_Core *n = dhts[i]->net;
647 kill_DHT(dhts[i]); 650 kill_DHT(dhts[i]);
648 kill_networking(n); 651 kill_networking(n);
649 } 652 }
diff --git a/auto_tests/onion_test.c b/auto_tests/onion_test.c
index 6e330091..ee9df7a0 100644
--- a/auto_tests/onion_test.c
+++ b/auto_tests/onion_test.c
@@ -32,7 +32,7 @@ static void do_onion(Onion *onion)
32static int handled_test_1; 32static int handled_test_1;
33static int handle_test_1(void *object, IP_Port source, const uint8_t *packet, uint16_t length, void *userdata) 33static int handle_test_1(void *object, IP_Port source, const uint8_t *packet, uint16_t length, void *userdata)
34{ 34{
35 Onion *onion = object; 35 Onion *onion = (Onion *)object;
36 36
37 if (memcmp(packet, "Install Gentoo", sizeof("Install Gentoo")) != 0) { 37 if (memcmp(packet, "Install Gentoo", sizeof("Install Gentoo")) != 0) {
38 return 1; 38 return 1;
@@ -79,7 +79,7 @@ static uint8_t test_3_pub_key[crypto_box_PUBLICKEYBYTES];
79static uint8_t test_3_ping_id[crypto_hash_sha256_BYTES]; 79static uint8_t test_3_ping_id[crypto_hash_sha256_BYTES];
80static int handle_test_3(void *object, IP_Port source, const uint8_t *packet, uint16_t length, void *userdata) 80static int handle_test_3(void *object, IP_Port source, const uint8_t *packet, uint16_t length, void *userdata)
81{ 81{
82 Onion *onion = object; 82 Onion *onion = (Onion *)object;
83 83
84 if (length != (1 + crypto_box_NONCEBYTES + ONION_ANNOUNCE_SENDBACK_DATA_LENGTH + 1 + crypto_hash_sha256_BYTES + 84 if (length != (1 + crypto_box_NONCEBYTES + ONION_ANNOUNCE_SENDBACK_DATA_LENGTH + 1 + crypto_hash_sha256_BYTES +
85 crypto_box_MACBYTES)) { 85 crypto_box_MACBYTES)) {
@@ -111,7 +111,7 @@ static uint8_t nonce[crypto_box_NONCEBYTES];
111static int handled_test_4; 111static int handled_test_4;
112static int handle_test_4(void *object, IP_Port source, const uint8_t *packet, uint16_t length, void *userdata) 112static int handle_test_4(void *object, IP_Port source, const uint8_t *packet, uint16_t length, void *userdata)
113{ 113{
114 Onion *onion = object; 114 Onion *onion = (Onion *)object;
115 115
116 if (length != (1 + crypto_box_NONCEBYTES + crypto_box_PUBLICKEYBYTES + sizeof("Install gentoo") + 116 if (length != (1 + crypto_box_NONCEBYTES + crypto_box_PUBLICKEYBYTES + sizeof("Install gentoo") +
117 crypto_box_MACBYTES)) { 117 crypto_box_MACBYTES)) {
@@ -284,7 +284,7 @@ static Onions *new_onions(uint16_t port)
284 IP ip; 284 IP ip;
285 ip_init(&ip, 1); 285 ip_init(&ip, 1);
286 ip.ip6.uint8[15] = 1; 286 ip.ip6.uint8[15] = 1;
287 Onions *on = malloc(sizeof(Onions)); 287 Onions *on = (Onions *)malloc(sizeof(Onions));
288 DHT *dht = new_DHT(NULL, new_networking(NULL, ip, port)); 288 DHT *dht = new_DHT(NULL, new_networking(NULL, ip, port));
289 on->onion = new_onion(dht); 289 on->onion = new_onion(dht);
290 on->onion_a = new_onion_announce(dht); 290 on->onion_a = new_onion_announce(dht);
@@ -346,7 +346,7 @@ static uint8_t last_dht_pk[crypto_box_PUBLICKEYBYTES];
346static void dht_pk_callback(void *object, int32_t number, const uint8_t *dht_public_key, void *userdata) 346static void dht_pk_callback(void *object, int32_t number, const uint8_t *dht_public_key, void *userdata)
347{ 347{
348 if ((NUM_FIRST == number && !first) || (NUM_LAST == number && !last)) { 348 if ((NUM_FIRST == number && !first) || (NUM_LAST == number && !last)) {
349 Onions *on = object; 349 Onions *on = (Onions *)object;
350 uint16_t count = 0; 350 uint16_t count = 0;
351 int ret = DHT_addfriend(on->onion->dht, dht_public_key, &dht_ip_callback, object, number, &count); 351 int ret = DHT_addfriend(on->onion->dht, dht_public_key, &dht_ip_callback, object, number, &count);
352 ck_assert_msg(ret == 0, "DHT_addfriend() did not return 0"); 352 ck_assert_msg(ret == 0, "DHT_addfriend() did not return 0");
diff --git a/auto_tests/tox_test.c b/auto_tests/tox_test.c
index a5745fe8..6ab03365 100644
--- a/auto_tests/tox_test.c
+++ b/auto_tests/tox_test.c
@@ -974,7 +974,7 @@ START_TEST(test_many_clients_tcp)
974 tox_callback_friend_request(toxes[i], accept_friend_request); 974 tox_callback_friend_request(toxes[i], accept_friend_request);
975 uint8_t dpk[TOX_PUBLIC_KEY_SIZE]; 975 uint8_t dpk[TOX_PUBLIC_KEY_SIZE];
976 tox_self_get_dht_id(toxes[0], dpk); 976 tox_self_get_dht_id(toxes[0], dpk);
977 TOX_ERR_BOOTSTRAP error = 0; 977 TOX_ERR_BOOTSTRAP error = TOX_ERR_BOOTSTRAP_OK;
978 ck_assert_msg(tox_add_tcp_relay(toxes[i], TOX_LOCALHOST, TCP_RELAY_PORT, dpk, &error), "add relay error, %i, %i", i, 978 ck_assert_msg(tox_add_tcp_relay(toxes[i], TOX_LOCALHOST, TCP_RELAY_PORT, dpk, &error), "add relay error, %i, %i", i,
979 error); 979 error);
980 ck_assert_msg(tox_bootstrap(toxes[i], TOX_LOCALHOST, 33445, dpk, 0), "Bootstrap error"); 980 ck_assert_msg(tox_bootstrap(toxes[i], TOX_LOCALHOST, 33445, dpk, 0), "Bootstrap error");
diff --git a/auto_tests/toxav_many_test.c b/auto_tests/toxav_many_test.c
index fec2a1de..6f864f07 100644
--- a/auto_tests/toxav_many_test.c
+++ b/auto_tests/toxav_many_test.c
@@ -164,10 +164,10 @@ static void *call_thread(void *pd)
164 164
165 c_sleep(30); 165 c_sleep(30);
166 166
167 int16_t *PCM = calloc(960, sizeof(int16_t)); 167 int16_t *PCM = (int16_t *)calloc(960, sizeof(int16_t));
168 uint8_t *video_y = calloc(800 * 600, sizeof(uint8_t)); 168 uint8_t *video_y = (uint8_t *)calloc(800 * 600, sizeof(uint8_t));
169 uint8_t *video_u = calloc(800 * 600 / 4, sizeof(uint8_t)); 169 uint8_t *video_u = (uint8_t *)calloc(800 * 600 / 4, sizeof(uint8_t));
170 uint8_t *video_v = calloc(800 * 600 / 4, sizeof(uint8_t)); 170 uint8_t *video_v = (uint8_t *)calloc(800 * 600 / 4, sizeof(uint8_t));
171 171
172 time_t start_time = time(NULL); 172 time_t start_time = time(NULL);
173 173
diff --git a/cmake/ModulePackage.cmake b/cmake/ModulePackage.cmake
index 1e49503a..b963e0de 100644
--- a/cmake/ModulePackage.cmake
+++ b/cmake/ModulePackage.cmake
@@ -1,8 +1,17 @@
1option(ENABLE_SHARED "Build shared (dynamic) libraries for all modules" ON) 1option(ENABLE_SHARED "Build shared (dynamic) libraries for all modules" ON)
2option(ENABLE_STATIC "Build static libraries for all modules" ON) 2option(ENABLE_STATIC "Build static libraries for all modules" ON)
3option(COMPILE_AS_CXX "Compile all C code as C++ code" OFF)
3 4
4find_package(PkgConfig REQUIRED) 5find_package(PkgConfig REQUIRED)
5 6
7function(add_c_executable exec)
8 if(COMPILE_AS_CXX)
9 set_source_files_properties(${ARGN} PROPERTIES LANGUAGE CXX)
10 endif()
11
12 add_executable(${exec} ${ARGN})
13endfunction()
14
6function(pkg_use_module mod) 15function(pkg_use_module mod)
7 pkg_search_module(${mod} ${ARGN}) 16 pkg_search_module(${mod} ${ARGN})
8 if(${mod}_FOUND) 17 if(${mod}_FOUND)
@@ -13,6 +22,10 @@ function(pkg_use_module mod)
13endfunction() 22endfunction()
14 23
15function(add_module lib) 24function(add_module lib)
25 if(COMPILE_AS_CXX)
26 set_source_files_properties(${ARGN} PROPERTIES LANGUAGE CXX)
27 endif()
28
16 if(ENABLE_SHARED) 29 if(ENABLE_SHARED)
17 add_library(${lib}_shared SHARED ${ARGN}) 30 add_library(${lib}_shared SHARED ${ARGN})
18 set_target_properties(${lib}_shared PROPERTIES OUTPUT_NAME ${lib}) 31 set_target_properties(${lib}_shared PROPERTIES OUTPUT_NAME ${lib})
diff --git a/other/bootstrap_daemon/src/config.c b/other/bootstrap_daemon/src/config.c
index 27d1364a..3e102af9 100644
--- a/other/bootstrap_daemon/src/config.c
+++ b/other/bootstrap_daemon/src/config.c
@@ -62,7 +62,7 @@ static void parse_tcp_relay_ports_config(config_t *cfg, uint16_t **tcp_relay_por
62 } 62 }
63 63
64 // similar procedure to the one of reading config file below 64 // similar procedure to the one of reading config file below
65 *tcp_relay_ports = malloc(DEFAULT_TCP_RELAY_PORTS_COUNT * sizeof(uint16_t)); 65 *tcp_relay_ports = (uint16_t *)malloc(DEFAULT_TCP_RELAY_PORTS_COUNT * sizeof(uint16_t));
66 66
67 for (i = 0; i < DEFAULT_TCP_RELAY_PORTS_COUNT; i ++) { 67 for (i = 0; i < DEFAULT_TCP_RELAY_PORTS_COUNT; i ++) {
68 68
@@ -80,7 +80,7 @@ static void parse_tcp_relay_ports_config(config_t *cfg, uint16_t **tcp_relay_por
80 80
81 // the loop above skips invalid ports, so we adjust the allocated memory size 81 // the loop above skips invalid ports, so we adjust the allocated memory size
82 if ((*tcp_relay_port_count) > 0) { 82 if ((*tcp_relay_port_count) > 0) {
83 *tcp_relay_ports = realloc(*tcp_relay_ports, (*tcp_relay_port_count) * sizeof(uint16_t)); 83 *tcp_relay_ports = (uint16_t *)realloc(*tcp_relay_ports, (*tcp_relay_port_count) * sizeof(uint16_t));
84 } else { 84 } else {
85 free(*tcp_relay_ports); 85 free(*tcp_relay_ports);
86 *tcp_relay_ports = NULL; 86 *tcp_relay_ports = NULL;
@@ -102,7 +102,7 @@ static void parse_tcp_relay_ports_config(config_t *cfg, uint16_t **tcp_relay_por
102 return; 102 return;
103 } 103 }
104 104
105 *tcp_relay_ports = malloc(config_port_count * sizeof(uint16_t)); 105 *tcp_relay_ports = (uint16_t *)malloc(config_port_count * sizeof(uint16_t));
106 106
107 int i; 107 int i;
108 108
@@ -134,7 +134,7 @@ static void parse_tcp_relay_ports_config(config_t *cfg, uint16_t **tcp_relay_por
134 134
135 // the loop above skips invalid ports, so we adjust the allocated memory size 135 // the loop above skips invalid ports, so we adjust the allocated memory size
136 if ((*tcp_relay_port_count) > 0) { 136 if ((*tcp_relay_port_count) > 0) {
137 *tcp_relay_ports = realloc(*tcp_relay_ports, (*tcp_relay_port_count) * sizeof(uint16_t)); 137 *tcp_relay_ports = (uint16_t *)realloc(*tcp_relay_ports, (*tcp_relay_port_count) * sizeof(uint16_t));
138 } else { 138 } else {
139 free(*tcp_relay_ports); 139 free(*tcp_relay_ports);
140 *tcp_relay_ports = NULL; 140 *tcp_relay_ports = NULL;
@@ -182,7 +182,7 @@ int get_general_config(const char *cfg_file_path, char **pid_file_path, char **k
182 tmp_pid_file = DEFAULT_PID_FILE_PATH; 182 tmp_pid_file = DEFAULT_PID_FILE_PATH;
183 } 183 }
184 184
185 *pid_file_path = malloc(strlen(tmp_pid_file) + 1); 185 *pid_file_path = (char *)malloc(strlen(tmp_pid_file) + 1);
186 strcpy(*pid_file_path, tmp_pid_file); 186 strcpy(*pid_file_path, tmp_pid_file);
187 187
188 // Get keys file location 188 // Get keys file location
@@ -194,7 +194,7 @@ int get_general_config(const char *cfg_file_path, char **pid_file_path, char **k
194 tmp_keys_file = DEFAULT_KEYS_FILE_PATH; 194 tmp_keys_file = DEFAULT_KEYS_FILE_PATH;
195 } 195 }
196 196
197 *keys_file_path = malloc(strlen(tmp_keys_file) + 1); 197 *keys_file_path = (char *)malloc(strlen(tmp_keys_file) + 1);
198 strcpy(*keys_file_path, tmp_keys_file); 198 strcpy(*keys_file_path, tmp_keys_file);
199 199
200 // Get IPv6 option 200 // Get IPv6 option
@@ -254,7 +254,7 @@ int get_general_config(const char *cfg_file_path, char **pid_file_path, char **k
254 254
255 size_t tmp_motd_length = strlen(tmp_motd) + 1; 255 size_t tmp_motd_length = strlen(tmp_motd) + 1;
256 size_t motd_length = tmp_motd_length > MAX_MOTD_LENGTH ? MAX_MOTD_LENGTH : tmp_motd_length; 256 size_t motd_length = tmp_motd_length > MAX_MOTD_LENGTH ? MAX_MOTD_LENGTH : tmp_motd_length;
257 *motd = malloc(motd_length); 257 *motd = (char *)malloc(motd_length);
258 strncpy(*motd, tmp_motd, motd_length); 258 strncpy(*motd, tmp_motd, motd_length);
259 (*motd)[motd_length - 1] = '\0'; 259 (*motd)[motd_length - 1] = '\0';
260 } 260 }
@@ -310,7 +310,7 @@ static uint8_t *hex_string_to_bin(const char *hex_string)
310 } 310 }
311 311
312 size_t len = strlen(hex_string) / 2; 312 size_t len = strlen(hex_string) / 2;
313 uint8_t *ret = malloc(len); 313 uint8_t *ret = (uint8_t *)malloc(len);
314 314
315 const char *pos = hex_string; 315 const char *pos = hex_string;
316 size_t i; 316 size_t i;
@@ -364,6 +364,8 @@ int bootstrap_from_config(const char *cfg_file_path, DHT *dht, int enable_ipv6)
364 int i = 0; 364 int i = 0;
365 365
366 while (config_setting_length(node_list)) { 366 while (config_setting_length(node_list)) {
367 int address_resolved;
368 uint8_t *bs_public_key_bin;
367 369
368 node = config_setting_get_elem(node_list, 0); 370 node = config_setting_get_elem(node_list, 0);
369 371
@@ -403,9 +405,9 @@ int bootstrap_from_config(const char *cfg_file_path, DHT *dht, int enable_ipv6)
403 goto next; 405 goto next;
404 } 406 }
405 407
406 uint8_t *bs_public_key_bin = hex_string_to_bin(bs_public_key); 408 bs_public_key_bin = hex_string_to_bin(bs_public_key);
407 const int address_resolved = DHT_bootstrap_from_address(dht, bs_address, enable_ipv6, htons(bs_port), 409 address_resolved = DHT_bootstrap_from_address(dht, bs_address, enable_ipv6, htons(bs_port),
408 bs_public_key_bin); 410 bs_public_key_bin);
409 free(bs_public_key_bin); 411 free(bs_public_key_bin);
410 412
411 if (!address_resolved) { 413 if (!address_resolved) {
diff --git a/other/bootstrap_daemon/src/log.c b/other/bootstrap_daemon/src/log.c
index 2eae3286..7632d739 100644
--- a/other/bootstrap_daemon/src/log.c
+++ b/other/bootstrap_daemon/src/log.c
@@ -31,11 +31,12 @@
31#include <stdarg.h> 31#include <stdarg.h>
32#include <stdio.h> 32#include <stdio.h>
33 33
34static LOG_BACKEND current_backend = -1; 34#define INVALID_BACKEND (LOG_BACKEND)-1u
35static LOG_BACKEND current_backend = INVALID_BACKEND;
35 36
36bool open_log(LOG_BACKEND backend) 37bool open_log(LOG_BACKEND backend)
37{ 38{
38 if (current_backend != -1) { 39 if (current_backend != INVALID_BACKEND) {
39 return false; 40 return false;
40 } 41 }
41 42
@@ -50,7 +51,7 @@ bool open_log(LOG_BACKEND backend)
50 51
51bool close_log(void) 52bool close_log(void)
52{ 53{
53 if (current_backend == -1) { 54 if (current_backend == INVALID_BACKEND) {
54 return false; 55 return false;
55 } 56 }
56 57
@@ -58,7 +59,7 @@ bool close_log(void)
58 closelog(); 59 closelog();
59 } 60 }
60 61
61 current_backend = -1; 62 current_backend = INVALID_BACKEND;
62 63
63 return true; 64 return true;
64} 65}
@@ -121,5 +122,5 @@ bool write_log(LOG_LEVEL level, const char *format, ...)
121 122
122 va_end(args); 123 va_end(args);
123 124
124 return current_backend != -1; 125 return current_backend != INVALID_BACKEND;
125} 126}
diff --git a/other/bootstrap_node_packets.c b/other/bootstrap_node_packets.c
index 8ee26786..8abbb7f2 100644
--- a/other/bootstrap_node_packets.c
+++ b/other/bootstrap_node_packets.c
@@ -40,13 +40,15 @@ static int handle_info_request(void *object, IP_Port source, const uint8_t *pack
40 return 1; 40 return 1;
41 } 41 }
42 42
43 Networking_Core *nc = (Networking_Core *)object;
44
43 uint8_t data[1 + sizeof(bootstrap_version) + MAX_MOTD_LENGTH]; 45 uint8_t data[1 + sizeof(bootstrap_version) + MAX_MOTD_LENGTH];
44 data[0] = BOOTSTRAP_INFO_PACKET_ID; 46 data[0] = BOOTSTRAP_INFO_PACKET_ID;
45 memcpy(data + 1, &bootstrap_version, sizeof(bootstrap_version)); 47 memcpy(data + 1, &bootstrap_version, sizeof(bootstrap_version));
46 uint16_t len = 1 + sizeof(bootstrap_version) + bootstrap_motd_length; 48 uint16_t len = 1 + sizeof(bootstrap_version) + bootstrap_motd_length;
47 memcpy(data + 1 + sizeof(bootstrap_version), bootstrap_motd, bootstrap_motd_length); 49 memcpy(data + 1 + sizeof(bootstrap_version), bootstrap_motd, bootstrap_motd_length);
48 50
49 if (sendpacket(object, source, data, len) == len) { 51 if (sendpacket(nc, source, data, len) == len) {
50 return 0; 52 return 0;
51 } 53 }
52 54
diff --git a/testing/Messenger_test.c b/testing/Messenger_test.c
index 8c62068e..3b7715a2 100644
--- a/testing/Messenger_test.c
+++ b/testing/Messenger_test.c
@@ -197,7 +197,7 @@ int main(int argc, char *argv[])
197 return 1; 197 return 1;
198 } 198 }
199 199
200 uint8_t *buffer = malloc(messenger_size(m)); 200 uint8_t *buffer = (uint8_t *)malloc(messenger_size(m));
201 messenger_save(m, buffer); 201 messenger_save(m, buffer);
202 size_t write_result = fwrite(buffer, 1, messenger_size(m), file); 202 size_t write_result = fwrite(buffer, 1, messenger_size(m), file);
203 203
diff --git a/testing/av_test.c b/testing/av_test.c
index 28796abb..02dc5f36 100644
--- a/testing/av_test.c
+++ b/testing/av_test.c
@@ -97,7 +97,7 @@ static void *pa_write_thread(void *d)
97 /* The purpose of this thread is to make sure Pa_WriteStream will not block 97 /* The purpose of this thread is to make sure Pa_WriteStream will not block
98 * toxav_iterate thread 98 * toxav_iterate thread
99 */ 99 */
100 CallControl *cc = d; 100 CallControl *cc = (CallControl *)d;
101 101
102 while (Pa_IsStreamActive(adout)) { 102 while (Pa_IsStreamActive(adout)) {
103 frame *f; 103 frame *f;
@@ -139,7 +139,7 @@ static void t_toxav_receive_video_frame_cb(ToxAV *av, uint32_t friend_number,
139 ustride = abs(ustride); 139 ustride = abs(ustride);
140 vstride = abs(vstride); 140 vstride = abs(vstride);
141 141
142 uint16_t *img_data = malloc(height * width * 6); 142 uint16_t *img_data = (uint16_t *)malloc(height * width * 6);
143 143
144 unsigned long int i, j; 144 unsigned long int i, j;
145 145
@@ -173,8 +173,8 @@ static void t_toxav_receive_audio_frame_cb(ToxAV *av, uint32_t friend_number,
173 uint32_t sampling_rate, 173 uint32_t sampling_rate,
174 void *user_data) 174 void *user_data)
175{ 175{
176 CallControl *cc = user_data; 176 CallControl *cc = (CallControl *)user_data;
177 frame *f = malloc(sizeof(uint16_t) + sample_count * sizeof(int16_t) * channels); 177 frame *f = (frame *)malloc(sizeof(uint16_t) + sample_count * sizeof(int16_t) * channels);
178 memcpy(f->data, pcm, sample_count * sizeof(int16_t) * channels); 178 memcpy(f->data, pcm, sample_count * sizeof(int16_t) * channels);
179 f->size = sample_count; 179 f->size = sample_count;
180 180
@@ -297,7 +297,7 @@ static int iterate_tox(Tox *bootstrap, ToxAV *AliceAV, ToxAV *BobAV, void *userd
297} 297}
298static void *iterate_toxav(void *data) 298static void *iterate_toxav(void *data)
299{ 299{
300 struct toxav_thread_data *data_cast = data; 300 struct toxav_thread_data *data_cast = (struct toxav_thread_data *)data;
301#if defined TEST_TRANSFER_V && TEST_TRANSFER_V == 1 301#if defined TEST_TRANSFER_V && TEST_TRANSFER_V == 1
302 cvNamedWindow(vdout, CV_WINDOW_AUTOSIZE); 302 cvNamedWindow(vdout, CV_WINDOW_AUTOSIZE);
303#endif 303#endif
@@ -335,9 +335,9 @@ static int send_opencv_img(ToxAV *av, uint32_t friend_number, const IplImage *im
335{ 335{
336 int32_t strides[3] = { 1280, 640, 640 }; 336 int32_t strides[3] = { 1280, 640, 640 };
337 uint8_t *planes[3] = { 337 uint8_t *planes[3] = {
338 malloc(img->height * img->width), 338 (uint8_t *)malloc(img->height * img->width),
339 malloc(img->height * img->width / 4), 339 (uint8_t *)malloc(img->height * img->width / 4),
340 malloc(img->height * img->width / 4), 340 (uint8_t *)malloc(img->height * img->width / 4),
341 }; 341 };
342 342
343 int x_chroma_shift = 1; 343 int x_chroma_shift = 1;
diff --git a/testing/misc_tools.c b/testing/misc_tools.c
index 8fdc936c..c1292ed8 100644
--- a/testing/misc_tools.c
+++ b/testing/misc_tools.c
@@ -43,7 +43,7 @@ uint8_t *hex_string_to_bin(const char *hex_string)
43 // is odd and return error code if it is. we assume strlen is even. if it's not 43 // is odd and return error code if it is. we assume strlen is even. if it's not
44 // then the last byte just won't be written in 'ret'. 44 // then the last byte just won't be written in 'ret'.
45 size_t i, len = strlen(hex_string) / 2; 45 size_t i, len = strlen(hex_string) / 2;
46 uint8_t *ret = malloc(len); 46 uint8_t *ret = (uint8_t *)malloc(len);
47 const char *pos = hex_string; 47 const char *pos = hex_string;
48 48
49 for (i = 0; i < len; ++i, pos += 2) { 49 for (i = 0; i < len; ++i, pos += 2) {
diff --git a/testing/tox_shell.c b/testing/tox_shell.c
index 944b7353..7a6678ce 100644
--- a/testing/tox_shell.c
+++ b/testing/tox_shell.c
@@ -77,7 +77,7 @@ int main(int argc, char *argv[])
77 exit(0); 77 exit(0);
78 } 78 }
79 79
80 int *master = malloc(sizeof(int)); 80 int *master = (int *)malloc(sizeof(int));
81 int ret = forkpty(master, NULL, NULL, NULL); 81 int ret = forkpty(master, NULL, NULL, NULL);
82 82
83 if (ret == -1) { 83 if (ret == -1) {
diff --git a/toxav/audio.c b/toxav/audio.c
index 59d1554e..f3351ac3 100644
--- a/toxav/audio.c
+++ b/toxav/audio.c
@@ -45,7 +45,7 @@ bool reconfigure_audio_decoder(ACSession *ac, int32_t sampling_rate, int8_t chan
45 45
46ACSession *ac_new(Logger *log, ToxAV *av, uint32_t friend_number, toxav_audio_receive_frame_cb *cb, void *cb_data) 46ACSession *ac_new(Logger *log, ToxAV *av, uint32_t friend_number, toxav_audio_receive_frame_cb *cb, void *cb_data)
47{ 47{
48 ACSession *ac = calloc(sizeof(ACSession), 1); 48 ACSession *ac = (ACSession *)calloc(sizeof(ACSession), 1);
49 49
50 if (!ac) { 50 if (!ac) {
51 LOGGER_WARNING(log, "Allocation failed! Application might misbehave!"); 51 LOGGER_WARNING(log, "Allocation failed! Application might misbehave!");
@@ -104,7 +104,7 @@ ACSession *ac_new(Logger *log, ToxAV *av, uint32_t friend_number, toxav_audio_re
104 104
105DECODER_CLEANUP: 105DECODER_CLEANUP:
106 opus_decoder_destroy(ac->decoder); 106 opus_decoder_destroy(ac->decoder);
107 jbuf_free(ac->j_buf); 107 jbuf_free((struct JitterBuffer *)ac->j_buf);
108BASE_CLEANUP: 108BASE_CLEANUP:
109 pthread_mutex_destroy(ac->queue_mutex); 109 pthread_mutex_destroy(ac->queue_mutex);
110 free(ac); 110 free(ac);
@@ -118,7 +118,7 @@ void ac_kill(ACSession *ac)
118 118
119 opus_encoder_destroy(ac->encoder); 119 opus_encoder_destroy(ac->encoder);
120 opus_decoder_destroy(ac->decoder); 120 opus_decoder_destroy(ac->decoder);
121 jbuf_free(ac->j_buf); 121 jbuf_free((struct JitterBuffer *)ac->j_buf);
122 122
123 pthread_mutex_destroy(ac->queue_mutex); 123 pthread_mutex_destroy(ac->queue_mutex);
124 124
@@ -141,7 +141,7 @@ void ac_iterate(ACSession *ac)
141 141
142 pthread_mutex_lock(ac->queue_mutex); 142 pthread_mutex_lock(ac->queue_mutex);
143 143
144 while ((msg = jbuf_read(ac->j_buf, &rc)) || rc == 2) { 144 while ((msg = jbuf_read((struct JitterBuffer *)ac->j_buf, &rc)) || rc == 2) {
145 pthread_mutex_unlock(ac->queue_mutex); 145 pthread_mutex_unlock(ac->queue_mutex);
146 146
147 if (rc == 2) { 147 if (rc == 2) {
@@ -204,7 +204,7 @@ int ac_queue_message(void *acp, struct RTPMessage *msg)
204 return -1; 204 return -1;
205 } 205 }
206 206
207 ACSession *ac = acp; 207 ACSession *ac = (ACSession *)acp;
208 208
209 if ((msg->header.pt & 0x7f) == (rtp_TypeAudio + 2) % 128) { 209 if ((msg->header.pt & 0x7f) == (rtp_TypeAudio + 2) % 128) {
210 LOGGER_WARNING(ac->log, "Got dummy!"); 210 LOGGER_WARNING(ac->log, "Got dummy!");
@@ -219,7 +219,7 @@ int ac_queue_message(void *acp, struct RTPMessage *msg)
219 } 219 }
220 220
221 pthread_mutex_lock(ac->queue_mutex); 221 pthread_mutex_lock(ac->queue_mutex);
222 int rc = jbuf_write(ac->log, ac->j_buf, msg); 222 int rc = jbuf_write(ac->log, (struct JitterBuffer *)ac->j_buf, msg);
223 pthread_mutex_unlock(ac->queue_mutex); 223 pthread_mutex_unlock(ac->queue_mutex);
224 224
225 if (rc == -1) { 225 if (rc == -1) {
@@ -261,13 +261,15 @@ static struct JitterBuffer *jbuf_new(uint32_t capacity)
261 size *= 2; 261 size *= 2;
262 } 262 }
263 263
264 struct JitterBuffer *q; 264 struct JitterBuffer *q = (struct JitterBuffer *)calloc(sizeof(struct JitterBuffer), 1);
265 265
266 if (!(q = calloc(sizeof(struct JitterBuffer), 1))) { 266 if (!q) {
267 return NULL; 267 return NULL;
268 } 268 }
269 269
270 if (!(q->queue = calloc(sizeof(struct RTPMessage *), size))) { 270 q->queue = (struct RTPMessage **)calloc(sizeof(struct RTPMessage *), size);
271
272 if (!q->queue) {
271 free(q); 273 free(q);
272 return NULL; 274 return NULL;
273 } 275 }
diff --git a/toxav/bwcontroller.c b/toxav/bwcontroller.c
index b97135d6..f5578465 100644
--- a/toxav/bwcontroller.c
+++ b/toxav/bwcontroller.c
@@ -68,7 +68,7 @@ BWController *bwc_new(Messenger *m, uint32_t friendnumber,
68 void (*mcb)(BWController *, uint32_t, float, void *), 68 void (*mcb)(BWController *, uint32_t, float, void *),
69 void *udata) 69 void *udata)
70{ 70{
71 BWController *retu = calloc(sizeof(struct BWController_s), 1); 71 BWController *retu = (BWController *)calloc(sizeof(struct BWController_s), 1);
72 72
73 retu->mcb = mcb; 73 retu->mcb = mcb;
74 retu->mcb_data = udata; 74 retu->mcb_data = udata;
@@ -210,5 +210,5 @@ int bwc_handle_data(Messenger *m, uint32_t friendnumber, const uint8_t *data, ui
210 return -1; 210 return -1;
211 } 211 }
212 212
213 return on_update(object, (const struct BWCMessage *)(data + 1)); 213 return on_update((BWController *)object, (const struct BWCMessage *)(data + 1));
214} 214}
diff --git a/toxav/group.c b/toxav/group.c
index 66c73572..ddefbcc4 100644
--- a/toxav/group.c
+++ b/toxav/group.c
@@ -55,11 +55,11 @@ static Group_JitterBuffer *create_queue(unsigned int capacity)
55 55
56 Group_JitterBuffer *q; 56 Group_JitterBuffer *q;
57 57
58 if (!(q = calloc(sizeof(Group_JitterBuffer), 1))) { 58 if (!(q = (Group_JitterBuffer *)calloc(sizeof(Group_JitterBuffer), 1))) {
59 return NULL; 59 return NULL;
60 } 60 }
61 61
62 if (!(q->queue = calloc(sizeof(Group_Audio_Packet *), size))) { 62 if (!(q->queue = (Group_Audio_Packet **)calloc(sizeof(Group_Audio_Packet *), size))) {
63 free(q); 63 free(q);
64 return NULL; 64 return NULL;
65 } 65 }
@@ -233,7 +233,7 @@ static Group_AV *new_group_av(Logger *log, Group_Chats *g_c, void (*audio_callba
233 return NULL; 233 return NULL;
234 } 234 }
235 235
236 Group_AV *group_av = calloc(1, sizeof(Group_AV)); 236 Group_AV *group_av = (Group_AV *)calloc(1, sizeof(Group_AV));
237 237
238 if (!group_av) { 238 if (!group_av) {
239 return NULL; 239 return NULL;
@@ -250,8 +250,8 @@ static Group_AV *new_group_av(Logger *log, Group_Chats *g_c, void (*audio_callba
250 250
251static void group_av_peer_new(void *object, int groupnumber, int friendgroupnumber) 251static void group_av_peer_new(void *object, int groupnumber, int friendgroupnumber)
252{ 252{
253 Group_AV *group_av = object; 253 Group_AV *group_av = (Group_AV *)object;
254 Group_Peer_AV *peer_av = calloc(1, sizeof(Group_Peer_AV)); 254 Group_Peer_AV *peer_av = (Group_Peer_AV *)calloc(1, sizeof(Group_Peer_AV));
255 255
256 if (!peer_av) { 256 if (!peer_av) {
257 return; 257 return;
@@ -263,7 +263,7 @@ static void group_av_peer_new(void *object, int groupnumber, int friendgroupnumb
263 263
264static void group_av_peer_delete(void *object, int groupnumber, int friendgroupnumber, void *peer_object) 264static void group_av_peer_delete(void *object, int groupnumber, int friendgroupnumber, void *peer_object)
265{ 265{
266 Group_Peer_AV *peer_av = peer_object; 266 Group_Peer_AV *peer_av = (Group_Peer_AV *)peer_object;
267 267
268 if (!peer_av) { 268 if (!peer_av) {
269 return; 269 return;
@@ -280,7 +280,7 @@ static void group_av_peer_delete(void *object, int groupnumber, int friendgroupn
280static void group_av_groupchat_delete(void *object, int groupnumber) 280static void group_av_groupchat_delete(void *object, int groupnumber)
281{ 281{
282 if (object) { 282 if (object) {
283 kill_group_av(object); 283 kill_group_av((Group_AV *)object);
284 } 284 }
285} 285}
286 286
@@ -335,7 +335,7 @@ static int decode_audio_packet(Group_AV *group_av, Group_Peer_AV *peer_av, int g
335 335
336 int num_samples = opus_decoder_get_nb_samples(peer_av->audio_decoder, pk->data, pk->length); 336 int num_samples = opus_decoder_get_nb_samples(peer_av->audio_decoder, pk->data, pk->length);
337 337
338 out_audio = malloc(num_samples * peer_av->decoder_channels * sizeof(int16_t)); 338 out_audio = (int16_t *)malloc(num_samples * peer_av->decoder_channels * sizeof(int16_t));
339 339
340 if (!out_audio) { 340 if (!out_audio) {
341 free(pk); 341 free(pk);
@@ -359,7 +359,7 @@ static int decode_audio_packet(Group_AV *group_av, Group_Peer_AV *peer_av, int g
359 return -1; 359 return -1;
360 } 360 }
361 361
362 out_audio = malloc(peer_av->last_packet_samples * peer_av->decoder_channels * sizeof(int16_t)); 362 out_audio = (int16_t *)malloc(peer_av->last_packet_samples * peer_av->decoder_channels * sizeof(int16_t));
363 363
364 if (!out_audio) { 364 if (!out_audio) {
365 free(pk); 365 free(pk);
@@ -394,9 +394,9 @@ static int handle_group_audio_packet(void *object, int groupnumber, int friendgr
394 return -1; 394 return -1;
395 } 395 }
396 396
397 Group_Peer_AV *peer_av = peer_object; 397 Group_Peer_AV *peer_av = (Group_Peer_AV *)peer_object;
398 398
399 Group_Audio_Packet *pk = calloc(1, sizeof(Group_Audio_Packet) + (length - sizeof(uint16_t))); 399 Group_Audio_Packet *pk = (Group_Audio_Packet *)calloc(1, sizeof(Group_Audio_Packet) + (length - sizeof(uint16_t)));
400 400
401 if (!pk) { 401 if (!pk) {
402 return -1; 402 return -1;
@@ -413,7 +413,7 @@ static int handle_group_audio_packet(void *object, int groupnumber, int friendgr
413 return -1; 413 return -1;
414 } 414 }
415 415
416 while (decode_audio_packet(object, peer_av, groupnumber, friendgroupnumber) == 0) { 416 while (decode_audio_packet((Group_AV *)object, peer_av, groupnumber, friendgroupnumber) == 0) {
417 ; 417 ;
418 } 418 }
419 419
@@ -508,7 +508,7 @@ static int send_audio_packet(Group_Chats *g_c, int groupnumber, uint8_t *packet,
508 return -1; 508 return -1;
509 } 509 }
510 510
511 Group_AV *group_av = group_get_object(g_c, groupnumber); 511 Group_AV *group_av = (Group_AV *)group_get_object(g_c, groupnumber);
512 uint8_t data[1 + sizeof(uint16_t) + length]; 512 uint8_t data[1 + sizeof(uint16_t) + length];
513 data[0] = GROUP_AUDIO_PACKET_ID; 513 data[0] = GROUP_AUDIO_PACKET_ID;
514 514
@@ -532,7 +532,7 @@ static int send_audio_packet(Group_Chats *g_c, int groupnumber, uint8_t *packet,
532int group_send_audio(Group_Chats *g_c, int groupnumber, const int16_t *pcm, unsigned int samples, uint8_t channels, 532int group_send_audio(Group_Chats *g_c, int groupnumber, const int16_t *pcm, unsigned int samples, uint8_t channels,
533 unsigned int sample_rate) 533 unsigned int sample_rate)
534{ 534{
535 Group_AV *group_av = group_get_object(g_c, groupnumber); 535 Group_AV *group_av = (Group_AV *)group_get_object(g_c, groupnumber);
536 536
537 if (!group_av) { 537 if (!group_av) {
538 return -1; 538 return -1;
diff --git a/toxav/msi.c b/toxav/msi.c
index 39086567..f1c40662 100644
--- a/toxav/msi.c
+++ b/toxav/msi.c
@@ -111,7 +111,7 @@ MSISession *msi_new(Messenger *m)
111 return NULL; 111 return NULL;
112 } 112 }
113 113
114 MSISession *retu = calloc(sizeof(MSISession), 1); 114 MSISession *retu = (MSISession *)calloc(sizeof(MSISession), 1);
115 115
116 if (retu == NULL) { 116 if (retu == NULL) {
117 LOGGER_ERROR(m->log, "Allocation failed! Program might misbehave!"); 117 LOGGER_ERROR(m->log, "Allocation failed! Program might misbehave!");
@@ -337,8 +337,8 @@ int msg_parse_in(Logger *log, MSIMessage *dest, const uint8_t *data, uint16_t le
337#define CHECK_ENUM_HIGH(bytes, enum_high) /* Assumes size == 1 */ \ 337#define CHECK_ENUM_HIGH(bytes, enum_high) /* Assumes size == 1 */ \
338 if (bytes[2] > enum_high) { LOGGER_ERROR(log, "Failed enum high limit!"); return -1; } 338 if (bytes[2] > enum_high) { LOGGER_ERROR(log, "Failed enum high limit!"); return -1; }
339 339
340#define SET_UINT8(bytes, header) do { \ 340#define SET_UINT8(type, bytes, header) do { \
341 header.value = bytes[2]; \ 341 header.value = (type)bytes[2]; \
342 header.exists = true; \ 342 header.exists = true; \
343 bytes += 3; \ 343 bytes += 3; \
344 } while(0) 344 } while(0)
@@ -367,18 +367,18 @@ int msg_parse_in(Logger *log, MSIMessage *dest, const uint8_t *data, uint16_t le
367 case IDRequest: 367 case IDRequest:
368 CHECK_SIZE(it, size_constraint, 1); 368 CHECK_SIZE(it, size_constraint, 1);
369 CHECK_ENUM_HIGH(it, requ_pop); 369 CHECK_ENUM_HIGH(it, requ_pop);
370 SET_UINT8(it, dest->request); 370 SET_UINT8(MSIRequest, it, dest->request);
371 break; 371 break;
372 372
373 case IDError: 373 case IDError:
374 CHECK_SIZE(it, size_constraint, 1); 374 CHECK_SIZE(it, size_constraint, 1);
375 CHECK_ENUM_HIGH(it, msi_EUndisclosed); 375 CHECK_ENUM_HIGH(it, msi_EUndisclosed);
376 SET_UINT8(it, dest->error); 376 SET_UINT8(MSIError, it, dest->error);
377 break; 377 break;
378 378
379 case IDCapabilities: 379 case IDCapabilities:
380 CHECK_SIZE(it, size_constraint, 1); 380 CHECK_SIZE(it, size_constraint, 1);
381 SET_UINT8(it, dest->capabilities); 381 SET_UINT8(uint8_t, it, dest->capabilities);
382 break; 382 break;
383 383
384 default: 384 default:
@@ -519,7 +519,7 @@ MSICall *new_call(MSISession *session, uint32_t friend_number)
519{ 519{
520 assert(session); 520 assert(session);
521 521
522 MSICall *rc = calloc(sizeof(MSICall), 1); 522 MSICall *rc = (MSICall *)calloc(sizeof(MSICall), 1);
523 523
524 if (rc == NULL) { 524 if (rc == NULL) {
525 return NULL; 525 return NULL;
@@ -529,7 +529,7 @@ MSICall *new_call(MSISession *session, uint32_t friend_number)
529 rc->friend_number = friend_number; 529 rc->friend_number = friend_number;
530 530
531 if (session->calls == NULL) { /* Creating */ 531 if (session->calls == NULL) { /* Creating */
532 session->calls = calloc(sizeof(MSICall *), friend_number + 1); 532 session->calls = (MSICall **)calloc(sizeof(MSICall *), friend_number + 1);
533 533
534 if (session->calls == NULL) { 534 if (session->calls == NULL) {
535 free(rc); 535 free(rc);
@@ -538,7 +538,7 @@ MSICall *new_call(MSISession *session, uint32_t friend_number)
538 538
539 session->calls_tail = session->calls_head = friend_number; 539 session->calls_tail = session->calls_head = friend_number;
540 } else if (session->calls_tail < friend_number) { /* Appending */ 540 } else if (session->calls_tail < friend_number) { /* Appending */
541 void *tmp = realloc(session->calls, sizeof(MSICall *) * (friend_number + 1)); 541 MSICall **tmp = (MSICall **)realloc(session->calls, sizeof(MSICall *) * (friend_number + 1));
542 542
543 if (tmp == NULL) { 543 if (tmp == NULL) {
544 free(rc); 544 free(rc);
@@ -610,7 +610,7 @@ CLEAR_CONTAINER:
610void on_peer_status(Messenger *m, uint32_t friend_number, uint8_t status, void *data) 610void on_peer_status(Messenger *m, uint32_t friend_number, uint8_t status, void *data)
611{ 611{
612 (void)m; 612 (void)m;
613 MSISession *session = data; 613 MSISession *session = (MSISession *)data;
614 614
615 switch (status) { 615 switch (status) {
616 case 0: { /* Friend is now offline */ 616 case 0: { /* Friend is now offline */
@@ -799,7 +799,7 @@ void handle_msi_packet(Messenger *m, uint32_t friend_number, const uint8_t *data
799{ 799{
800 LOGGER_DEBUG(m->log, "Got msi message"); 800 LOGGER_DEBUG(m->log, "Got msi message");
801 801
802 MSISession *session = object; 802 MSISession *session = (MSISession *)object;
803 MSIMessage msg; 803 MSIMessage msg;
804 804
805 if (msg_parse_in(m->log, &msg, data, length) == -1) { 805 if (msg_parse_in(m->log, &msg, data, length) == -1) {
diff --git a/toxav/rtp.c b/toxav/rtp.c
index 534efc1a..edab1b1c 100644
--- a/toxav/rtp.c
+++ b/toxav/rtp.c
@@ -46,7 +46,7 @@ RTPSession *rtp_new(int payload_type, Messenger *m, uint32_t friendnumber,
46 assert(cs); 46 assert(cs);
47 assert(m); 47 assert(m);
48 48
49 RTPSession *retu = calloc(1, sizeof(RTPSession)); 49 RTPSession *retu = (RTPSession *)calloc(1, sizeof(RTPSession));
50 50
51 if (!retu) { 51 if (!retu) {
52 LOGGER_WARNING(m->log, "Alloc failed! Program might misbehave!"); 52 LOGGER_WARNING(m->log, "Alloc failed! Program might misbehave!");
@@ -219,7 +219,8 @@ static struct RTPMessage *new_message(size_t allocate_len, const uint8_t *data,
219{ 219{
220 assert(allocate_len >= data_length); 220 assert(allocate_len >= data_length);
221 221
222 struct RTPMessage *msg = calloc(sizeof(struct RTPMessage) + (allocate_len - sizeof(struct RTPHeader)), 1); 222 struct RTPMessage *msg = (struct RTPMessage *)calloc(sizeof(struct RTPMessage) + (allocate_len - sizeof(
223 struct RTPHeader)), 1);
223 224
224 msg->len = data_length - sizeof(struct RTPHeader); 225 msg->len = data_length - sizeof(struct RTPHeader);
225 memcpy(&msg->header, data, data_length); 226 memcpy(&msg->header, data, data_length);
@@ -238,7 +239,7 @@ int handle_rtp_packet(Messenger *m, uint32_t friendnumber, const uint8_t *data,
238 (void) m; 239 (void) m;
239 (void) friendnumber; 240 (void) friendnumber;
240 241
241 RTPSession *session = object; 242 RTPSession *session = (RTPSession *)object;
242 243
243 data ++; 244 data ++;
244 length--; 245 length--;
diff --git a/toxav/toxav.c b/toxav/toxav.c
index 1ae914e8..a5314d23 100644
--- a/toxav/toxav.c
+++ b/toxav/toxav.c
@@ -146,7 +146,7 @@ ToxAV *toxav_new(Tox *tox, TOXAV_ERR_NEW *error)
146 goto END; 146 goto END;
147 } 147 }
148 148
149 av = calloc(sizeof(ToxAV), 1); 149 av = (ToxAV *)calloc(sizeof(ToxAV), 1);
150 150
151 if (av == NULL) { 151 if (av == NULL) {
152 LOGGER_WARNING(m->log, "Allocation failed!"); 152 LOGGER_WARNING(m->log, "Allocation failed!");
@@ -289,6 +289,7 @@ bool toxav_call(ToxAV *av, uint32_t friend_number, uint32_t audio_bit_rate, uint
289 TOXAV_ERR_CALL *error) 289 TOXAV_ERR_CALL *error)
290{ 290{
291 TOXAV_ERR_CALL rc = TOXAV_ERR_CALL_OK; 291 TOXAV_ERR_CALL rc = TOXAV_ERR_CALL_OK;
292 ToxAVCall *call;
292 293
293 pthread_mutex_lock(av->mutex); 294 pthread_mutex_lock(av->mutex);
294 295
@@ -298,7 +299,7 @@ bool toxav_call(ToxAV *av, uint32_t friend_number, uint32_t audio_bit_rate, uint
298 goto END; 299 goto END;
299 } 300 }
300 301
301 ToxAVCall *call = call_new(av, friend_number, &rc); 302 call = call_new(av, friend_number, &rc);
302 303
303 if (call == NULL) { 304 if (call == NULL) {
304 goto END; 305 goto END;
@@ -342,6 +343,7 @@ bool toxav_answer(ToxAV *av, uint32_t friend_number, uint32_t audio_bit_rate, ui
342 pthread_mutex_lock(av->mutex); 343 pthread_mutex_lock(av->mutex);
343 344
344 TOXAV_ERR_ANSWER rc = TOXAV_ERR_ANSWER_OK; 345 TOXAV_ERR_ANSWER rc = TOXAV_ERR_ANSWER_OK;
346 ToxAVCall *call;
345 347
346 if (m_friend_exists(av->m, friend_number) == 0) { 348 if (m_friend_exists(av->m, friend_number) == 0) {
347 rc = TOXAV_ERR_ANSWER_FRIEND_NOT_FOUND; 349 rc = TOXAV_ERR_ANSWER_FRIEND_NOT_FOUND;
@@ -355,7 +357,7 @@ bool toxav_answer(ToxAV *av, uint32_t friend_number, uint32_t audio_bit_rate, ui
355 goto END; 357 goto END;
356 } 358 }
357 359
358 ToxAVCall *call = call_get(av, friend_number); 360 call = call_get(av, friend_number);
359 361
360 if (call == NULL) { 362 if (call == NULL) {
361 rc = TOXAV_ERR_ANSWER_FRIEND_NOT_CALLING; 363 rc = TOXAV_ERR_ANSWER_FRIEND_NOT_CALLING;
@@ -399,13 +401,14 @@ bool toxav_call_control(ToxAV *av, uint32_t friend_number, TOXAV_CALL_CONTROL co
399{ 401{
400 pthread_mutex_lock(av->mutex); 402 pthread_mutex_lock(av->mutex);
401 TOXAV_ERR_CALL_CONTROL rc = TOXAV_ERR_CALL_CONTROL_OK; 403 TOXAV_ERR_CALL_CONTROL rc = TOXAV_ERR_CALL_CONTROL_OK;
404 ToxAVCall *call;
402 405
403 if (m_friend_exists(av->m, friend_number) == 0) { 406 if (m_friend_exists(av->m, friend_number) == 0) {
404 rc = TOXAV_ERR_CALL_CONTROL_FRIEND_NOT_FOUND; 407 rc = TOXAV_ERR_CALL_CONTROL_FRIEND_NOT_FOUND;
405 goto END; 408 goto END;
406 } 409 }
407 410
408 ToxAVCall *call = call_get(av, friend_number); 411 call = call_get(av, friend_number);
409 412
410 if (call == NULL || (!call->active && control != TOXAV_CALL_CONTROL_CANCEL)) { 413 if (call == NULL || (!call->active && control != TOXAV_CALL_CONTROL_CANCEL)) {
411 rc = TOXAV_ERR_CALL_CONTROL_FRIEND_NOT_IN_CALL; 414 rc = TOXAV_ERR_CALL_CONTROL_FRIEND_NOT_IN_CALL;
@@ -815,8 +818,8 @@ bool toxav_video_send_frame(ToxAV *av, uint32_t friend_number, uint16_t width, u
815 memcpy(img.planes[VPX_PLANE_U], u, (width / 2) * (height / 2)); 818 memcpy(img.planes[VPX_PLANE_U], u, (width / 2) * (height / 2));
816 memcpy(img.planes[VPX_PLANE_V], v, (width / 2) * (height / 2)); 819 memcpy(img.planes[VPX_PLANE_V], v, (width / 2) * (height / 2));
817 820
818 int vrc = vpx_codec_encode(call->video.second->encoder, &img, 821 vpx_codec_err_t vrc = vpx_codec_encode(call->video.second->encoder, &img,
819 call->video.second->frame_counter, 1, 0, MAX_ENCODE_TIME_US); 822 call->video.second->frame_counter, 1, 0, MAX_ENCODE_TIME_US);
820 823
821 vpx_img_free(&img); 824 vpx_img_free(&img);
822 825
@@ -836,7 +839,7 @@ bool toxav_video_send_frame(ToxAV *av, uint32_t friend_number, uint16_t width, u
836 839
837 while ((pkt = vpx_codec_get_cx_data(call->video.second->encoder, &iter))) { 840 while ((pkt = vpx_codec_get_cx_data(call->video.second->encoder, &iter))) {
838 if (pkt->kind == VPX_CODEC_CX_FRAME_PKT && 841 if (pkt->kind == VPX_CODEC_CX_FRAME_PKT &&
839 rtp_send_data(call->video.first, pkt->data.frame.buf, pkt->data.frame.sz) < 0) { 842 rtp_send_data(call->video.first, (const uint8_t *)pkt->data.frame.buf, pkt->data.frame.sz) < 0) {
840 843
841 pthread_mutex_unlock(call->mutex_video); 844 pthread_mutex_unlock(call->mutex_video);
842 LOGGER_WARNING(av->m->log, "Could not send video frame: %s\n", strerror(errno)); 845 LOGGER_WARNING(av->m->log, "Could not send video frame: %s\n", strerror(errno));
@@ -886,7 +889,7 @@ void callback_bwc(BWController *bwc, uint32_t friend_number, float loss, void *u
886 * The application may choose to disable video totally if the stream is too bad. 889 * The application may choose to disable video totally if the stream is too bad.
887 */ 890 */
888 891
889 ToxAVCall *call = user_data; 892 ToxAVCall *call = (ToxAVCall *)user_data;
890 assert(call); 893 assert(call);
891 894
892 LOGGER_DEBUG(call->av->m->log, "Reported loss of %f%%", loss * 100); 895 LOGGER_DEBUG(call->av->m->log, "Reported loss of %f%%", loss * 100);
@@ -917,7 +920,7 @@ void callback_bwc(BWController *bwc, uint32_t friend_number, float loss, void *u
917} 920}
918int callback_invite(void *toxav_inst, MSICall *call) 921int callback_invite(void *toxav_inst, MSICall *call)
919{ 922{
920 ToxAV *toxav = toxav_inst; 923 ToxAV *toxav = (ToxAV *)toxav_inst;
921 pthread_mutex_lock(toxav->mutex); 924 pthread_mutex_lock(toxav->mutex);
922 925
923 ToxAVCall *av_call = call_new(toxav, call->friend_number, NULL); 926 ToxAVCall *av_call = call_new(toxav, call->friend_number, NULL);
@@ -945,7 +948,7 @@ int callback_invite(void *toxav_inst, MSICall *call)
945} 948}
946int callback_start(void *toxav_inst, MSICall *call) 949int callback_start(void *toxav_inst, MSICall *call)
947{ 950{
948 ToxAV *toxav = toxav_inst; 951 ToxAV *toxav = (ToxAV *)toxav_inst;
949 pthread_mutex_lock(toxav->mutex); 952 pthread_mutex_lock(toxav->mutex);
950 953
951 ToxAVCall *av_call = call_get(toxav, call->friend_number); 954 ToxAVCall *av_call = call_get(toxav, call->friend_number);
@@ -973,14 +976,14 @@ int callback_start(void *toxav_inst, MSICall *call)
973} 976}
974int callback_end(void *toxav_inst, MSICall *call) 977int callback_end(void *toxav_inst, MSICall *call)
975{ 978{
976 ToxAV *toxav = toxav_inst; 979 ToxAV *toxav = (ToxAV *)toxav_inst;
977 pthread_mutex_lock(toxav->mutex); 980 pthread_mutex_lock(toxav->mutex);
978 981
979 invoke_call_state_callback(toxav, call->friend_number, TOXAV_FRIEND_CALL_STATE_FINISHED); 982 invoke_call_state_callback(toxav, call->friend_number, TOXAV_FRIEND_CALL_STATE_FINISHED);
980 983
981 if (call->av_call) { 984 if (call->av_call) {
982 call_kill_transmission(call->av_call); 985 call_kill_transmission((ToxAVCall *)call->av_call);
983 call_remove(call->av_call); 986 call_remove((ToxAVCall *)call->av_call);
984 } 987 }
985 988
986 pthread_mutex_unlock(toxav->mutex); 989 pthread_mutex_unlock(toxav->mutex);
@@ -988,14 +991,14 @@ int callback_end(void *toxav_inst, MSICall *call)
988} 991}
989int callback_error(void *toxav_inst, MSICall *call) 992int callback_error(void *toxav_inst, MSICall *call)
990{ 993{
991 ToxAV *toxav = toxav_inst; 994 ToxAV *toxav = (ToxAV *)toxav_inst;
992 pthread_mutex_lock(toxav->mutex); 995 pthread_mutex_lock(toxav->mutex);
993 996
994 invoke_call_state_callback(toxav, call->friend_number, TOXAV_FRIEND_CALL_STATE_ERROR); 997 invoke_call_state_callback(toxav, call->friend_number, TOXAV_FRIEND_CALL_STATE_ERROR);
995 998
996 if (call->av_call) { 999 if (call->av_call) {
997 call_kill_transmission(call->av_call); 1000 call_kill_transmission((ToxAVCall *)call->av_call);
998 call_remove(call->av_call); 1001 call_remove((ToxAVCall *)call->av_call);
999 } 1002 }
1000 1003
1001 pthread_mutex_unlock(toxav->mutex); 1004 pthread_mutex_unlock(toxav->mutex);
@@ -1003,7 +1006,7 @@ int callback_error(void *toxav_inst, MSICall *call)
1003} 1006}
1004int callback_capabilites(void *toxav_inst, MSICall *call) 1007int callback_capabilites(void *toxav_inst, MSICall *call)
1005{ 1008{
1006 ToxAV *toxav = toxav_inst; 1009 ToxAV *toxav = (ToxAV *)toxav_inst;
1007 pthread_mutex_lock(toxav->mutex); 1010 pthread_mutex_lock(toxav->mutex);
1008 1011
1009 if (call->peer_capabilities & msi_CapSAudio) { 1012 if (call->peer_capabilities & msi_CapSAudio) {
@@ -1068,7 +1071,7 @@ ToxAVCall *call_new(ToxAV *av, uint32_t friend_number, TOXAV_ERR_CALL *error)
1068 } 1071 }
1069 1072
1070 1073
1071 call = calloc(sizeof(ToxAVCall), 1); 1074 call = (ToxAVCall *)calloc(sizeof(ToxAVCall), 1);
1072 1075
1073 if (call == NULL) { 1076 if (call == NULL) {
1074 rc = TOXAV_ERR_CALL_MALLOC; 1077 rc = TOXAV_ERR_CALL_MALLOC;
@@ -1079,7 +1082,7 @@ ToxAVCall *call_new(ToxAV *av, uint32_t friend_number, TOXAV_ERR_CALL *error)
1079 call->friend_number = friend_number; 1082 call->friend_number = friend_number;
1080 1083
1081 if (av->calls == NULL) { /* Creating */ 1084 if (av->calls == NULL) { /* Creating */
1082 av->calls = calloc(sizeof(ToxAVCall *), friend_number + 1); 1085 av->calls = (ToxAVCall **)calloc(sizeof(ToxAVCall *), friend_number + 1);
1083 1086
1084 if (av->calls == NULL) { 1087 if (av->calls == NULL) {
1085 free(call); 1088 free(call);
@@ -1090,7 +1093,7 @@ ToxAVCall *call_new(ToxAV *av, uint32_t friend_number, TOXAV_ERR_CALL *error)
1090 1093
1091 av->calls_tail = av->calls_head = friend_number; 1094 av->calls_tail = av->calls_head = friend_number;
1092 } else if (av->calls_tail < friend_number) { /* Appending */ 1095 } else if (av->calls_tail < friend_number) { /* Appending */
1093 void *tmp = realloc(av->calls, sizeof(ToxAVCall *) * (friend_number + 1)); 1096 ToxAVCall **tmp = (ToxAVCall **)realloc(av->calls, sizeof(ToxAVCall *) * (friend_number + 1));
1094 1097
1095 if (tmp == NULL) { 1098 if (tmp == NULL) {
1096 free(call); 1099 free(call);
diff --git a/toxav/toxav_old.c b/toxav/toxav_old.c
index a344455d..767fac9c 100644
--- a/toxav/toxav_old.c
+++ b/toxav/toxav_old.c
@@ -40,8 +40,9 @@ int toxav_add_av_groupchat(struct Tox *tox, void (*audio_callback)(void *, int,
40 uint8_t, unsigned int, void *), void *userdata) 40 uint8_t, unsigned int, void *), void *userdata)
41{ 41{
42 Messenger *m = (Messenger *)tox; 42 Messenger *m = (Messenger *)tox;
43 return add_av_groupchat(m->log, m->group_chat_object, (void (*)(Messenger *, int, int, const int16_t *, unsigned int, 43 return add_av_groupchat(m->log, (Group_Chats *)m->group_chat_object,
44 uint8_t, unsigned int, void *))audio_callback, userdata); 44 (void (*)(Messenger *, int, int, const int16_t *, unsigned int, uint8_t, unsigned int, void *))audio_callback,
45 userdata);
45} 46}
46 47
47/* Join a AV group (you need to have been invited first.) 48/* Join a AV group (you need to have been invited first.)
@@ -59,7 +60,8 @@ int toxav_join_av_groupchat(struct Tox *tox, int32_t friendnumber, const uint8_t
59 void *userdata) 60 void *userdata)
60{ 61{
61 Messenger *m = (Messenger *)tox; 62 Messenger *m = (Messenger *)tox;
62 return join_av_groupchat(m->log, m->group_chat_object, friendnumber, data, length, (void (*)(Messenger *, int, int, 63 return join_av_groupchat(m->log, (Group_Chats *)m->group_chat_object, friendnumber, data, length, (void (*)(Messenger *,
64 int, int,
63 const int16_t *, unsigned int, uint8_t, unsigned int, void *))audio_callback, userdata); 65 const int16_t *, unsigned int, uint8_t, unsigned int, void *))audio_callback, userdata);
64} 66}
65 67
@@ -80,5 +82,5 @@ int toxav_group_send_audio(struct Tox *tox, int groupnumber, const int16_t *pcm,
80 unsigned int sample_rate) 82 unsigned int sample_rate)
81{ 83{
82 Messenger *m = (Messenger *)tox; 84 Messenger *m = (Messenger *)tox;
83 return group_send_audio(m->group_chat_object, groupnumber, pcm, samples, channels, sample_rate); 85 return group_send_audio((Group_Chats *)m->group_chat_object, groupnumber, pcm, samples, channels, sample_rate);
84} 86}
diff --git a/toxav/video.c b/toxav/video.c
index de028c7c..5bb3b8ae 100644
--- a/toxav/video.c
+++ b/toxav/video.c
@@ -39,7 +39,8 @@
39 39
40VCSession *vc_new(Logger *log, ToxAV *av, uint32_t friend_number, toxav_video_receive_frame_cb *cb, void *cb_data) 40VCSession *vc_new(Logger *log, ToxAV *av, uint32_t friend_number, toxav_video_receive_frame_cb *cb, void *cb_data)
41{ 41{
42 VCSession *vc = calloc(sizeof(VCSession), 1); 42 VCSession *vc = (VCSession *)calloc(sizeof(VCSession), 1);
43 vpx_codec_err_t rc;
43 44
44 if (!vc) { 45 if (!vc) {
45 LOGGER_WARNING(log, "Allocation failed! Application might misbehave!"); 46 LOGGER_WARNING(log, "Allocation failed! Application might misbehave!");
@@ -56,7 +57,7 @@ VCSession *vc_new(Logger *log, ToxAV *av, uint32_t friend_number, toxav_video_re
56 goto BASE_CLEANUP; 57 goto BASE_CLEANUP;
57 } 58 }
58 59
59 int rc = vpx_codec_dec_init(vc->decoder, VIDEO_CODEC_DECODER_INTERFACE, NULL, 0); 60 rc = vpx_codec_dec_init(vc->decoder, VIDEO_CODEC_DECODER_INTERFACE, NULL, 0);
60 61
61 if (rc != VPX_CODEC_OK) { 62 if (rc != VPX_CODEC_OK) {
62 LOGGER_ERROR(log, "Init video_decoder failed: %s", vpx_codec_err_to_string(rc)); 63 LOGGER_ERROR(log, "Init video_decoder failed: %s", vpx_codec_err_to_string(rc));
@@ -116,7 +117,7 @@ BASE_CLEANUP_1:
116 vpx_codec_destroy(vc->decoder); 117 vpx_codec_destroy(vc->decoder);
117BASE_CLEANUP: 118BASE_CLEANUP:
118 pthread_mutex_destroy(vc->queue_mutex); 119 pthread_mutex_destroy(vc->queue_mutex);
119 rb_kill(vc->vbuf_raw); 120 rb_kill((RingBuffer *)vc->vbuf_raw);
120 free(vc); 121 free(vc);
121 return NULL; 122 return NULL;
122} 123}
@@ -131,11 +132,11 @@ void vc_kill(VCSession *vc)
131 132
132 void *p; 133 void *p;
133 134
134 while (rb_read(vc->vbuf_raw, &p)) { 135 while (rb_read((RingBuffer *)vc->vbuf_raw, &p)) {
135 free(p); 136 free(p);
136 } 137 }
137 138
138 rb_kill(vc->vbuf_raw); 139 rb_kill((RingBuffer *)vc->vbuf_raw);
139 140
140 pthread_mutex_destroy(vc->queue_mutex); 141 pthread_mutex_destroy(vc->queue_mutex);
141 142
@@ -150,11 +151,11 @@ void vc_iterate(VCSession *vc)
150 151
151 struct RTPMessage *p; 152 struct RTPMessage *p;
152 153
153 int rc; 154 vpx_codec_err_t rc;
154 155
155 pthread_mutex_lock(vc->queue_mutex); 156 pthread_mutex_lock(vc->queue_mutex);
156 157
157 if (rb_read(vc->vbuf_raw, (void **)&p)) { 158 if (rb_read((RingBuffer *)vc->vbuf_raw, (void **)&p)) {
158 pthread_mutex_unlock(vc->queue_mutex); 159 pthread_mutex_unlock(vc->queue_mutex);
159 160
160 rc = vpx_codec_decode(vc->decoder, p->data, p->len, NULL, MAX_DECODE_TIME_US); 161 rc = vpx_codec_decode(vc->decoder, p->data, p->len, NULL, MAX_DECODE_TIME_US);
@@ -192,7 +193,7 @@ int vc_queue_message(void *vcp, struct RTPMessage *msg)
192 return -1; 193 return -1;
193 } 194 }
194 195
195 VCSession *vc = vcp; 196 VCSession *vc = (VCSession *)vcp;
196 197
197 if (msg->header.pt == (rtp_TypeVideo + 2) % 128) { 198 if (msg->header.pt == (rtp_TypeVideo + 2) % 128) {
198 LOGGER_WARNING(vc->log, "Got dummy!"); 199 LOGGER_WARNING(vc->log, "Got dummy!");
@@ -207,7 +208,7 @@ int vc_queue_message(void *vcp, struct RTPMessage *msg)
207 } 208 }
208 209
209 pthread_mutex_lock(vc->queue_mutex); 210 pthread_mutex_lock(vc->queue_mutex);
210 free(rb_write(vc->vbuf_raw, msg)); 211 free(rb_write((RingBuffer *)vc->vbuf_raw, msg));
211 { 212 {
212 /* Calculate time took for peer to send us this frame */ 213 /* Calculate time took for peer to send us this frame */
213 uint32_t t_lcfd = current_time_monotonic() - vc->linfts; 214 uint32_t t_lcfd = current_time_monotonic() - vc->linfts;
@@ -225,7 +226,7 @@ int vc_reconfigure_encoder(VCSession *vc, uint32_t bit_rate, uint16_t width, uin
225 } 226 }
226 227
227 vpx_codec_enc_cfg_t cfg = *vc->encoder->config.enc; 228 vpx_codec_enc_cfg_t cfg = *vc->encoder->config.enc;
228 int rc; 229 vpx_codec_err_t rc;
229 230
230 if (cfg.rc_target_bitrate == bit_rate && cfg.g_w == width && cfg.g_h == height) { 231 if (cfg.rc_target_bitrate == bit_rate && cfg.g_w == width && cfg.g_h == height) {
231 return 0; /* Nothing changed */ 232 return 0; /* Nothing changed */
diff --git a/toxcore/DHT.c b/toxcore/DHT.c
index 2f078314..ed03fac8 100644
--- a/toxcore/DHT.c
+++ b/toxcore/DHT.c
@@ -985,24 +985,24 @@ static unsigned int ping_node_from_getnodes_ok(DHT *dht, const uint8_t *public_k
985 for (i = 0; i < dht->num_friends; ++i) { 985 for (i = 0; i < dht->num_friends; ++i) {
986 bool store_ok = 0; 986 bool store_ok = 0;
987 987
988 DHT_Friend *friend = &dht->friends_list[i]; 988 DHT_Friend *dht_friend = &dht->friends_list[i];
989 989
990 if (store_node_ok(&friend->client_list[1], public_key, friend->public_key)) { 990 if (store_node_ok(&dht_friend->client_list[1], public_key, dht_friend->public_key)) {
991 store_ok = 1; 991 store_ok = 1;
992 } 992 }
993 993
994 if (store_node_ok(&friend->client_list[0], public_key, friend->public_key)) { 994 if (store_node_ok(&dht_friend->client_list[0], public_key, dht_friend->public_key)) {
995 store_ok = 1; 995 store_ok = 1;
996 } 996 }
997 997
998 if (store_ok && !client_in_nodelist(friend->to_bootstrap, friend->num_to_bootstrap, public_key) 998 if (store_ok && !client_in_nodelist(dht_friend->to_bootstrap, dht_friend->num_to_bootstrap, public_key)
999 && !is_pk_in_client_list(friend->client_list, MAX_FRIEND_CLIENTS, public_key, ip_port)) { 999 && !is_pk_in_client_list(dht_friend->client_list, MAX_FRIEND_CLIENTS, public_key, ip_port)) {
1000 if (friend->num_to_bootstrap < MAX_SENT_NODES) { 1000 if (dht_friend->num_to_bootstrap < MAX_SENT_NODES) {
1001 memcpy(friend->to_bootstrap[friend->num_to_bootstrap].public_key, public_key, crypto_box_PUBLICKEYBYTES); 1001 memcpy(dht_friend->to_bootstrap[dht_friend->num_to_bootstrap].public_key, public_key, crypto_box_PUBLICKEYBYTES);
1002 friend->to_bootstrap[friend->num_to_bootstrap].ip_port = ip_port; 1002 dht_friend->to_bootstrap[dht_friend->num_to_bootstrap].ip_port = ip_port;
1003 ++friend->num_to_bootstrap; 1003 ++dht_friend->num_to_bootstrap;
1004 } else { 1004 } else {
1005 add_to_list(friend->to_bootstrap, MAX_SENT_NODES, public_key, ip_port, friend->public_key); 1005 add_to_list(dht_friend->to_bootstrap, MAX_SENT_NODES, public_key, ip_port, dht_friend->public_key);
1006 } 1006 }
1007 1007
1008 ret = 1; 1008 ret = 1;
@@ -1046,19 +1046,19 @@ int addto_lists(DHT *dht, IP_Port ip_port, const uint8_t *public_key)
1046 if (replace_all(dht->friends_list[i].client_list, MAX_FRIEND_CLIENTS, 1046 if (replace_all(dht->friends_list[i].client_list, MAX_FRIEND_CLIENTS,
1047 public_key, ip_port, dht->friends_list[i].public_key)) { 1047 public_key, ip_port, dht->friends_list[i].public_key)) {
1048 1048
1049 DHT_Friend *friend = &dht->friends_list[i]; 1049 DHT_Friend *dht_friend = &dht->friends_list[i];
1050 1050
1051 if (public_key_cmp(public_key, friend->public_key) == 0) { 1051 if (public_key_cmp(public_key, dht_friend->public_key) == 0) {
1052 friend_foundip = friend; 1052 friend_foundip = dht_friend;
1053 } 1053 }
1054 1054
1055 used++; 1055 used++;
1056 } 1056 }
1057 } else { 1057 } else {
1058 DHT_Friend *friend = &dht->friends_list[i]; 1058 DHT_Friend *dht_friend = &dht->friends_list[i];
1059 1059
1060 if (public_key_cmp(public_key, friend->public_key) == 0) { 1060 if (public_key_cmp(public_key, dht_friend->public_key) == 0) {
1061 friend_foundip = friend; 1061 friend_foundip = dht_friend;
1062 } 1062 }
1063 1063
1064 used++; 1064 used++;
@@ -1282,7 +1282,7 @@ static int handle_getnodes(void *object, IP_Port source, const uint8_t *packet,
1282 return 1; 1282 return 1;
1283 } 1283 }
1284 1284
1285 DHT *dht = object; 1285 DHT *dht = (DHT *)object;
1286 1286
1287 /* Check if packet is from ourself. */ 1287 /* Check if packet is from ourself. */
1288 if (id_equal(packet + 1, dht->self_public_key)) { 1288 if (id_equal(packet + 1, dht->self_public_key)) {
@@ -1341,7 +1341,7 @@ static int send_hardening_getnode_res(const DHT *dht, const Node_format *sendto,
1341static int handle_sendnodes_core(void *object, IP_Port source, const uint8_t *packet, uint16_t length, 1341static int handle_sendnodes_core(void *object, IP_Port source, const uint8_t *packet, uint16_t length,
1342 Node_format *plain_nodes, uint16_t size_plain_nodes, uint32_t *num_nodes_out) 1342 Node_format *plain_nodes, uint16_t size_plain_nodes, uint32_t *num_nodes_out)
1343{ 1343{
1344 DHT *dht = object; 1344 DHT *dht = (DHT *)object;
1345 uint32_t cid_size = 1 + crypto_box_PUBLICKEYBYTES + crypto_box_NONCEBYTES + 1 + sizeof(uint64_t) + crypto_box_MACBYTES; 1345 uint32_t cid_size = 1 + crypto_box_PUBLICKEYBYTES + crypto_box_NONCEBYTES + 1 + sizeof(uint64_t) + crypto_box_MACBYTES;
1346 1346
1347 if (length < cid_size) { /* too short */ 1347 if (length < cid_size) { /* too short */
@@ -1411,7 +1411,7 @@ static int handle_sendnodes_core(void *object, IP_Port source, const uint8_t *pa
1411 1411
1412static int handle_sendnodes_ipv6(void *object, IP_Port source, const uint8_t *packet, uint16_t length, void *userdata) 1412static int handle_sendnodes_ipv6(void *object, IP_Port source, const uint8_t *packet, uint16_t length, void *userdata)
1413{ 1413{
1414 DHT *dht = object; 1414 DHT *dht = (DHT *)object;
1415 Node_format plain_nodes[MAX_SENT_NODES]; 1415 Node_format plain_nodes[MAX_SENT_NODES];
1416 uint32_t num_nodes; 1416 uint32_t num_nodes;
1417 1417
@@ -1447,17 +1447,17 @@ int DHT_addfriend(DHT *dht, const uint8_t *public_key, void (*ip_callback)(void
1447 uint16_t lock_num; 1447 uint16_t lock_num;
1448 1448
1449 if (friend_num != -1) { /* Is friend already in DHT? */ 1449 if (friend_num != -1) { /* Is friend already in DHT? */
1450 DHT_Friend *friend = &dht->friends_list[friend_num]; 1450 DHT_Friend *dht_friend = &dht->friends_list[friend_num];
1451 1451
1452 if (friend->lock_count == DHT_FRIEND_MAX_LOCKS) { 1452 if (dht_friend->lock_count == DHT_FRIEND_MAX_LOCKS) {
1453 return -1; 1453 return -1;
1454 } 1454 }
1455 1455
1456 lock_num = friend->lock_count; 1456 lock_num = dht_friend->lock_count;
1457 ++friend->lock_count; 1457 ++dht_friend->lock_count;
1458 friend->callbacks[lock_num].ip_callback = ip_callback; 1458 dht_friend->callbacks[lock_num].ip_callback = ip_callback;
1459 friend->callbacks[lock_num].data = data; 1459 dht_friend->callbacks[lock_num].data = data;
1460 friend->callbacks[lock_num].number = number; 1460 dht_friend->callbacks[lock_num].number = number;
1461 1461
1462 if (lock_count) { 1462 if (lock_count) {
1463 *lock_count = lock_num + 1; 1463 *lock_count = lock_num + 1;
@@ -1466,32 +1466,31 @@ int DHT_addfriend(DHT *dht, const uint8_t *public_key, void (*ip_callback)(void
1466 return 0; 1466 return 0;
1467 } 1467 }
1468 1468
1469 DHT_Friend *temp; 1469 DHT_Friend *temp = (DHT_Friend *)realloc(dht->friends_list, sizeof(DHT_Friend) * (dht->num_friends + 1));
1470 temp = realloc(dht->friends_list, sizeof(DHT_Friend) * (dht->num_friends + 1));
1471 1470
1472 if (temp == NULL) { 1471 if (temp == NULL) {
1473 return -1; 1472 return -1;
1474 } 1473 }
1475 1474
1476 dht->friends_list = temp; 1475 dht->friends_list = temp;
1477 DHT_Friend *friend = &dht->friends_list[dht->num_friends]; 1476 DHT_Friend *dht_friend = &dht->friends_list[dht->num_friends];
1478 memset(friend, 0, sizeof(DHT_Friend)); 1477 memset(dht_friend, 0, sizeof(DHT_Friend));
1479 memcpy(friend->public_key, public_key, crypto_box_PUBLICKEYBYTES); 1478 memcpy(dht_friend->public_key, public_key, crypto_box_PUBLICKEYBYTES);
1480 1479
1481 friend->nat.NATping_id = random_64b(); 1480 dht_friend->nat.NATping_id = random_64b();
1482 ++dht->num_friends; 1481 ++dht->num_friends;
1483 1482
1484 lock_num = friend->lock_count; 1483 lock_num = dht_friend->lock_count;
1485 ++friend->lock_count; 1484 ++dht_friend->lock_count;
1486 friend->callbacks[lock_num].ip_callback = ip_callback; 1485 dht_friend->callbacks[lock_num].ip_callback = ip_callback;
1487 friend->callbacks[lock_num].data = data; 1486 dht_friend->callbacks[lock_num].data = data;
1488 friend->callbacks[lock_num].number = number; 1487 dht_friend->callbacks[lock_num].number = number;
1489 1488
1490 if (lock_count) { 1489 if (lock_count) {
1491 *lock_count = lock_num + 1; 1490 *lock_count = lock_num + 1;
1492 } 1491 }
1493 1492
1494 friend->num_to_bootstrap = get_close_nodes(dht, friend->public_key, friend->to_bootstrap, 0, 1, 0); 1493 dht_friend->num_to_bootstrap = get_close_nodes(dht, dht_friend->public_key, dht_friend->to_bootstrap, 0, 1, 0);
1495 1494
1496 return 0; 1495 return 0;
1497} 1496}
@@ -1504,19 +1503,17 @@ int DHT_delfriend(DHT *dht, const uint8_t *public_key, uint16_t lock_count)
1504 return -1; 1503 return -1;
1505 } 1504 }
1506 1505
1507 DHT_Friend *friend = &dht->friends_list[friend_num]; 1506 DHT_Friend *dht_friend = &dht->friends_list[friend_num];
1508 --friend->lock_count; 1507 --dht_friend->lock_count;
1509 1508
1510 if (friend->lock_count && lock_count) { /* DHT friend is still in use.*/ 1509 if (dht_friend->lock_count && lock_count) { /* DHT friend is still in use.*/
1511 --lock_count; 1510 --lock_count;
1512 friend->callbacks[lock_count].ip_callback = NULL; 1511 dht_friend->callbacks[lock_count].ip_callback = NULL;
1513 friend->callbacks[lock_count].data = NULL; 1512 dht_friend->callbacks[lock_count].data = NULL;
1514 friend->callbacks[lock_count].number = 0; 1513 dht_friend->callbacks[lock_count].number = 0;
1515 return 0; 1514 return 0;
1516 } 1515 }
1517 1516
1518 DHT_Friend *temp;
1519
1520 --dht->num_friends; 1517 --dht->num_friends;
1521 1518
1522 if (dht->num_friends != friend_num) { 1519 if (dht->num_friends != friend_num) {
@@ -1531,7 +1528,7 @@ int DHT_delfriend(DHT *dht, const uint8_t *public_key, uint16_t lock_count)
1531 return 0; 1528 return 0;
1532 } 1529 }
1533 1530
1534 temp = realloc(dht->friends_list, sizeof(DHT_Friend) * (dht->num_friends)); 1531 DHT_Friend *temp = (DHT_Friend *)realloc(dht->friends_list, sizeof(DHT_Friend) * (dht->num_friends));
1535 1532
1536 if (temp == NULL) { 1533 if (temp == NULL) {
1537 return -1; 1534 return -1;
@@ -1650,16 +1647,18 @@ static void do_DHT_friends(DHT *dht)
1650 unsigned int i, j; 1647 unsigned int i, j;
1651 1648
1652 for (i = 0; i < dht->num_friends; ++i) { 1649 for (i = 0; i < dht->num_friends; ++i) {
1653 DHT_Friend *friend = &dht->friends_list[i]; 1650 DHT_Friend *dht_friend = &dht->friends_list[i];
1654 1651
1655 for (j = 0; j < friend->num_to_bootstrap; ++j) { 1652 for (j = 0; j < dht_friend->num_to_bootstrap; ++j) {
1656 getnodes(dht, friend->to_bootstrap[j].ip_port, friend->to_bootstrap[j].public_key, friend->public_key, NULL); 1653 getnodes(dht, dht_friend->to_bootstrap[j].ip_port, dht_friend->to_bootstrap[j].public_key, dht_friend->public_key,
1654 NULL);
1657 } 1655 }
1658 1656
1659 friend->num_to_bootstrap = 0; 1657 dht_friend->num_to_bootstrap = 0;
1660 1658
1661 do_ping_and_sendnode_requests(dht, &friend->lastgetnode, friend->public_key, friend->client_list, MAX_FRIEND_CLIENTS, 1659 do_ping_and_sendnode_requests(dht, &dht_friend->lastgetnode, dht_friend->public_key, dht_friend->client_list,
1662 &friend->bootstrap_times, 1); 1660 MAX_FRIEND_CLIENTS,
1661 &dht_friend->bootstrap_times, 1);
1663 } 1662 }
1664} 1663}
1665 1664
@@ -1791,7 +1790,7 @@ static int friend_iplist(const DHT *dht, IP_Port *ip_portlist, uint16_t friend_n
1791 return -1; 1790 return -1;
1792 } 1791 }
1793 1792
1794 DHT_Friend *friend = &dht->friends_list[friend_num]; 1793 DHT_Friend *dht_friend = &dht->friends_list[friend_num];
1795 Client_data *client; 1794 Client_data *client;
1796 IP_Port ipv4s[MAX_FRIEND_CLIENTS]; 1795 IP_Port ipv4s[MAX_FRIEND_CLIENTS];
1797 int num_ipv4s = 0; 1796 int num_ipv4s = 0;
@@ -1800,7 +1799,7 @@ static int friend_iplist(const DHT *dht, IP_Port *ip_portlist, uint16_t friend_n
1800 int i; 1799 int i;
1801 1800
1802 for (i = 0; i < MAX_FRIEND_CLIENTS; ++i) { 1801 for (i = 0; i < MAX_FRIEND_CLIENTS; ++i) {
1803 client = &(friend->client_list[i]); 1802 client = &(dht_friend->client_list[i]);
1804 1803
1805 /* If ip is not zero and node is good. */ 1804 /* If ip is not zero and node is good. */
1806 if (ip_isset(&client->assoc4.ret_ip_port.ip) && !is_timeout(client->assoc4.ret_timestamp, BAD_NODE_TIMEOUT)) { 1805 if (ip_isset(&client->assoc4.ret_ip_port.ip) && !is_timeout(client->assoc4.ret_timestamp, BAD_NODE_TIMEOUT)) {
@@ -1813,7 +1812,7 @@ static int friend_iplist(const DHT *dht, IP_Port *ip_portlist, uint16_t friend_n
1813 ++num_ipv6s; 1812 ++num_ipv6s;
1814 } 1813 }
1815 1814
1816 if (id_equal(client->public_key, friend->public_key)) { 1815 if (id_equal(client->public_key, dht_friend->public_key)) {
1817 if (!is_timeout(client->assoc6.timestamp, BAD_NODE_TIMEOUT) 1816 if (!is_timeout(client->assoc6.timestamp, BAD_NODE_TIMEOUT)
1818 || !is_timeout(client->assoc4.timestamp, BAD_NODE_TIMEOUT)) { 1817 || !is_timeout(client->assoc4.timestamp, BAD_NODE_TIMEOUT)) {
1819 return 0; /* direct connectivity */ 1818 return 0; /* direct connectivity */
@@ -1877,7 +1876,7 @@ int route_tofriend(const DHT *dht, const uint8_t *friend_id, const uint8_t *pack
1877 return 0; /* Reason for that? */ 1876 return 0; /* Reason for that? */
1878 } 1877 }
1879 1878
1880 DHT_Friend *friend = &dht->friends_list[num]; 1879 DHT_Friend *dht_friend = &dht->friends_list[num];
1881 Client_data *client; 1880 Client_data *client;
1882 1881
1883 /* extra legwork, because having the outside allocating the space for us 1882 /* extra legwork, because having the outside allocating the space for us
@@ -1890,7 +1889,7 @@ int route_tofriend(const DHT *dht, const uint8_t *friend_id, const uint8_t *pack
1890 continue; 1889 continue;
1891 } 1890 }
1892 1891
1893 client = &friend->client_list[i]; 1892 client = &dht_friend->client_list[i];
1894 IPPTsPng *assoc = NULL; 1893 IPPTsPng *assoc = NULL;
1895 1894
1896 if (!a) { 1895 if (!a) {
@@ -1927,7 +1926,7 @@ static int routeone_tofriend(DHT *dht, const uint8_t *friend_id, const uint8_t *
1927 return 0; 1926 return 0;
1928 } 1927 }
1929 1928
1930 DHT_Friend *friend = &dht->friends_list[num]; 1929 DHT_Friend *dht_friend = &dht->friends_list[num];
1931 Client_data *client; 1930 Client_data *client;
1932 1931
1933 IP_Port ip_list[MAX_FRIEND_CLIENTS * 2]; 1932 IP_Port ip_list[MAX_FRIEND_CLIENTS * 2];
@@ -1940,7 +1939,7 @@ static int routeone_tofriend(DHT *dht, const uint8_t *friend_id, const uint8_t *
1940 1939
1941 for (a = 0; a < 2; a++) { 1940 for (a = 0; a < 2; a++) {
1942 for (i = 0; i < MAX_FRIEND_CLIENTS; ++i) { 1941 for (i = 0; i < MAX_FRIEND_CLIENTS; ++i) {
1943 client = &friend->client_list[i]; 1942 client = &dht_friend->client_list[i];
1944 IPPTsPng *assoc = NULL; 1943 IPPTsPng *assoc = NULL;
1945 1944
1946 if (!a) { 1945 if (!a) {
@@ -2011,7 +2010,7 @@ static int handle_NATping(void *object, IP_Port source, const uint8_t *source_pu
2011 return 1; 2010 return 1;
2012 } 2011 }
2013 2012
2014 DHT *dht = object; 2013 DHT *dht = (DHT *)object;
2015 uint64_t ping_id; 2014 uint64_t ping_id;
2016 memcpy(&ping_id, packet + 1, sizeof(uint64_t)); 2015 memcpy(&ping_id, packet + 1, sizeof(uint64_t));
2017 2016
@@ -2021,19 +2020,19 @@ static int handle_NATping(void *object, IP_Port source, const uint8_t *source_pu
2021 return 1; 2020 return 1;
2022 } 2021 }
2023 2022
2024 DHT_Friend *friend = &dht->friends_list[friendnumber]; 2023 DHT_Friend *dht_friend = &dht->friends_list[friendnumber];
2025 2024
2026 if (packet[0] == NAT_PING_REQUEST) { 2025 if (packet[0] == NAT_PING_REQUEST) {
2027 /* 1 is reply */ 2026 /* 1 is reply */
2028 send_NATping(dht, source_pubkey, ping_id, NAT_PING_RESPONSE); 2027 send_NATping(dht, source_pubkey, ping_id, NAT_PING_RESPONSE);
2029 friend->nat.recvNATping_timestamp = unix_time(); 2028 dht_friend->nat.recvNATping_timestamp = unix_time();
2030 return 0; 2029 return 0;
2031 } 2030 }
2032 2031
2033 if (packet[0] == NAT_PING_RESPONSE) { 2032 if (packet[0] == NAT_PING_RESPONSE) {
2034 if (friend->nat.NATping_id == ping_id) { 2033 if (dht_friend->nat.NATping_id == ping_id) {
2035 friend->nat.NATping_id = random_64b(); 2034 dht_friend->nat.NATping_id = random_64b();
2036 friend->nat.hole_punching = 1; 2035 dht_friend->nat.hole_punching = 1;
2037 return 0; 2036 return 0;
2038 } 2037 }
2039 } 2038 }
@@ -2308,7 +2307,7 @@ static uint32_t have_nodes_closelist(DHT *dht, Node_format *nodes, uint16_t num)
2308static int handle_hardening(void *object, IP_Port source, const uint8_t *source_pubkey, const uint8_t *packet, 2307static int handle_hardening(void *object, IP_Port source, const uint8_t *source_pubkey, const uint8_t *packet,
2309 uint16_t length, void *userdata) 2308 uint16_t length, void *userdata)
2310{ 2309{
2311 DHT *dht = object; 2310 DHT *dht = (DHT *)object;
2312 2311
2313 if (length < 2) { 2312 if (length < 2) {
2314 return 1; 2313 return 1;
@@ -2547,7 +2546,7 @@ void cryptopacket_registerhandler(DHT *dht, uint8_t byte, cryptopacket_handler_c
2547 2546
2548static int cryptopacket_handle(void *object, IP_Port source, const uint8_t *packet, uint16_t length, void *userdata) 2547static int cryptopacket_handle(void *object, IP_Port source, const uint8_t *packet, uint16_t length, void *userdata)
2549{ 2548{
2550 DHT *dht = object; 2549 DHT *dht = (DHT *)object;
2551 2550
2552 if (packet[0] == NET_PACKET_CRYPTO) { 2551 if (packet[0] == NET_PACKET_CRYPTO) {
2553 if (length <= crypto_box_PUBLICKEYBYTES * 2 + crypto_box_NONCEBYTES + 1 + crypto_box_MACBYTES || 2552 if (length <= crypto_box_PUBLICKEYBYTES * 2 + crypto_box_NONCEBYTES + 1 + crypto_box_MACBYTES ||
@@ -2595,7 +2594,7 @@ DHT *new_DHT(Logger *log, Networking_Core *net)
2595 return NULL; 2594 return NULL;
2596 } 2595 }
2597 2596
2598 DHT *dht = calloc(1, sizeof(DHT)); 2597 DHT *dht = (DHT *)calloc(1, sizeof(DHT));
2599 2598
2600 if (dht == NULL) { 2599 if (dht == NULL) {
2601 return NULL; 2600 return NULL;
@@ -2813,7 +2812,7 @@ int DHT_connect_after_load(DHT *dht)
2813 2812
2814static int dht_load_state_callback(void *outer, const uint8_t *data, uint32_t length, uint16_t type) 2813static int dht_load_state_callback(void *outer, const uint8_t *data, uint32_t length, uint16_t type)
2815{ 2814{
2816 DHT *dht = outer; 2815 DHT *dht = (DHT *)outer;
2817 2816
2818 switch (type) { 2817 switch (type) {
2819 case DHT_STATE_TYPE_NODES: 2818 case DHT_STATE_TYPE_NODES:
@@ -2824,7 +2823,7 @@ static int dht_load_state_callback(void *outer, const uint8_t *data, uint32_t le
2824 { 2823 {
2825 free(dht->loaded_nodes_list); 2824 free(dht->loaded_nodes_list);
2826 // Copy to loaded_clients_list 2825 // Copy to loaded_clients_list
2827 dht->loaded_nodes_list = calloc(MAX_SAVED_DHT_NODES, sizeof(Node_format)); 2826 dht->loaded_nodes_list = (Node_format *)calloc(MAX_SAVED_DHT_NODES, sizeof(Node_format));
2828 2827
2829 int num = unpack_nodes(dht->loaded_nodes_list, MAX_SAVED_DHT_NODES, NULL, data, length, 0); 2828 int num = unpack_nodes(dht->loaded_nodes_list, MAX_SAVED_DHT_NODES, NULL, data, length, 0);
2830 2829
diff --git a/toxcore/LAN_discovery.c b/toxcore/LAN_discovery.c
index 1c28756b..d2bfb4e1 100644
--- a/toxcore/LAN_discovery.c
+++ b/toxcore/LAN_discovery.c
@@ -323,7 +323,7 @@ int LAN_ip(IP ip)
323 323
324static int handle_LANdiscovery(void *object, IP_Port source, const uint8_t *packet, uint16_t length, void *userdata) 324static int handle_LANdiscovery(void *object, IP_Port source, const uint8_t *packet, uint16_t length, void *userdata)
325{ 325{
326 DHT *dht = object; 326 DHT *dht = (DHT *)object;
327 327
328 if (LAN_ip(source.ip) == -1) { 328 if (LAN_ip(source.ip) == -1) {
329 return 1; 329 return 1;
diff --git a/toxcore/Messenger.c b/toxcore/Messenger.c
index 8969f83d..2355eb89 100644
--- a/toxcore/Messenger.c
+++ b/toxcore/Messenger.c
@@ -65,7 +65,7 @@ static int realloc_friendlist(Messenger *m, uint32_t num)
65 return 0; 65 return 0;
66 } 66 }
67 67
68 Friend *newfriendlist = realloc(m->friendlist, num * sizeof(Friend)); 68 Friend *newfriendlist = (Friend *)realloc(m->friendlist, num * sizeof(Friend));
69 69
70 if (newfriendlist == NULL) { 70 if (newfriendlist == NULL) {
71 return -1; 71 return -1;
@@ -337,23 +337,23 @@ static int add_receipt(Messenger *m, int32_t friendnumber, uint32_t packet_num,
337 return -1; 337 return -1;
338 } 338 }
339 339
340 struct Receipts *new = calloc(1, sizeof(struct Receipts)); 340 struct Receipts *new_receipts = (struct Receipts *)calloc(1, sizeof(struct Receipts));
341 341
342 if (!new) { 342 if (!new_receipts) {
343 return -1; 343 return -1;
344 } 344 }
345 345
346 new->packet_num = packet_num; 346 new_receipts->packet_num = packet_num;
347 new->msg_id = msg_id; 347 new_receipts->msg_id = msg_id;
348 348
349 if (!m->friendlist[friendnumber].receipts_start) { 349 if (!m->friendlist[friendnumber].receipts_start) {
350 m->friendlist[friendnumber].receipts_start = new; 350 m->friendlist[friendnumber].receipts_start = new_receipts;
351 } else { 351 } else {
352 m->friendlist[friendnumber].receipts_end->next = new; 352 m->friendlist[friendnumber].receipts_end->next = new_receipts;
353 } 353 }
354 354
355 m->friendlist[friendnumber].receipts_end = new; 355 m->friendlist[friendnumber].receipts_end = new_receipts;
356 new->next = NULL; 356 new_receipts->next = NULL;
357 return 0; 357 return 0;
358} 358}
359/* 359/*
@@ -676,7 +676,7 @@ int m_set_userstatus(Messenger *m, uint8_t status)
676 return 0; 676 return 0;
677 } 677 }
678 678
679 m->userstatus = status; 679 m->userstatus = (USERSTATUS)status;
680 uint32_t i; 680 uint32_t i;
681 681
682 for (i = 0; i < m->numfriends; ++i) { 682 for (i = 0; i < m->numfriends; ++i) {
@@ -823,7 +823,7 @@ static int set_friend_statusmessage(const Messenger *m, int32_t friendnumber, co
823 823
824static void set_friend_userstatus(const Messenger *m, int32_t friendnumber, uint8_t status) 824static void set_friend_userstatus(const Messenger *m, int32_t friendnumber, uint8_t status)
825{ 825{
826 m->friendlist[friendnumber].userstatus = status; 826 m->friendlist[friendnumber].userstatus = (USERSTATUS)status;
827} 827}
828 828
829static void set_friend_typing(const Messenger *m, int32_t friendnumber, uint8_t is_typing) 829static void set_friend_typing(const Messenger *m, int32_t friendnumber, uint8_t is_typing)
@@ -1731,7 +1731,7 @@ int m_msi_packet(const Messenger *m, int32_t friendnumber, const uint8_t *data,
1731static int handle_custom_lossy_packet(void *object, int friend_num, const uint8_t *packet, uint16_t length, 1731static int handle_custom_lossy_packet(void *object, int friend_num, const uint8_t *packet, uint16_t length,
1732 void *userdata) 1732 void *userdata)
1733{ 1733{
1734 Messenger *m = object; 1734 Messenger *m = (Messenger *)object;
1735 1735
1736 if (friend_not_valid(m, friend_num)) { 1736 if (friend_not_valid(m, friend_num)) {
1737 return 1; 1737 return 1;
@@ -1815,7 +1815,7 @@ int send_custom_lossy_packet(const Messenger *m, int32_t friendnumber, const uin
1815static int handle_custom_lossless_packet(void *object, int friend_num, const uint8_t *packet, uint16_t length, 1815static int handle_custom_lossless_packet(void *object, int friend_num, const uint8_t *packet, uint16_t length,
1816 void *userdata) 1816 void *userdata)
1817{ 1817{
1818 Messenger *m = object; 1818 Messenger *m = (Messenger *)object;
1819 1819
1820 if (friend_not_valid(m, friend_num)) { 1820 if (friend_not_valid(m, friend_num)) {
1821 return -1; 1821 return -1;
@@ -1875,7 +1875,7 @@ int send_custom_lossless_packet(const Messenger *m, int32_t friendnumber, const
1875/* Function to filter out some friend requests*/ 1875/* Function to filter out some friend requests*/
1876static int friend_already_added(const uint8_t *real_pk, void *data) 1876static int friend_already_added(const uint8_t *real_pk, void *data)
1877{ 1877{
1878 const Messenger *m = data; 1878 const Messenger *m = (const Messenger *)data;
1879 1879
1880 if (getfriend_id(m, real_pk) == -1) { 1880 if (getfriend_id(m, real_pk) == -1) {
1881 return 0; 1881 return 0;
@@ -1887,7 +1887,7 @@ static int friend_already_added(const uint8_t *real_pk, void *data)
1887/* Run this at startup. */ 1887/* Run this at startup. */
1888Messenger *new_messenger(Logger *log, Messenger_Options *options, unsigned int *error) 1888Messenger *new_messenger(Logger *log, Messenger_Options *options, unsigned int *error)
1889{ 1889{
1890 Messenger *m = calloc(1, sizeof(Messenger)); 1890 Messenger *m = (Messenger *)calloc(1, sizeof(Messenger));
1891 1891
1892 if (error) { 1892 if (error) {
1893 *error = MESSENGER_ERROR_OTHER; 1893 *error = MESSENGER_ERROR_OTHER;
@@ -1903,7 +1903,7 @@ Messenger *new_messenger(Logger *log, Messenger_Options *options, unsigned int *
1903 1903
1904 if (options->udp_disabled) { 1904 if (options->udp_disabled) {
1905 /* this is the easiest way to completely disable UDP without changing too much code. */ 1905 /* this is the easiest way to completely disable UDP without changing too much code. */
1906 m->net = calloc(1, sizeof(Networking_Core)); 1906 m->net = (Networking_Core *)calloc(1, sizeof(Networking_Core));
1907 } else { 1907 } else {
1908 IP ip; 1908 IP ip;
1909 ip_init(&ip, options->ipv6enabled); 1909 ip_init(&ip, options->ipv6enabled);
@@ -2036,7 +2036,7 @@ static void check_friend_request_timed_out(Messenger *m, uint32_t i, uint64_t t,
2036 2036
2037static int handle_status(void *object, int i, uint8_t status, void *userdata) 2037static int handle_status(void *object, int i, uint8_t status, void *userdata)
2038{ 2038{
2039 Messenger *m = object; 2039 Messenger *m = (Messenger *)object;
2040 2040
2041 if (status) { /* Went online. */ 2041 if (status) { /* Went online. */
2042 send_online_packet(m, i); 2042 send_online_packet(m, i);
@@ -2055,7 +2055,7 @@ static int handle_packet(void *object, int i, const uint8_t *temp, uint16_t len,
2055 return -1; 2055 return -1;
2056 } 2056 }
2057 2057
2058 Messenger *m = object; 2058 Messenger *m = (Messenger *)object;
2059 uint8_t packet_id = temp[0]; 2059 uint8_t packet_id = temp[0];
2060 const uint8_t *data = temp + 1; 2060 const uint8_t *data = temp + 1;
2061 uint32_t data_length = len - 1; 2061 uint32_t data_length = len - 1;
@@ -2123,7 +2123,7 @@ static int handle_packet(void *object, int i, const uint8_t *temp, uint16_t len,
2123 break; 2123 break;
2124 } 2124 }
2125 2125
2126 USERSTATUS status = data[0]; 2126 USERSTATUS status = (USERSTATUS)data[0];
2127 2127
2128 if (status >= USERSTATUS_INVALID) { 2128 if (status >= USERSTATUS_INVALID) {
2129 break; 2129 break;
@@ -2529,32 +2529,32 @@ void do_messenger(Messenger *m, void *userdata)
2529 } 2529 }
2530 2530
2531 2531
2532 uint32_t friend, dhtfriend; 2532 uint32_t friend_idx, dhtfriend;
2533 2533
2534 /* dht contains additional "friends" (requests) */ 2534 /* dht contains additional "friends" (requests) */
2535 uint32_t num_dhtfriends = m->dht->num_friends; 2535 uint32_t num_dhtfriends = m->dht->num_friends;
2536 int32_t m2dht[num_dhtfriends]; 2536 int32_t m2dht[num_dhtfriends];
2537 int32_t dht2m[num_dhtfriends]; 2537 int32_t dht2m[num_dhtfriends];
2538 2538
2539 for (friend = 0; friend < num_dhtfriends; friend++) { 2539 for (friend_idx = 0; friend_idx < num_dhtfriends; friend_idx++) {
2540 m2dht[friend] = -1; 2540 m2dht[friend_idx] = -1;
2541 dht2m[friend] = -1; 2541 dht2m[friend_idx] = -1;
2542 2542
2543 if (friend >= m->numfriends) { 2543 if (friend_idx >= m->numfriends) {
2544 continue; 2544 continue;
2545 } 2545 }
2546 2546
2547 for (dhtfriend = 0; dhtfriend < m->dht->num_friends; dhtfriend++) { 2547 for (dhtfriend = 0; dhtfriend < m->dht->num_friends; dhtfriend++) {
2548 if (id_equal(m->friendlist[friend].real_pk, m->dht->friends_list[dhtfriend].public_key)) { 2548 if (id_equal(m->friendlist[friend_idx].real_pk, m->dht->friends_list[dhtfriend].public_key)) {
2549 m2dht[friend] = dhtfriend; 2549 m2dht[friend_idx] = dhtfriend;
2550 break; 2550 break;
2551 } 2551 }
2552 } 2552 }
2553 } 2553 }
2554 2554
2555 for (friend = 0; friend < num_dhtfriends; friend++) { 2555 for (friend_idx = 0; friend_idx < num_dhtfriends; friend_idx++) {
2556 if (m2dht[friend] >= 0) { 2556 if (m2dht[friend_idx] >= 0) {
2557 dht2m[m2dht[friend]] = friend; 2557 dht2m[m2dht[friend_idx]] = friend_idx;
2558 } 2558 }
2559 } 2559 }
2560 2560
@@ -2565,21 +2565,21 @@ void do_messenger(Messenger *m, void *userdata)
2565 Friend *msgfptr; 2565 Friend *msgfptr;
2566 DHT_Friend *dhtfptr; 2566 DHT_Friend *dhtfptr;
2567 2567
2568 for (friend = 0; friend < num_dhtfriends; friend++) { 2568 for (friend_idx = 0; friend_idx < num_dhtfriends; friend_idx++) {
2569 if (dht2m[friend] >= 0) { 2569 if (dht2m[friend_idx] >= 0) {
2570 msgfptr = &m->friendlist[dht2m[friend]]; 2570 msgfptr = &m->friendlist[dht2m[friend_idx]];
2571 } else { 2571 } else {
2572 msgfptr = NULL; 2572 msgfptr = NULL;
2573 } 2573 }
2574 2574
2575 dhtfptr = &m->dht->friends_list[friend]; 2575 dhtfptr = &m->dht->friends_list[friend_idx];
2576 2576
2577 if (msgfptr) { 2577 if (msgfptr) {
2578 LOGGER_TRACE(m->log, "F[%2u:%2u] <%s> %s", 2578 LOGGER_TRACE(m->log, "F[%2u:%2u] <%s> %s",
2579 dht2m[friend], friend, msgfptr->name, 2579 dht2m[friend_idx], friend_idx, msgfptr->name,
2580 ID2String(msgfptr->real_pk)); 2580 ID2String(msgfptr->real_pk));
2581 } else { 2581 } else {
2582 LOGGER_TRACE(m->log, "F[--:%2u] %s", friend, ID2String(dhtfptr->public_key)); 2582 LOGGER_TRACE(m->log, "F[--:%2u] %s", friend_idx, ID2String(dhtfptr->public_key));
2583 } 2583 }
2584 2584
2585 for (client = 0; client < MAX_FRIEND_CLIENTS; client++) { 2585 for (client = 0; client < MAX_FRIEND_CLIENTS; client++) {
@@ -2596,7 +2596,7 @@ void do_messenger(Messenger *m, void *userdata)
2596 } 2596 }
2597 2597
2598 LOGGER_TRACE(m->log, "F[%2u] => C[%2u] %s:%u [%3u] %s", 2598 LOGGER_TRACE(m->log, "F[%2u] => C[%2u] %s:%u [%3u] %s",
2599 friend, client, ip_ntoa(&assoc->ip_port.ip), 2599 friend_idx, client, ip_ntoa(&assoc->ip_port.ip),
2600 ntohs(assoc->ip_port.port), last_pinged, 2600 ntohs(assoc->ip_port.port), last_pinged,
2601 ID2String(cptr->public_key)); 2601 ID2String(cptr->public_key));
2602 } 2602 }
@@ -2836,7 +2836,7 @@ void messenger_save(const Messenger *m, uint8_t *data)
2836 2836
2837static int messenger_load_state_callback(void *outer, const uint8_t *data, uint32_t length, uint16_t type) 2837static int messenger_load_state_callback(void *outer, const uint8_t *data, uint32_t length, uint16_t type)
2838{ 2838{
2839 Messenger *m = outer; 2839 Messenger *m = (Messenger *)outer;
2840 2840
2841 switch (type) { 2841 switch (type) {
2842 case MESSENGER_STATE_TYPE_NOSPAMKEYS: 2842 case MESSENGER_STATE_TYPE_NOSPAMKEYS:
diff --git a/toxcore/TCP_client.c b/toxcore/TCP_client.c
index 396bb9e3..ba8aeabe 100644
--- a/toxcore/TCP_client.c
+++ b/toxcore/TCP_client.c
@@ -332,25 +332,25 @@ static int send_pending_data(TCP_Client_Connection *con)
332 */ 332 */
333static bool add_priority(TCP_Client_Connection *con, const uint8_t *packet, uint16_t size, uint16_t sent) 333static bool add_priority(TCP_Client_Connection *con, const uint8_t *packet, uint16_t size, uint16_t sent)
334{ 334{
335 TCP_Priority_List *p = con->priority_queue_end, *new; 335 TCP_Priority_List *p = con->priority_queue_end;
336 new = malloc(sizeof(TCP_Priority_List) + size); 336 TCP_Priority_List *new_list = (TCP_Priority_List *)malloc(sizeof(TCP_Priority_List) + size);
337 337
338 if (!new) { 338 if (!new_list) {
339 return 0; 339 return 0;
340 } 340 }
341 341
342 new->next = NULL; 342 new_list->next = NULL;
343 new->size = size; 343 new_list->size = size;
344 new->sent = sent; 344 new_list->sent = sent;
345 memcpy(new->data, packet, size); 345 memcpy(new_list->data, packet, size);
346 346
347 if (p) { 347 if (p) {
348 p->next = new; 348 p->next = new_list;
349 } else { 349 } else {
350 con->priority_queue_start = new; 350 con->priority_queue_start = new_list;
351 } 351 }
352 352
353 con->priority_queue_end = new; 353 con->priority_queue_end = new_list;
354 return 1; 354 return 1;
355} 355}
356 356
@@ -668,7 +668,7 @@ TCP_Client_Connection *new_TCP_connection(IP_Port ip_port, const uint8_t *public
668 return NULL; 668 return NULL;
669 } 669 }
670 670
671 TCP_Client_Connection *temp = calloc(sizeof(TCP_Client_Connection), 1); 671 TCP_Client_Connection *temp = (TCP_Client_Connection *)calloc(sizeof(TCP_Client_Connection), 1);
672 672
673 if (temp == NULL) { 673 if (temp == NULL) {
674 kill_sock(sock); 674 kill_sock(sock);
diff --git a/toxcore/TCP_connection.c b/toxcore/TCP_connection.c
index e838c281..234a8d79 100644
--- a/toxcore/TCP_connection.c
+++ b/toxcore/TCP_connection.c
@@ -70,7 +70,13 @@ const uint8_t *tcp_connections_public_key(const TCP_Connections *tcp_c)
70 * return -1 if realloc fails. 70 * return -1 if realloc fails.
71 * return 0 if it succeeds. 71 * return 0 if it succeeds.
72 */ 72 */
73#define realloc_tox_array(array, element_size, num, temp_pointer) (num ? (temp_pointer = realloc(array, ((num) * (element_size))), temp_pointer ? (array = temp_pointer, 0) : (-1) ) : (free(array), array = NULL, 0)) 73#define realloc_tox_array(array, element_type, num, temp_pointer) \
74 (num \
75 ? (temp_pointer = (element_type *)realloc( \
76 array, \
77 (num) * sizeof(element_type)), \
78 temp_pointer ? (array = temp_pointer, 0) : -1) \
79 : (free(array), array = NULL, 0))
74 80
75 81
76/* return 1 if the connections_number is not valid. 82/* return 1 if the connections_number is not valid.
@@ -132,7 +138,7 @@ static int create_connection(TCP_Connections *tcp_c)
132 138
133 TCP_Connection_to *temp_pointer; 139 TCP_Connection_to *temp_pointer;
134 140
135 if (realloc_tox_array(tcp_c->connections, sizeof(TCP_Connection_to), tcp_c->connections_length + 1, 141 if (realloc_tox_array(tcp_c->connections, TCP_Connection_to, tcp_c->connections_length + 1,
136 temp_pointer) == 0) { 142 temp_pointer) == 0) {
137 id = tcp_c->connections_length; 143 id = tcp_c->connections_length;
138 ++tcp_c->connections_length; 144 ++tcp_c->connections_length;
@@ -161,7 +167,7 @@ static int create_tcp_connection(TCP_Connections *tcp_c)
161 167
162 TCP_con *temp_pointer; 168 TCP_con *temp_pointer;
163 169
164 if (realloc_tox_array(tcp_c->tcp_connections, sizeof(TCP_con), tcp_c->tcp_connections_length + 1, temp_pointer) == 0) { 170 if (realloc_tox_array(tcp_c->tcp_connections, TCP_con, tcp_c->tcp_connections_length + 1, temp_pointer) == 0) {
165 id = tcp_c->tcp_connections_length; 171 id = tcp_c->tcp_connections_length;
166 ++tcp_c->tcp_connections_length; 172 ++tcp_c->tcp_connections_length;
167 memset(&(tcp_c->tcp_connections[id]), 0, sizeof(TCP_con)); 173 memset(&(tcp_c->tcp_connections[id]), 0, sizeof(TCP_con));
@@ -193,7 +199,7 @@ static int wipe_connection(TCP_Connections *tcp_c, int connections_number)
193 if (tcp_c->connections_length != i) { 199 if (tcp_c->connections_length != i) {
194 tcp_c->connections_length = i; 200 tcp_c->connections_length = i;
195 TCP_Connection_to *temp_pointer; 201 TCP_Connection_to *temp_pointer;
196 realloc_tox_array(tcp_c->connections, sizeof(TCP_Connection_to), tcp_c->connections_length, temp_pointer); 202 realloc_tox_array(tcp_c->connections, TCP_Connection_to, tcp_c->connections_length, temp_pointer);
197 } 203 }
198 204
199 return 0; 205 return 0;
@@ -222,7 +228,7 @@ static int wipe_tcp_connection(TCP_Connections *tcp_c, int tcp_connections_numbe
222 if (tcp_c->tcp_connections_length != i) { 228 if (tcp_c->tcp_connections_length != i) {
223 tcp_c->tcp_connections_length = i; 229 tcp_c->tcp_connections_length = i;
224 TCP_con *temp_pointer; 230 TCP_con *temp_pointer;
225 realloc_tox_array(tcp_c->tcp_connections, sizeof(TCP_con), tcp_c->tcp_connections_length, temp_pointer); 231 realloc_tox_array(tcp_c->tcp_connections, TCP_con, tcp_c->tcp_connections_length, temp_pointer);
226 } 232 }
227 233
228 return 0; 234 return 0;
@@ -896,8 +902,8 @@ static int send_tcp_relay_routing_request(TCP_Connections *tcp_c, int tcp_connec
896 902
897static int tcp_response_callback(void *object, uint8_t connection_id, const uint8_t *public_key) 903static int tcp_response_callback(void *object, uint8_t connection_id, const uint8_t *public_key)
898{ 904{
899 TCP_Client_Connection *TCP_client_con = object; 905 TCP_Client_Connection *TCP_client_con = (TCP_Client_Connection *)object;
900 TCP_Connections *tcp_c = TCP_client_con->custom_object; 906 TCP_Connections *tcp_c = (TCP_Connections *)TCP_client_con->custom_object;
901 907
902 unsigned int tcp_connections_number = TCP_client_con->custom_uint; 908 unsigned int tcp_connections_number = TCP_client_con->custom_uint;
903 TCP_con *tcp_con = get_tcp_connection(tcp_c, tcp_connections_number); 909 TCP_con *tcp_con = get_tcp_connection(tcp_c, tcp_connections_number);
@@ -929,8 +935,8 @@ static int tcp_response_callback(void *object, uint8_t connection_id, const uint
929 935
930static int tcp_status_callback(void *object, uint32_t number, uint8_t connection_id, uint8_t status) 936static int tcp_status_callback(void *object, uint32_t number, uint8_t connection_id, uint8_t status)
931{ 937{
932 TCP_Client_Connection *TCP_client_con = object; 938 TCP_Client_Connection *TCP_client_con = (TCP_Client_Connection *)object;
933 TCP_Connections *tcp_c = TCP_client_con->custom_object; 939 TCP_Connections *tcp_c = (TCP_Connections *)TCP_client_con->custom_object;
934 940
935 unsigned int tcp_connections_number = TCP_client_con->custom_uint; 941 unsigned int tcp_connections_number = TCP_client_con->custom_uint;
936 TCP_con *tcp_con = get_tcp_connection(tcp_c, tcp_connections_number); 942 TCP_con *tcp_con = get_tcp_connection(tcp_c, tcp_connections_number);
@@ -968,13 +974,12 @@ static int tcp_status_callback(void *object, uint32_t number, uint8_t connection
968static int tcp_data_callback(void *object, uint32_t number, uint8_t connection_id, const uint8_t *data, uint16_t length, 974static int tcp_data_callback(void *object, uint32_t number, uint8_t connection_id, const uint8_t *data, uint16_t length,
969 void *userdata) 975 void *userdata)
970{ 976{
971
972 if (length == 0) { 977 if (length == 0) {
973 return -1; 978 return -1;
974 } 979 }
975 980
976 TCP_Client_Connection *TCP_client_con = object; 981 TCP_Client_Connection *TCP_client_con = (TCP_Client_Connection *)object;
977 TCP_Connections *tcp_c = TCP_client_con->custom_object; 982 TCP_Connections *tcp_c = (TCP_Connections *)TCP_client_con->custom_object;
978 983
979 unsigned int tcp_connections_number = TCP_client_con->custom_uint; 984 unsigned int tcp_connections_number = TCP_client_con->custom_uint;
980 TCP_con *tcp_con = get_tcp_connection(tcp_c, tcp_connections_number); 985 TCP_con *tcp_con = get_tcp_connection(tcp_c, tcp_connections_number);
@@ -1003,8 +1008,8 @@ static int tcp_oob_callback(void *object, const uint8_t *public_key, const uint8
1003 return -1; 1008 return -1;
1004 } 1009 }
1005 1010
1006 TCP_Client_Connection *TCP_client_con = object; 1011 TCP_Client_Connection *TCP_client_con = (TCP_Client_Connection *)object;
1007 TCP_Connections *tcp_c = TCP_client_con->custom_object; 1012 TCP_Connections *tcp_c = (TCP_Connections *)TCP_client_con->custom_object;
1008 1013
1009 unsigned int tcp_connections_number = TCP_client_con->custom_uint; 1014 unsigned int tcp_connections_number = TCP_client_con->custom_uint;
1010 TCP_con *tcp_con = get_tcp_connection(tcp_c, tcp_connections_number); 1015 TCP_con *tcp_con = get_tcp_connection(tcp_c, tcp_connections_number);
@@ -1031,7 +1036,7 @@ static int tcp_oob_callback(void *object, const uint8_t *public_key, const uint8
1031 1036
1032static int tcp_onion_callback(void *object, const uint8_t *data, uint16_t length, void *userdata) 1037static int tcp_onion_callback(void *object, const uint8_t *data, uint16_t length, void *userdata)
1033{ 1038{
1034 TCP_Connections *tcp_c = object; 1039 TCP_Connections *tcp_c = (TCP_Connections *)object;
1035 1040
1036 if (tcp_c->tcp_onion_callback) { 1041 if (tcp_c->tcp_onion_callback) {
1037 tcp_c->tcp_onion_callback(tcp_c->tcp_onion_callback_object, data, length, userdata); 1042 tcp_c->tcp_onion_callback(tcp_c->tcp_onion_callback_object, data, length, userdata);
@@ -1365,7 +1370,7 @@ TCP_Connections *new_tcp_connections(const uint8_t *secret_key, TCP_Proxy_Info *
1365 return NULL; 1370 return NULL;
1366 } 1371 }
1367 1372
1368 TCP_Connections *temp = calloc(1, sizeof(TCP_Connections)); 1373 TCP_Connections *temp = (TCP_Connections *)calloc(1, sizeof(TCP_Connections));
1369 1374
1370 if (temp == NULL) { 1375 if (temp == NULL) {
1371 return NULL; 1376 return NULL;
diff --git a/toxcore/TCP_server.c b/toxcore/TCP_server.c
index 7e348fa5..a078da94 100644
--- a/toxcore/TCP_server.c
+++ b/toxcore/TCP_server.c
@@ -113,8 +113,9 @@ static int realloc_connection(TCP_Server *TCP_server, uint32_t num)
113 return 0; 113 return 0;
114 } 114 }
115 115
116 TCP_Secure_Connection *new_connections = realloc(TCP_server->accepted_connection_array, 116 TCP_Secure_Connection *new_connections = (TCP_Secure_Connection *)realloc(
117 num * sizeof(TCP_Secure_Connection)); 117 TCP_server->accepted_connection_array,
118 num * sizeof(TCP_Secure_Connection));
118 119
119 if (new_connections == NULL) { 120 if (new_connections == NULL) {
120 return -1; 121 return -1;
@@ -407,25 +408,25 @@ static int send_pending_data(TCP_Secure_Connection *con)
407 */ 408 */
408static bool add_priority(TCP_Secure_Connection *con, const uint8_t *packet, uint16_t size, uint16_t sent) 409static bool add_priority(TCP_Secure_Connection *con, const uint8_t *packet, uint16_t size, uint16_t sent)
409{ 410{
410 TCP_Priority_List *p = con->priority_queue_end, *new; 411 TCP_Priority_List *p = con->priority_queue_end;
411 new = malloc(sizeof(TCP_Priority_List) + size); 412 TCP_Priority_List *new_list = (TCP_Priority_List *)malloc(sizeof(TCP_Priority_List) + size);
412 413
413 if (!new) { 414 if (!new_list) {
414 return 0; 415 return 0;
415 } 416 }
416 417
417 new->next = NULL; 418 new_list->next = NULL;
418 new->size = size; 419 new_list->size = size;
419 new->sent = sent; 420 new_list->sent = sent;
420 memcpy(new->data, packet, size); 421 memcpy(new_list->data, packet, size);
421 422
422 if (p) { 423 if (p) {
423 p->next = new; 424 p->next = new_list;
424 } else { 425 } else {
425 con->priority_queue_start = new; 426 con->priority_queue_start = new_list;
426 } 427 }
427 428
428 con->priority_queue_end = new; 429 con->priority_queue_end = new_list;
429 return 1; 430 return 1;
430} 431}
431 432
@@ -779,7 +780,7 @@ static int rm_connection_index(TCP_Server *TCP_server, TCP_Secure_Connection *co
779 780
780static int handle_onion_recv_1(void *object, IP_Port dest, const uint8_t *data, uint16_t length) 781static int handle_onion_recv_1(void *object, IP_Port dest, const uint8_t *data, uint16_t length)
781{ 782{
782 TCP_Server *TCP_server = object; 783 TCP_Server *TCP_server = (TCP_Server *)object;
783 uint32_t index = dest.ip.ip6.uint32[0]; 784 uint32_t index = dest.ip.ip6.uint32[0];
784 785
785 if (index >= TCP_server->size_accepted_connections) { 786 if (index >= TCP_server->size_accepted_connections) {
@@ -1034,13 +1035,13 @@ TCP_Server *new_TCP_server(uint8_t ipv6_enabled, uint16_t num_sockets, const uin
1034 return NULL; 1035 return NULL;
1035 } 1036 }
1036 1037
1037 TCP_Server *temp = calloc(1, sizeof(TCP_Server)); 1038 TCP_Server *temp = (TCP_Server *)calloc(1, sizeof(TCP_Server));
1038 1039
1039 if (temp == NULL) { 1040 if (temp == NULL) {
1040 return NULL; 1041 return NULL;
1041 } 1042 }
1042 1043
1043 temp->socks_listening = calloc(num_sockets, sizeof(sock_t)); 1044 temp->socks_listening = (sock_t *)calloc(num_sockets, sizeof(sock_t));
1044 1045
1045 if (temp->socks_listening == NULL) { 1046 if (temp->socks_listening == NULL) {
1046 free(temp); 1047 free(temp);
diff --git a/toxcore/assoc.c b/toxcore/assoc.c
index 3653a8d4..74e4b0e0 100644
--- a/toxcore/assoc.c
+++ b/toxcore/assoc.c
@@ -123,8 +123,8 @@ static uint64_t id_distance(const Assoc *assoc, void *callback_data, const uint8
123/* qsort() callback for a sorting by id_distance() values */ 123/* qsort() callback for a sorting by id_distance() values */
124static int dist_index_comp(const void *a, const void *b) 124static int dist_index_comp(const void *a, const void *b)
125{ 125{
126 const uint64_t *_a = a; 126 const uint64_t *_a = (const uint64_t *)a;
127 const uint64_t *_b = b; 127 const uint64_t *_b = (const uint64_t *)b;
128 128
129 if (*_a < *_b) { 129 if (*_a < *_b) {
130 return -1; 130 return -1;
@@ -847,7 +847,7 @@ Assoc *new_Assoc(Logger *log, size_t bits, size_t entries, const uint8_t *public
847 return NULL; 847 return NULL;
848 } 848 }
849 849
850 Assoc *assoc = calloc(1, sizeof(*assoc)); 850 Assoc *assoc = (Assoc *)calloc(1, sizeof(*assoc));
851 851
852 if (!assoc) { 852 if (!assoc) {
853 return NULL; 853 return NULL;
@@ -900,14 +900,15 @@ Assoc *new_Assoc(Logger *log, size_t bits, size_t entries, const uint8_t *public
900 900
901 /* allocation: preferably few blobs */ 901 /* allocation: preferably few blobs */
902 size_t bckt, cix; 902 size_t bckt, cix;
903 Client_entry *clients = malloc(sizeof(*clients) * assoc->candidates_bucket_count * assoc->candidates_bucket_size); 903 Client_entry *clients = (Client_entry *)malloc(sizeof(*clients) * assoc->candidates_bucket_count *
904 assoc->candidates_bucket_size);
904 905
905 if (!clients) { 906 if (!clients) {
906 free(assoc); 907 free(assoc);
907 return NULL; 908 return NULL;
908 } 909 }
909 910
910 candidates_bucket *lists = malloc(sizeof(*lists) * assoc->candidates_bucket_count); 911 candidates_bucket *lists = (candidates_bucket *)malloc(sizeof(*lists) * assoc->candidates_bucket_count);
911 912
912 if (!lists) { 913 if (!lists) {
913 free(assoc); 914 free(assoc);
diff --git a/toxcore/friend_connection.c b/toxcore/friend_connection.c
index 314f4e61..5abf6381 100644
--- a/toxcore/friend_connection.c
+++ b/toxcore/friend_connection.c
@@ -63,7 +63,7 @@ static int realloc_friendconns(Friend_Connections *fr_c, uint32_t num)
63 return 0; 63 return 0;
64 } 64 }
65 65
66 Friend_Conn *newgroup_cons = realloc(fr_c->conns, num * sizeof(Friend_Conn)); 66 Friend_Conn *newgroup_cons = (Friend_Conn *)realloc(fr_c->conns, num * sizeof(Friend_Conn));
67 67
68 if (newgroup_cons == NULL) { 68 if (newgroup_cons == NULL) {
69 return -1; 69 return -1;
@@ -261,7 +261,7 @@ static unsigned int send_relays(Friend_Connections *fr_c, int friendcon_id)
261/* callback for recv TCP relay nodes. */ 261/* callback for recv TCP relay nodes. */
262static int tcp_relay_node_callback(void *object, uint32_t number, IP_Port ip_port, const uint8_t *public_key) 262static int tcp_relay_node_callback(void *object, uint32_t number, IP_Port ip_port, const uint8_t *public_key)
263{ 263{
264 Friend_Connections *fr_c = object; 264 Friend_Connections *fr_c = (Friend_Connections *)object;
265 Friend_Conn *friend_con = get_conn(fr_c, number); 265 Friend_Conn *friend_con = get_conn(fr_c, number);
266 266
267 if (!friend_con) { 267 if (!friend_con) {
@@ -279,7 +279,7 @@ static int friend_new_connection(Friend_Connections *fr_c, int friendcon_id);
279/* Callback for DHT ip_port changes. */ 279/* Callback for DHT ip_port changes. */
280static void dht_ip_callback(void *object, int32_t number, IP_Port ip_port) 280static void dht_ip_callback(void *object, int32_t number, IP_Port ip_port)
281{ 281{
282 Friend_Connections *fr_c = object; 282 Friend_Connections *fr_c = (Friend_Connections *)object;
283 Friend_Conn *friend_con = get_conn(fr_c, number); 283 Friend_Conn *friend_con = get_conn(fr_c, number);
284 284
285 if (!friend_con) { 285 if (!friend_con) {
@@ -325,7 +325,7 @@ static void change_dht_pk(Friend_Connections *fr_c, int friendcon_id, const uint
325 325
326static int handle_status(void *object, int number, uint8_t status, void *userdata) 326static int handle_status(void *object, int number, uint8_t status, void *userdata)
327{ 327{
328 Friend_Connections *fr_c = object; 328 Friend_Connections *fr_c = (Friend_Connections *)object;
329 Friend_Conn *friend_con = get_conn(fr_c, number); 329 Friend_Conn *friend_con = get_conn(fr_c, number);
330 330
331 if (!friend_con) { 331 if (!friend_con) {
@@ -369,7 +369,7 @@ static int handle_status(void *object, int number, uint8_t status, void *userdat
369/* Callback for dht public key changes. */ 369/* Callback for dht public key changes. */
370static void dht_pk_callback(void *object, int32_t number, const uint8_t *dht_public_key, void *userdata) 370static void dht_pk_callback(void *object, int32_t number, const uint8_t *dht_public_key, void *userdata)
371{ 371{
372 Friend_Connections *fr_c = object; 372 Friend_Connections *fr_c = (Friend_Connections *)object;
373 Friend_Conn *friend_con = get_conn(fr_c, number); 373 Friend_Conn *friend_con = get_conn(fr_c, number);
374 374
375 if (!friend_con) { 375 if (!friend_con) {
@@ -399,7 +399,7 @@ static int handle_packet(void *object, int number, const uint8_t *data, uint16_t
399 return -1; 399 return -1;
400 } 400 }
401 401
402 Friend_Connections *fr_c = object; 402 Friend_Connections *fr_c = (Friend_Connections *)object;
403 Friend_Conn *friend_con = get_conn(fr_c, number); 403 Friend_Conn *friend_con = get_conn(fr_c, number);
404 404
405 if (!friend_con) { 405 if (!friend_con) {
@@ -461,7 +461,7 @@ static int handle_lossy_packet(void *object, int number, const uint8_t *data, ui
461 return -1; 461 return -1;
462 } 462 }
463 463
464 Friend_Connections *fr_c = object; 464 Friend_Connections *fr_c = (Friend_Connections *)object;
465 Friend_Conn *friend_con = get_conn(fr_c, number); 465 Friend_Conn *friend_con = get_conn(fr_c, number);
466 466
467 if (!friend_con) { 467 if (!friend_con) {
@@ -488,7 +488,7 @@ static int handle_lossy_packet(void *object, int number, const uint8_t *data, ui
488 488
489static int handle_new_connections(void *object, New_Connection *n_c) 489static int handle_new_connections(void *object, New_Connection *n_c)
490{ 490{
491 Friend_Connections *fr_c = object; 491 Friend_Connections *fr_c = (Friend_Connections *)object;
492 int friendcon_id = getfriend_conn_id_pk(fr_c, n_c->public_key); 492 int friendcon_id = getfriend_conn_id_pk(fr_c, n_c->public_key);
493 Friend_Conn *friend_con = get_conn(fr_c, friendcon_id); 493 Friend_Conn *friend_con = get_conn(fr_c, friendcon_id);
494 494
@@ -819,7 +819,7 @@ Friend_Connections *new_friend_connections(Onion_Client *onion_c)
819 return NULL; 819 return NULL;
820 } 820 }
821 821
822 Friend_Connections *temp = calloc(1, sizeof(Friend_Connections)); 822 Friend_Connections *temp = (Friend_Connections *)calloc(1, sizeof(Friend_Connections));
823 823
824 if (temp == NULL) { 824 if (temp == NULL) {
825 return NULL; 825 return NULL;
diff --git a/toxcore/friend_requests.c b/toxcore/friend_requests.c
index a011c72e..f0281d3a 100644
--- a/toxcore/friend_requests.c
+++ b/toxcore/friend_requests.c
@@ -108,7 +108,7 @@ int remove_request_received(Friend_Requests *fr, const uint8_t *real_pk)
108static int friendreq_handlepacket(void *object, const uint8_t *source_pubkey, const uint8_t *packet, uint16_t length, 108static int friendreq_handlepacket(void *object, const uint8_t *source_pubkey, const uint8_t *packet, uint16_t length,
109 void *userdata) 109 void *userdata)
110{ 110{
111 Friend_Requests *fr = object; 111 Friend_Requests *fr = (Friend_Requests *)object;
112 112
113 if (length <= 1 + sizeof(fr->nospam) || length > ONION_CLIENT_MAX_DATA_SIZE) { 113 if (length <= 1 + sizeof(fr->nospam) || length > ONION_CLIENT_MAX_DATA_SIZE) {
114 return 1; 114 return 1;
diff --git a/toxcore/group.c b/toxcore/group.c
index e4560687..d56301cf 100644
--- a/toxcore/group.c
+++ b/toxcore/group.c
@@ -63,7 +63,7 @@ static int realloc_groupchats(Group_Chats *g_c, uint32_t num)
63 return 0; 63 return 0;
64 } 64 }
65 65
66 Group_c *newgroup_chats = realloc(g_c->chats, num * sizeof(Group_c)); 66 Group_c *newgroup_chats = (Group_c *)realloc(g_c->chats, num * sizeof(Group_c));
67 67
68 if (newgroup_chats == NULL) { 68 if (newgroup_chats == NULL) {
69 return -1; 69 return -1;
@@ -436,8 +436,7 @@ static int addpeer(Group_Chats *g_c, int groupnumber, const uint8_t *real_pk, co
436 return -1; 436 return -1;
437 } 437 }
438 438
439 Group_Peer *temp; 439 Group_Peer *temp = (Group_Peer *)realloc(g->group, sizeof(Group_Peer) * (g->numpeers + 1));
440 temp = realloc(g->group, sizeof(Group_Peer) * (g->numpeers + 1));
441 440
442 if (temp == NULL) { 441 if (temp == NULL) {
443 return -1; 442 return -1;
@@ -522,7 +521,6 @@ static int delpeer(Group_Chats *g_c, int groupnumber, int peer_index, void *user
522 remove_close_conn(g_c, groupnumber, friendcon_id); 521 remove_close_conn(g_c, groupnumber, friendcon_id);
523 } 522 }
524 523
525 Group_Peer *temp;
526 --g->numpeers; 524 --g->numpeers;
527 525
528 void *peer_object = g->group[peer_index].object; 526 void *peer_object = g->group[peer_index].object;
@@ -535,7 +533,7 @@ static int delpeer(Group_Chats *g_c, int groupnumber, int peer_index, void *user
535 memcpy(&g->group[peer_index], &g->group[g->numpeers], sizeof(Group_Peer)); 533 memcpy(&g->group[peer_index], &g->group[g->numpeers], sizeof(Group_Peer));
536 } 534 }
537 535
538 temp = realloc(g->group, sizeof(Group_Peer) * (g->numpeers)); 536 Group_Peer *temp = (Group_Peer *)realloc(g->group, sizeof(Group_Peer) * (g->numpeers));
539 537
540 if (temp == NULL) { 538 if (temp == NULL) {
541 return -1; 539 return -1;
@@ -663,7 +661,7 @@ static void set_conns_status_groups(Group_Chats *g_c, int friendcon_id, uint8_t
663 661
664static int handle_status(void *object, int friendcon_id, uint8_t status, void *userdata) 662static int handle_status(void *object, int friendcon_id, uint8_t status, void *userdata)
665{ 663{
666 Group_Chats *g_c = object; 664 Group_Chats *g_c = (Group_Chats *)object;
667 665
668 if (status) { /* Went online */ 666 if (status) { /* Went online */
669 set_conns_status_groups(g_c, friendcon_id, GROUPCHAT_CLOSE_ONLINE); 667 set_conns_status_groups(g_c, friendcon_id, GROUPCHAT_CLOSE_ONLINE);
@@ -1379,7 +1377,7 @@ int group_title_get(const Group_Chats *g_c, int groupnumber, uint8_t *title)
1379static void handle_friend_invite_packet(Messenger *m, uint32_t friendnumber, const uint8_t *data, uint16_t length, 1377static void handle_friend_invite_packet(Messenger *m, uint32_t friendnumber, const uint8_t *data, uint16_t length,
1380 void *userdata) 1378 void *userdata)
1381{ 1379{
1382 Group_Chats *g_c = m->group_chat_object; 1380 Group_Chats *g_c = (Group_Chats *)m->group_chat_object;
1383 1381
1384 if (length <= 1) { 1382 if (length <= 1) {
1385 return; 1383 return;
@@ -2128,7 +2126,7 @@ static void handle_message_packet_group(Group_Chats *g_c, int groupnumber, const
2128 2126
2129static int handle_packet(void *object, int friendcon_id, const uint8_t *data, uint16_t length, void *userdata) 2127static int handle_packet(void *object, int friendcon_id, const uint8_t *data, uint16_t length, void *userdata)
2130{ 2128{
2131 Group_Chats *g_c = object; 2129 Group_Chats *g_c = (Group_Chats *)object;
2132 2130
2133 if (length < 1 + sizeof(uint16_t) + 1) { 2131 if (length < 1 + sizeof(uint16_t) + 1) {
2134 return -1; 2132 return -1;
@@ -2240,7 +2238,7 @@ static unsigned int lossy_packet_not_received(Group_c *g, int peer_index, uint16
2240 2238
2241static int handle_lossy(void *object, int friendcon_id, const uint8_t *data, uint16_t length, void *userdata) 2239static int handle_lossy(void *object, int friendcon_id, const uint8_t *data, uint16_t length, void *userdata)
2242{ 2240{
2243 Group_Chats *g_c = object; 2241 Group_Chats *g_c = (Group_Chats *)object;
2244 2242
2245 if (length < 1 + sizeof(uint16_t) * 3 + 1) { 2243 if (length < 1 + sizeof(uint16_t) * 3 + 1) {
2246 return -1; 2244 return -1;
@@ -2446,7 +2444,7 @@ Group_Chats *new_groupchats(Messenger *m)
2446 return NULL; 2444 return NULL;
2447 } 2445 }
2448 2446
2449 Group_Chats *temp = calloc(1, sizeof(Group_Chats)); 2447 Group_Chats *temp = (Group_Chats *)calloc(1, sizeof(Group_Chats));
2450 2448
2451 if (temp == NULL) { 2449 if (temp == NULL) {
2452 return NULL; 2450 return NULL;
diff --git a/toxcore/list.c b/toxcore/list.c
index 305e563c..015f8f8a 100644
--- a/toxcore/list.c
+++ b/toxcore/list.c
@@ -113,23 +113,21 @@ static int find(const BS_LIST *list, const uint8_t *data)
113 */ 113 */
114static int resize(BS_LIST *list, uint32_t new_size) 114static int resize(BS_LIST *list, uint32_t new_size)
115{ 115{
116 void *p; 116 uint8_t *data = (uint8_t *)realloc(list->data, list->element_size * new_size);
117 117
118 p = realloc(list->data, list->element_size * new_size); 118 if (!data) {
119
120 if (!p) {
121 return 0; 119 return 0;
122 } 120 }
123 121
124 list->data = p; 122 list->data = data;
125 123
126 p = realloc(list->ids, sizeof(int) * new_size); 124 int *ids = (int *)realloc(list->ids, sizeof(int) * new_size);
127 125
128 if (!p) { 126 if (!ids) {
129 return 0; 127 return 0;
130 } 128 }
131 129
132 list->ids = p; 130 list->ids = ids;
133 131
134 return 1; 132 return 1;
135} 133}
diff --git a/toxcore/logger.c b/toxcore/logger.c
index c6f4056b..bbb31aa2 100644
--- a/toxcore/logger.c
+++ b/toxcore/logger.c
@@ -37,7 +37,7 @@ struct Logger {
37 */ 37 */
38Logger *logger_new(void) 38Logger *logger_new(void)
39{ 39{
40 return calloc(1, sizeof(Logger)); 40 return (Logger *)calloc(1, sizeof(Logger));
41} 41}
42 42
43void logger_kill(Logger *log) 43void logger_kill(Logger *log)
diff --git a/toxcore/net_crypto.c b/toxcore/net_crypto.c
index 2da8de61..16b3c6d2 100644
--- a/toxcore/net_crypto.c
+++ b/toxcore/net_crypto.c
@@ -207,7 +207,7 @@ static int handle_cookie_request(const Net_Crypto *c, uint8_t *request_plain, ui
207static int udp_handle_cookie_request(void *object, IP_Port source, const uint8_t *packet, uint16_t length, 207static int udp_handle_cookie_request(void *object, IP_Port source, const uint8_t *packet, uint16_t length,
208 void *userdata) 208 void *userdata)
209{ 209{
210 Net_Crypto *c = object; 210 Net_Crypto *c = (Net_Crypto *)object;
211 uint8_t request_plain[COOKIE_REQUEST_PLAIN_LENGTH]; 211 uint8_t request_plain[COOKIE_REQUEST_PLAIN_LENGTH];
212 uint8_t shared_key[crypto_box_BEFORENMBYTES]; 212 uint8_t shared_key[crypto_box_BEFORENMBYTES];
213 uint8_t dht_public_key[crypto_box_PUBLICKEYBYTES]; 213 uint8_t dht_public_key[crypto_box_PUBLICKEYBYTES];
@@ -592,7 +592,7 @@ static int add_data_to_buffer(Packets_Array *array, uint32_t number, const Packe
592 return -1; 592 return -1;
593 } 593 }
594 594
595 Packet_Data *new_d = malloc(sizeof(Packet_Data)); 595 Packet_Data *new_d = (Packet_Data *)malloc(sizeof(Packet_Data));
596 596
597 if (new_d == NULL) { 597 if (new_d == NULL) {
598 return -1; 598 return -1;
@@ -643,7 +643,7 @@ static int64_t add_data_end_of_buffer(Packets_Array *array, const Packet_Data *d
643 return -1; 643 return -1;
644 } 644 }
645 645
646 Packet_Data *new_d = malloc(sizeof(Packet_Data)); 646 Packet_Data *new_d = (Packet_Data *)malloc(sizeof(Packet_Data));
647 647
648 if (new_d == NULL) { 648 if (new_d == NULL) {
649 return -1; 649 return -1;
@@ -1183,7 +1183,7 @@ static int new_temp_packet(const Net_Crypto *c, int crypt_connection_id, const u
1183 return -1; 1183 return -1;
1184 } 1184 }
1185 1185
1186 uint8_t *temp_packet = malloc(length); 1186 uint8_t *temp_packet = (uint8_t *)malloc(length);
1187 1187
1188 if (temp_packet == 0) { 1188 if (temp_packet == 0) {
1189 return -1; 1189 return -1;
@@ -1569,7 +1569,8 @@ static int realloc_cryptoconnection(Net_Crypto *c, uint32_t num)
1569 return 0; 1569 return 0;
1570 } 1570 }
1571 1571
1572 Crypto_Connection *newcrypto_connections = realloc(c->crypto_connections, num * sizeof(Crypto_Connection)); 1572 Crypto_Connection *newcrypto_connections = (Crypto_Connection *)realloc(c->crypto_connections,
1573 num * sizeof(Crypto_Connection));
1573 1574
1574 if (newcrypto_connections == NULL) { 1575 if (newcrypto_connections == NULL) {
1575 return -1; 1576 return -1;
@@ -1738,7 +1739,7 @@ static int handle_new_connection_handshake(Net_Crypto *c, IP_Port source, const
1738 void *userdata) 1739 void *userdata)
1739{ 1740{
1740 New_Connection n_c; 1741 New_Connection n_c;
1741 n_c.cookie = malloc(COOKIE_LENGTH); 1742 n_c.cookie = (uint8_t *)malloc(COOKIE_LENGTH);
1742 1743
1743 if (n_c.cookie == NULL) { 1744 if (n_c.cookie == NULL) {
1744 return -1; 1745 return -1;
@@ -1947,7 +1948,7 @@ static int tcp_data_callback(void *object, int id, const uint8_t *data, uint16_t
1947 return -1; 1948 return -1;
1948 } 1949 }
1949 1950
1950 Net_Crypto *c = object; 1951 Net_Crypto *c = (Net_Crypto *)object;
1951 1952
1952 Crypto_Connection *conn = get_crypto_connection(c, id); 1953 Crypto_Connection *conn = get_crypto_connection(c, id);
1953 1954
@@ -1978,7 +1979,7 @@ static int tcp_oob_callback(void *object, const uint8_t *public_key, unsigned in
1978 return -1; 1979 return -1;
1979 } 1980 }
1980 1981
1981 Net_Crypto *c = object; 1982 Net_Crypto *c = (Net_Crypto *)object;
1982 1983
1983 if (data[0] == NET_PACKET_COOKIE_REQUEST) { 1984 if (data[0] == NET_PACKET_COOKIE_REQUEST) {
1984 return tcp_oob_handle_cookie_request(c, tcp_connections_number, public_key, data, length); 1985 return tcp_oob_handle_cookie_request(c, tcp_connections_number, public_key, data, length);
@@ -2238,7 +2239,7 @@ static int udp_handle_packet(void *object, IP_Port source, const uint8_t *packet
2238 return 1; 2239 return 1;
2239 } 2240 }
2240 2241
2241 Net_Crypto *c = object; 2242 Net_Crypto *c = (Net_Crypto *)object;
2242 int crypt_connection_id = crypto_id_ip_port(c, source); 2243 int crypt_connection_id = crypto_id_ip_port(c, source);
2243 2244
2244 if (crypt_connection_id == -1) { 2245 if (crypt_connection_id == -1) {
@@ -2787,7 +2788,7 @@ Net_Crypto *new_net_crypto(Logger *log, DHT *dht, TCP_Proxy_Info *proxy_info)
2787 return NULL; 2788 return NULL;
2788 } 2789 }
2789 2790
2790 Net_Crypto *temp = calloc(1, sizeof(Net_Crypto)); 2791 Net_Crypto *temp = (Net_Crypto *)calloc(1, sizeof(Net_Crypto));
2791 2792
2792 if (temp == NULL) { 2793 if (temp == NULL) {
2793 return NULL; 2794 return NULL;
diff --git a/toxcore/network.c b/toxcore/network.c
index e20f4c01..39e1fc98 100644
--- a/toxcore/network.c
+++ b/toxcore/network.c
@@ -557,7 +557,7 @@ Networking_Core *new_networking_ex(Logger *log, IP ip, uint16_t port_from, uint1
557 return NULL; 557 return NULL;
558 } 558 }
559 559
560 Networking_Core *temp = calloc(1, sizeof(Networking_Core)); 560 Networking_Core *temp = (Networking_Core *)calloc(1, sizeof(Networking_Core));
561 561
562 if (temp == NULL) { 562 if (temp == NULL) {
563 return NULL; 563 return NULL;
diff --git a/toxcore/onion.c b/toxcore/onion.c
index 5e5fd135..5705c14f 100644
--- a/toxcore/onion.c
+++ b/toxcore/onion.c
@@ -325,7 +325,7 @@ int send_onion_response(Networking_Core *net, IP_Port dest, const uint8_t *data,
325 325
326static int handle_send_initial(void *object, IP_Port source, const uint8_t *packet, uint16_t length, void *userdata) 326static int handle_send_initial(void *object, IP_Port source, const uint8_t *packet, uint16_t length, void *userdata)
327{ 327{
328 Onion *onion = object; 328 Onion *onion = (Onion *)object;
329 329
330 if (length > ONION_MAX_PACKET_SIZE) { 330 if (length > ONION_MAX_PACKET_SIZE) {
331 return 1; 331 return 1;
@@ -394,7 +394,7 @@ int onion_send_1(const Onion *onion, const uint8_t *plain, uint16_t len, IP_Port
394 394
395static int handle_send_1(void *object, IP_Port source, const uint8_t *packet, uint16_t length, void *userdata) 395static int handle_send_1(void *object, IP_Port source, const uint8_t *packet, uint16_t length, void *userdata)
396{ 396{
397 Onion *onion = object; 397 Onion *onion = (Onion *)object;
398 398
399 if (length > ONION_MAX_PACKET_SIZE) { 399 if (length > ONION_MAX_PACKET_SIZE) {
400 return 1; 400 return 1;
@@ -450,7 +450,7 @@ static int handle_send_1(void *object, IP_Port source, const uint8_t *packet, ui
450 450
451static int handle_send_2(void *object, IP_Port source, const uint8_t *packet, uint16_t length, void *userdata) 451static int handle_send_2(void *object, IP_Port source, const uint8_t *packet, uint16_t length, void *userdata)
452{ 452{
453 Onion *onion = object; 453 Onion *onion = (Onion *)object;
454 454
455 if (length > ONION_MAX_PACKET_SIZE) { 455 if (length > ONION_MAX_PACKET_SIZE) {
456 return 1; 456 return 1;
@@ -505,7 +505,7 @@ static int handle_send_2(void *object, IP_Port source, const uint8_t *packet, ui
505 505
506static int handle_recv_3(void *object, IP_Port source, const uint8_t *packet, uint16_t length, void *userdata) 506static int handle_recv_3(void *object, IP_Port source, const uint8_t *packet, uint16_t length, void *userdata)
507{ 507{
508 Onion *onion = object; 508 Onion *onion = (Onion *)object;
509 509
510 if (length > ONION_MAX_PACKET_SIZE) { 510 if (length > ONION_MAX_PACKET_SIZE) {
511 return 1; 511 return 1;
@@ -546,7 +546,7 @@ static int handle_recv_3(void *object, IP_Port source, const uint8_t *packet, ui
546 546
547static int handle_recv_2(void *object, IP_Port source, const uint8_t *packet, uint16_t length, void *userdata) 547static int handle_recv_2(void *object, IP_Port source, const uint8_t *packet, uint16_t length, void *userdata)
548{ 548{
549 Onion *onion = object; 549 Onion *onion = (Onion *)object;
550 550
551 if (length > ONION_MAX_PACKET_SIZE) { 551 if (length > ONION_MAX_PACKET_SIZE) {
552 return 1; 552 return 1;
@@ -587,7 +587,7 @@ static int handle_recv_2(void *object, IP_Port source, const uint8_t *packet, ui
587 587
588static int handle_recv_1(void *object, IP_Port source, const uint8_t *packet, uint16_t length, void *userdata) 588static int handle_recv_1(void *object, IP_Port source, const uint8_t *packet, uint16_t length, void *userdata)
589{ 589{
590 Onion *onion = object; 590 Onion *onion = (Onion *)object;
591 591
592 if (length > ONION_MAX_PACKET_SIZE) { 592 if (length > ONION_MAX_PACKET_SIZE) {
593 return 1; 593 return 1;
@@ -638,7 +638,7 @@ Onion *new_onion(DHT *dht)
638 return NULL; 638 return NULL;
639 } 639 }
640 640
641 Onion *onion = calloc(1, sizeof(Onion)); 641 Onion *onion = (Onion *)calloc(1, sizeof(Onion));
642 642
643 if (onion == NULL) { 643 if (onion == NULL) {
644 return NULL; 644 return NULL;
diff --git a/toxcore/onion_announce.c b/toxcore/onion_announce.c
index 42b3a635..acde04a7 100644
--- a/toxcore/onion_announce.c
+++ b/toxcore/onion_announce.c
@@ -309,7 +309,7 @@ static int add_to_entries(Onion_Announce *onion_a, IP_Port ret_ip_port, const ui
309 309
310static int handle_announce_request(void *object, IP_Port source, const uint8_t *packet, uint16_t length, void *userdata) 310static int handle_announce_request(void *object, IP_Port source, const uint8_t *packet, uint16_t length, void *userdata)
311{ 311{
312 Onion_Announce *onion_a = object; 312 Onion_Announce *onion_a = (Onion_Announce *)object;
313 313
314 if (length != ANNOUNCE_REQUEST_SIZE_RECV) { 314 if (length != ANNOUNCE_REQUEST_SIZE_RECV) {
315 return 1; 315 return 1;
@@ -408,7 +408,7 @@ static int handle_announce_request(void *object, IP_Port source, const uint8_t *
408 408
409static int handle_data_request(void *object, IP_Port source, const uint8_t *packet, uint16_t length, void *userdata) 409static int handle_data_request(void *object, IP_Port source, const uint8_t *packet, uint16_t length, void *userdata)
410{ 410{
411 Onion_Announce *onion_a = object; 411 Onion_Announce *onion_a = (Onion_Announce *)object;
412 412
413 if (length <= DATA_REQUEST_MIN_SIZE_RECV) { 413 if (length <= DATA_REQUEST_MIN_SIZE_RECV) {
414 return 1; 414 return 1;
@@ -442,7 +442,7 @@ Onion_Announce *new_onion_announce(DHT *dht)
442 return NULL; 442 return NULL;
443 } 443 }
444 444
445 Onion_Announce *onion_a = calloc(1, sizeof(Onion_Announce)); 445 Onion_Announce *onion_a = (Onion_Announce *)calloc(1, sizeof(Onion_Announce));
446 446
447 if (onion_a == NULL) { 447 if (onion_a == NULL) {
448 return NULL; 448 return NULL;
diff --git a/toxcore/onion_client.c b/toxcore/onion_client.c
index 316ed3d1..86f4de72 100644
--- a/toxcore/onion_client.c
+++ b/toxcore/onion_client.c
@@ -662,7 +662,7 @@ static int client_ping_nodes(Onion_Client *onion_c, uint32_t num, const Node_for
662static int handle_announce_response(void *object, IP_Port source, const uint8_t *packet, uint16_t length, 662static int handle_announce_response(void *object, IP_Port source, const uint8_t *packet, uint16_t length,
663 void *userdata) 663 void *userdata)
664{ 664{
665 Onion_Client *onion_c = object; 665 Onion_Client *onion_c = (Onion_Client *)object;
666 666
667 if (length < ONION_ANNOUNCE_RESPONSE_MIN_SIZE || length > ONION_ANNOUNCE_RESPONSE_MAX_SIZE) { 667 if (length < ONION_ANNOUNCE_RESPONSE_MIN_SIZE || length > ONION_ANNOUNCE_RESPONSE_MAX_SIZE) {
668 return 1; 668 return 1;
@@ -727,7 +727,7 @@ static int handle_announce_response(void *object, IP_Port source, const uint8_t
727 727
728static int handle_data_response(void *object, IP_Port source, const uint8_t *packet, uint16_t length, void *userdata) 728static int handle_data_response(void *object, IP_Port source, const uint8_t *packet, uint16_t length, void *userdata)
729{ 729{
730 Onion_Client *onion_c = object; 730 Onion_Client *onion_c = (Onion_Client *)object;
731 731
732 if (length <= (ONION_DATA_RESPONSE_MIN_SIZE + DATA_IN_RESPONSE_MIN_SIZE)) { 732 if (length <= (ONION_DATA_RESPONSE_MIN_SIZE + DATA_IN_RESPONSE_MIN_SIZE)) {
733 return 1; 733 return 1;
@@ -767,7 +767,7 @@ static int handle_data_response(void *object, IP_Port source, const uint8_t *pac
767static int handle_dhtpk_announce(void *object, const uint8_t *source_pubkey, const uint8_t *data, uint16_t length, 767static int handle_dhtpk_announce(void *object, const uint8_t *source_pubkey, const uint8_t *data, uint16_t length,
768 void *userdata) 768 void *userdata)
769{ 769{
770 Onion_Client *onion_c = object; 770 Onion_Client *onion_c = (Onion_Client *)object;
771 771
772 if (length < DHTPK_DATA_MIN_LENGTH) { 772 if (length < DHTPK_DATA_MIN_LENGTH) {
773 return 1; 773 return 1;
@@ -975,7 +975,7 @@ static int send_dht_dhtpk(const Onion_Client *onion_c, int friend_num, const uin
975static int handle_dht_dhtpk(void *object, IP_Port source, const uint8_t *source_pubkey, const uint8_t *packet, 975static int handle_dht_dhtpk(void *object, IP_Port source, const uint8_t *source_pubkey, const uint8_t *packet,
976 uint16_t length, void *userdata) 976 uint16_t length, void *userdata)
977{ 977{
978 Onion_Client *onion_c = object; 978 Onion_Client *onion_c = (Onion_Client *)object;
979 979
980 if (length < DHTPK_DATA_MIN_LENGTH + DATA_IN_RESPONSE_MIN_SIZE + crypto_box_NONCEBYTES) { 980 if (length < DHTPK_DATA_MIN_LENGTH + DATA_IN_RESPONSE_MIN_SIZE + crypto_box_NONCEBYTES) {
981 return 1; 981 return 1;
@@ -1092,7 +1092,7 @@ static int realloc_onion_friends(Onion_Client *onion_c, uint32_t num)
1092 return 0; 1092 return 0;
1093 } 1093 }
1094 1094
1095 Onion_Friend *newonion_friends = realloc(onion_c->friends_list, num * sizeof(Onion_Friend)); 1095 Onion_Friend *newonion_friends = (Onion_Friend *)realloc(onion_c->friends_list, num * sizeof(Onion_Friend));
1096 1096
1097 if (newonion_friends == NULL) { 1097 if (newonion_friends == NULL) {
1098 return -1; 1098 return -1;
@@ -1605,7 +1605,7 @@ Onion_Client *new_onion_client(Net_Crypto *c)
1605 return NULL; 1605 return NULL;
1606 } 1606 }
1607 1607
1608 Onion_Client *onion_c = calloc(1, sizeof(Onion_Client)); 1608 Onion_Client *onion_c = (Onion_Client *)calloc(1, sizeof(Onion_Client));
1609 1609
1610 if (onion_c == NULL) { 1610 if (onion_c == NULL) {
1611 return NULL; 1611 return NULL;
diff --git a/toxcore/ping.c b/toxcore/ping.c
index d15ccd47..052650e3 100644
--- a/toxcore/ping.c
+++ b/toxcore/ping.c
@@ -134,9 +134,9 @@ static int send_ping_response(PING *ping, IP_Port ipp, const uint8_t *public_key
134 return sendpacket(ping->dht->net, ipp, pk, sizeof(pk)); 134 return sendpacket(ping->dht->net, ipp, pk, sizeof(pk));
135} 135}
136 136
137static int handle_ping_request(void *_dht, IP_Port source, const uint8_t *packet, uint16_t length, void *userdata) 137static int handle_ping_request(void *object, IP_Port source, const uint8_t *packet, uint16_t length, void *userdata)
138{ 138{
139 DHT *dht = _dht; 139 DHT *dht = (DHT *)object;
140 int rc; 140 int rc;
141 141
142 if (length != DHT_PING_SIZE) { 142 if (length != DHT_PING_SIZE) {
@@ -177,9 +177,9 @@ static int handle_ping_request(void *_dht, IP_Port source, const uint8_t *packet
177 return 0; 177 return 0;
178} 178}
179 179
180static int handle_ping_response(void *_dht, IP_Port source, const uint8_t *packet, uint16_t length, void *userdata) 180static int handle_ping_response(void *object, IP_Port source, const uint8_t *packet, uint16_t length, void *userdata)
181{ 181{
182 DHT *dht = _dht; 182 DHT *dht = (DHT *)object;
183 int rc; 183 int rc;
184 184
185 if (length != DHT_PING_SIZE) { 185 if (length != DHT_PING_SIZE) {
@@ -353,7 +353,7 @@ void do_to_ping(PING *ping)
353 353
354PING *new_ping(DHT *dht) 354PING *new_ping(DHT *dht)
355{ 355{
356 PING *ping = calloc(1, sizeof(PING)); 356 PING *ping = (PING *)calloc(1, sizeof(PING));
357 357
358 if (ping == NULL) { 358 if (ping == NULL) {
359 return NULL; 359 return NULL;
diff --git a/toxcore/ping_array.c b/toxcore/ping_array.c
index 8a23c6d8..ee7ff8be 100644
--- a/toxcore/ping_array.c
+++ b/toxcore/ping_array.c
@@ -145,7 +145,7 @@ int ping_array_init(Ping_Array *empty_array, uint32_t size, uint32_t timeout)
145 return -1; 145 return -1;
146 } 146 }
147 147
148 empty_array->entries = calloc(size, sizeof(Ping_Array_Entry)); 148 empty_array->entries = (Ping_Array_Entry *)calloc(size, sizeof(Ping_Array_Entry));
149 149
150 if (empty_array->entries == NULL) { 150 if (empty_array->entries == NULL) {
151 return -1; 151 return -1;
diff --git a/toxcore/tox.c b/toxcore/tox.c
index 93993c53..bf664b41 100644
--- a/toxcore/tox.c
+++ b/toxcore/tox.c
@@ -158,7 +158,7 @@ void tox_options_default(struct Tox_Options *options)
158 158
159struct Tox_Options *tox_options_new(TOX_ERR_OPTIONS_NEW *error) 159struct Tox_Options *tox_options_new(TOX_ERR_OPTIONS_NEW *error)
160{ 160{
161 struct Tox_Options *options = calloc(sizeof(struct Tox_Options), 1); 161 struct Tox_Options *options = (struct Tox_Options *)calloc(sizeof(struct Tox_Options), 1);
162 162
163 if (options) { 163 if (options) {
164 tox_options_default(options); 164 tox_options_default(options);
@@ -303,7 +303,7 @@ void tox_kill(Tox *tox)
303 303
304 Messenger *m = tox; 304 Messenger *m = tox;
305 Logger *log = m->log; 305 Logger *log = m->log;
306 kill_groupchats(m->group_chat_object); 306 kill_groupchats((Group_Chats *)m->group_chat_object);
307 kill_messenger(m); 307 kill_messenger(m);
308 logger_kill(log); 308 logger_kill(log);
309} 309}
@@ -463,7 +463,7 @@ TOX_CONNECTION tox_self_get_connection_status(const Tox *tox)
463void tox_callback_self_connection_status(Tox *tox, tox_self_connection_status_cb *callback) 463void tox_callback_self_connection_status(Tox *tox, tox_self_connection_status_cb *callback)
464{ 464{
465 Messenger *m = tox; 465 Messenger *m = tox;
466 m_callback_core_connection(m, callback); 466 m_callback_core_connection(m, (void (*)(Messenger *, unsigned int, void *))callback);
467} 467}
468 468
469uint32_t tox_iteration_interval(const Tox *tox) 469uint32_t tox_iteration_interval(const Tox *tox)
@@ -476,7 +476,7 @@ void tox_iterate(Tox *tox, void *user_data)
476{ 476{
477 Messenger *m = tox; 477 Messenger *m = tox;
478 do_messenger(m, user_data); 478 do_messenger(m, user_data);
479 do_groupchats(m->group_chat_object, user_data); 479 do_groupchats((Group_Chats *)m->group_chat_object, user_data);
480} 480}
481 481
482void tox_self_get_address(const Tox *tox, uint8_t *address) 482void tox_self_get_address(const Tox *tox, uint8_t *address)
@@ -528,7 +528,7 @@ bool tox_self_set_name(Tox *tox, const uint8_t *name, size_t length, TOX_ERR_SET
528 528
529 if (setname(m, name, length) == 0) { 529 if (setname(m, name, length) == 0) {
530 // TODO(irungentoo): function to set different per group names? 530 // TODO(irungentoo): function to set different per group names?
531 send_name_all_groups(m->group_chat_object); 531 send_name_all_groups((Group_Chats *)m->group_chat_object);
532 SET_ERROR_PARAMETER(error, TOX_ERR_SET_INFO_OK); 532 SET_ERROR_PARAMETER(error, TOX_ERR_SET_INFO_OK);
533 return 1; 533 return 1;
534 } 534 }
@@ -592,7 +592,7 @@ void tox_self_set_status(Tox *tox, TOX_USER_STATUS status)
592TOX_USER_STATUS tox_self_get_status(const Tox *tox) 592TOX_USER_STATUS tox_self_get_status(const Tox *tox)
593{ 593{
594 const Messenger *m = tox; 594 const Messenger *m = tox;
595 return m_get_self_userstatus(m); 595 return (TOX_USER_STATUS)m_get_self_userstatus(m);
596} 596}
597 597
598static void set_friend_error(int32_t ret, TOX_ERR_FRIEND_ADD *error) 598static void set_friend_error(int32_t ret, TOX_ERR_FRIEND_ADD *error)
@@ -842,17 +842,17 @@ TOX_USER_STATUS tox_friend_get_status(const Tox *tox, uint32_t friend_number, TO
842 842
843 if (ret == USERSTATUS_INVALID) { 843 if (ret == USERSTATUS_INVALID) {
844 SET_ERROR_PARAMETER(error, TOX_ERR_FRIEND_QUERY_FRIEND_NOT_FOUND); 844 SET_ERROR_PARAMETER(error, TOX_ERR_FRIEND_QUERY_FRIEND_NOT_FOUND);
845 return TOX_USER_STATUS_BUSY + 1; 845 return (TOX_USER_STATUS)(TOX_USER_STATUS_BUSY + 1);
846 } 846 }
847 847
848 SET_ERROR_PARAMETER(error, TOX_ERR_FRIEND_QUERY_OK); 848 SET_ERROR_PARAMETER(error, TOX_ERR_FRIEND_QUERY_OK);
849 return ret; 849 return (TOX_USER_STATUS)ret;
850} 850}
851 851
852void tox_callback_friend_status(Tox *tox, tox_friend_status_cb *callback) 852void tox_callback_friend_status(Tox *tox, tox_friend_status_cb *callback)
853{ 853{
854 Messenger *m = tox; 854 Messenger *m = tox;
855 m_callback_userstatus(m, callback); 855 m_callback_userstatus(m, (void (*)(Messenger *, uint32_t, unsigned int, void *))callback);
856} 856}
857 857
858TOX_CONNECTION tox_friend_get_connection_status(const Tox *tox, uint32_t friend_number, TOX_ERR_FRIEND_QUERY *error) 858TOX_CONNECTION tox_friend_get_connection_status(const Tox *tox, uint32_t friend_number, TOX_ERR_FRIEND_QUERY *error)
@@ -867,13 +867,13 @@ TOX_CONNECTION tox_friend_get_connection_status(const Tox *tox, uint32_t friend_
867 } 867 }
868 868
869 SET_ERROR_PARAMETER(error, TOX_ERR_FRIEND_QUERY_OK); 869 SET_ERROR_PARAMETER(error, TOX_ERR_FRIEND_QUERY_OK);
870 return ret; 870 return (TOX_CONNECTION)ret;
871} 871}
872 872
873void tox_callback_friend_connection_status(Tox *tox, tox_friend_connection_status_cb *callback) 873void tox_callback_friend_connection_status(Tox *tox, tox_friend_connection_status_cb *callback)
874{ 874{
875 Messenger *m = tox; 875 Messenger *m = tox;
876 m_callback_connectionstatus(m, callback); 876 m_callback_connectionstatus(m, (void (*)(Messenger *, uint32_t, unsigned int, void *))callback);
877} 877}
878 878
879bool tox_friend_get_typing(const Tox *tox, uint32_t friend_number, TOX_ERR_FRIEND_QUERY *error) 879bool tox_friend_get_typing(const Tox *tox, uint32_t friend_number, TOX_ERR_FRIEND_QUERY *error)
@@ -972,7 +972,7 @@ void tox_callback_friend_request(Tox *tox, tox_friend_request_cb *callback)
972void tox_callback_friend_message(Tox *tox, tox_friend_message_cb *callback) 972void tox_callback_friend_message(Tox *tox, tox_friend_message_cb *callback)
973{ 973{
974 Messenger *m = tox; 974 Messenger *m = tox;
975 m_callback_friendmessage(m, callback); 975 m_callback_friendmessage(m, (void (*)(Messenger *, uint32_t, unsigned int, const uint8_t *, size_t, void *))callback);
976} 976}
977 977
978bool tox_hash(uint8_t *hash, const uint8_t *data, size_t length) 978bool tox_hash(uint8_t *hash, const uint8_t *data, size_t length)
@@ -1079,7 +1079,7 @@ bool tox_file_seek(Tox *tox, uint32_t friend_number, uint32_t file_number, uint6
1079void tox_callback_file_recv_control(Tox *tox, tox_file_recv_control_cb *callback) 1079void tox_callback_file_recv_control(Tox *tox, tox_file_recv_control_cb *callback)
1080{ 1080{
1081 Messenger *m = tox; 1081 Messenger *m = tox;
1082 callback_file_control(m, callback); 1082 callback_file_control(m, (void (*)(Messenger *, uint32_t, uint32_t, unsigned int, void *))callback);
1083} 1083}
1084 1084
1085bool tox_file_get_file_id(const Tox *tox, uint32_t friend_number, uint32_t file_number, uint8_t *file_id, 1085bool tox_file_get_file_id(const Tox *tox, uint32_t friend_number, uint32_t file_number, uint8_t *file_id,
diff --git a/toxcore/util.c b/toxcore/util.c
index f9fe7852..93a3d436 100644
--- a/toxcore/util.c
+++ b/toxcore/util.c
@@ -240,7 +240,7 @@ bool rb_read(RingBuffer *b, void **p)
240} 240}
241RingBuffer *rb_new(int size) 241RingBuffer *rb_new(int size)
242{ 242{
243 RingBuffer *buf = calloc(sizeof(RingBuffer), 1); 243 RingBuffer *buf = (RingBuffer *)calloc(sizeof(RingBuffer), 1);
244 244
245 if (!buf) { 245 if (!buf) {
246 return NULL; 246 return NULL;
@@ -248,7 +248,7 @@ RingBuffer *rb_new(int size)
248 248
249 buf->size = size + 1; /* include empty elem */ 249 buf->size = size + 1; /* include empty elem */
250 250
251 if (!(buf->data = calloc(buf->size, sizeof(void *)))) { 251 if (!(buf->data = (void **)calloc(buf->size, sizeof(void *)))) {
252 free(buf); 252 free(buf);
253 return NULL; 253 return NULL;
254 } 254 }
diff --git a/toxdns/toxdns.c b/toxdns/toxdns.c
index c420c944..6622d6a5 100644
--- a/toxdns/toxdns.c
+++ b/toxdns/toxdns.c
@@ -29,7 +29,11 @@
29#include "../toxcore/logger.h" 29#include "../toxcore/logger.h"
30#include "toxdns.h" 30#include "toxdns.h"
31 31
32static const char base32[32] = {"abcdefghijklmnopqrstuvwxyz012345"}; 32static const char base32[32] = {
33 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm',
34 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z',
35 '0', '1', '2', '3', '4', '5',
36};
33 37
34#define _encode(a, b, c) \ 38#define _encode(a, b, c) \
35{ \ 39{ \
@@ -68,7 +72,7 @@ static void dns_new_temp_keys(DNS_Object *d)
68 */ 72 */
69void *tox_dns3_new(uint8_t *server_public_key) 73void *tox_dns3_new(uint8_t *server_public_key)
70{ 74{
71 DNS_Object *d = malloc(sizeof(DNS_Object)); 75 DNS_Object *d = (DNS_Object *)malloc(sizeof(DNS_Object));
72 76
73 if (d == NULL) { 77 if (d == NULL) {
74 return NULL; 78 return NULL;
@@ -111,7 +115,7 @@ int tox_generate_dns3_string(void *dns3_object, uint8_t *string, uint16_t string
111 return -1; 115 return -1;
112 } 116 }
113 117
114 DNS_Object *d = dns3_object; 118 DNS_Object *d = (DNS_Object *)dns3_object;
115 uint8_t buffer[1024]; 119 uint8_t buffer[1024];
116 uint8_t nonce[crypto_box_NONCEBYTES] = {0}; 120 uint8_t nonce[crypto_box_NONCEBYTES] = {0};
117 memcpy(nonce, &d->nonce, sizeof(uint32_t)); 121 memcpy(nonce, &d->nonce, sizeof(uint32_t));
@@ -202,7 +206,7 @@ static int decode(uint8_t *dest, uint8_t *src)
202int tox_decrypt_dns3_TXT(void *dns3_object, uint8_t *tox_id, uint8_t *id_record, uint32_t id_record_len, 206int tox_decrypt_dns3_TXT(void *dns3_object, uint8_t *tox_id, uint8_t *id_record, uint32_t id_record_len,
203 uint32_t request_id) 207 uint32_t request_id)
204{ 208{
205 DNS_Object *d = dns3_object; 209 DNS_Object *d = (DNS_Object *)dns3_object;
206 210
207 if (id_record_len != 87) { 211 if (id_record_len != 87) {
208 return -1; 212 return -1;