summaryrefslogtreecommitdiff
path: root/toxcore
diff options
context:
space:
mode:
authoriphydf <iphydf@users.noreply.github.com>2018-01-28 21:30:39 +0000
committeriphydf <iphydf@users.noreply.github.com>2018-01-30 23:35:50 +0000
commit92ffad1a72bc8c422426d52ac408bd71242dd047 (patch)
treef592f353068dd2043525dd2cc04d6124a4ed4bc4 /toxcore
parent623e9ac331df7323660e21c8a2226523a5ee713b (diff)
Use nullptr as NULL pointer constant instead of NULL or 0.
This changes only code, no string literals or comments.
Diffstat (limited to 'toxcore')
-rw-r--r--toxcore/BUILD.bazel2
-rw-r--r--toxcore/DHT.c82
-rw-r--r--toxcore/LAN_discovery.c6
-rw-r--r--toxcore/Messenger.c73
-rw-r--r--toxcore/TCP_client.c24
-rw-r--r--toxcore/TCP_connection.c24
-rw-r--r--toxcore/TCP_server.c28
-rw-r--r--toxcore/ccompat.h4
-rw-r--r--toxcore/friend_connection.c16
-rw-r--r--toxcore/group.c38
-rw-r--r--toxcore/list.c10
-rw-r--r--toxcore/net_crypto.c134
-rw-r--r--toxcore/network.c66
-rw-r--r--toxcore/network.h9
-rw-r--r--toxcore/onion.c22
-rw-r--r--toxcore/onion_announce.c14
-rw-r--r--toxcore/onion_client.c55
-rw-r--r--toxcore/ping.c12
-rw-r--r--toxcore/ping_array.c18
-rw-r--r--toxcore/tox.c24
-rw-r--r--toxcore/tox_api.c4
-rw-r--r--toxcore/util.c2
22 files changed, 339 insertions, 328 deletions
diff --git a/toxcore/BUILD.bazel b/toxcore/BUILD.bazel
index f59e55fc..cde5b70c 100644
--- a/toxcore/BUILD.bazel
+++ b/toxcore/BUILD.bazel
@@ -9,6 +9,7 @@ filegroup(
9cc_library( 9cc_library(
10 name = "ccompat", 10 name = "ccompat",
11 hdrs = ["ccompat.h"], 11 hdrs = ["ccompat.h"],
12 visibility = ["//c-toxcore:__subpackages__"],
12) 13)
13 14
14cc_library( 15cc_library(
@@ -31,6 +32,7 @@ cc_library(
31 name = "list", 32 name = "list",
32 srcs = ["list.c"], 33 srcs = ["list.c"],
33 hdrs = ["list.h"], 34 hdrs = ["list.h"],
35 deps = [":ccompat"],
34) 36)
35 37
36cc_library( 38cc_library(
diff --git a/toxcore/DHT.c b/toxcore/DHT.c
index 747f7328..4ee84fd2 100644
--- a/toxcore/DHT.c
+++ b/toxcore/DHT.c
@@ -376,7 +376,7 @@ int packed_node_size(uint8_t ip_family)
376 */ 376 */
377int pack_ip_port(uint8_t *data, uint16_t length, const IP_Port *ip_port) 377int pack_ip_port(uint8_t *data, uint16_t length, const IP_Port *ip_port)
378{ 378{
379 if (data == NULL) { 379 if (data == nullptr) {
380 return -1; 380 return -1;
381 } 381 }
382 382
@@ -454,7 +454,7 @@ static int DHT_create_packet(const uint8_t public_key[CRYPTO_PUBLIC_KEY_SIZE],
454 */ 454 */
455int unpack_ip_port(IP_Port *ip_port, const uint8_t *data, uint16_t length, uint8_t tcp_enabled) 455int unpack_ip_port(IP_Port *ip_port, const uint8_t *data, uint16_t length, uint8_t tcp_enabled)
456{ 456{
457 if (data == NULL) { 457 if (data == nullptr) {
458 return -1; 458 return -1;
459 } 459 }
460 460
@@ -772,7 +772,7 @@ static void get_close_nodes_inner(const uint8_t *public_key, Node_format *nodes_
772 continue; 772 continue;
773 } 773 }
774 774
775 const IPPTsPng *ipptp = NULL; 775 const IPPTsPng *ipptp = nullptr;
776 776
777 if (sa_family == TOX_AF_INET) { 777 if (sa_family == TOX_AF_INET) {
778 ipptp = &client->assoc4; 778 ipptp = &client->assoc4;
@@ -942,8 +942,8 @@ static void sort_client_list(Client_data *list, unsigned int length, const uint8
942 942
943static void update_client_with_reset(Client_data *client, const IP_Port *ip_port) 943static void update_client_with_reset(Client_data *client, const IP_Port *ip_port)
944{ 944{
945 IPPTsPng *ipptp_write = NULL; 945 IPPTsPng *ipptp_write = nullptr;
946 IPPTsPng *ipptp_clear = NULL; 946 IPPTsPng *ipptp_clear = nullptr;
947 947
948 if (ip_port->ip.family == TOX_AF_INET) { 948 if (ip_port->ip.family == TOX_AF_INET) {
949 ipptp_write = &client->assoc4; 949 ipptp_write = &client->assoc4;
@@ -1161,7 +1161,7 @@ uint32_t addto_lists(DHT *dht, IP_Port ip_port, const uint8_t *public_key)
1161 used++; 1161 used++;
1162 } 1162 }
1163 1163
1164 DHT_Friend *friend_foundip = 0; 1164 DHT_Friend *friend_foundip = nullptr;
1165 1165
1166 for (uint32_t i = 0; i < dht->num_friends; ++i) { 1166 for (uint32_t i = 0; i < dht->num_friends; ++i) {
1167 const bool in_list = client_or_ip_port_in_list(dht->log, dht->friends_list[i].client_list, 1167 const bool in_list = client_or_ip_port_in_list(dht->log, dht->friends_list[i].client_list,
@@ -1265,7 +1265,7 @@ static int getnodes(DHT *dht, IP_Port ip_port, const uint8_t *public_key, const
1265 1265
1266 uint64_t ping_id = 0; 1266 uint64_t ping_id = 0;
1267 1267
1268 if (sendback_node != NULL) { 1268 if (sendback_node != nullptr) {
1269 memcpy(plain_message + sizeof(receiver), sendback_node, sizeof(Node_format)); 1269 memcpy(plain_message + sizeof(receiver), sendback_node, sizeof(Node_format));
1270 ping_id = ping_array_add(dht->dht_harden_ping_array, plain_message, sizeof(plain_message)); 1270 ping_id = ping_array_add(dht->dht_harden_ping_array, plain_message, sizeof(plain_message));
1271 } else { 1271 } else {
@@ -1533,7 +1533,7 @@ int DHT_addfriend(DHT *dht, const uint8_t *public_key, void (*ip_callback)(void
1533 1533
1534 DHT_Friend *temp = (DHT_Friend *)realloc(dht->friends_list, sizeof(DHT_Friend) * (dht->num_friends + 1)); 1534 DHT_Friend *temp = (DHT_Friend *)realloc(dht->friends_list, sizeof(DHT_Friend) * (dht->num_friends + 1));
1535 1535
1536 if (temp == NULL) { 1536 if (temp == nullptr) {
1537 return -1; 1537 return -1;
1538 } 1538 }
1539 1539
@@ -1573,8 +1573,8 @@ int DHT_delfriend(DHT *dht, const uint8_t *public_key, uint16_t lock_count)
1573 1573
1574 if (dht_friend->lock_count && lock_count) { /* DHT friend is still in use.*/ 1574 if (dht_friend->lock_count && lock_count) { /* DHT friend is still in use.*/
1575 --lock_count; 1575 --lock_count;
1576 dht_friend->callbacks[lock_count].ip_callback = NULL; 1576 dht_friend->callbacks[lock_count].ip_callback = nullptr;
1577 dht_friend->callbacks[lock_count].data = NULL; 1577 dht_friend->callbacks[lock_count].data = nullptr;
1578 dht_friend->callbacks[lock_count].number = 0; 1578 dht_friend->callbacks[lock_count].number = 0;
1579 return 0; 1579 return 0;
1580 } 1580 }
@@ -1589,13 +1589,13 @@ int DHT_delfriend(DHT *dht, const uint8_t *public_key, uint16_t lock_count)
1589 1589
1590 if (dht->num_friends == 0) { 1590 if (dht->num_friends == 0) {
1591 free(dht->friends_list); 1591 free(dht->friends_list);
1592 dht->friends_list = NULL; 1592 dht->friends_list = nullptr;
1593 return 0; 1593 return 0;
1594 } 1594 }
1595 1595
1596 DHT_Friend *temp = (DHT_Friend *)realloc(dht->friends_list, sizeof(DHT_Friend) * (dht->num_friends)); 1596 DHT_Friend *temp = (DHT_Friend *)realloc(dht->friends_list, sizeof(DHT_Friend) * (dht->num_friends));
1597 1597
1598 if (temp == NULL) { 1598 if (temp == nullptr) {
1599 return -1; 1599 return -1;
1600 } 1600 }
1601 1601
@@ -1664,7 +1664,7 @@ static uint8_t do_ping_and_sendnode_requests(DHT *dht, uint64_t *lastgetnode, co
1664 not_kill++; 1664 not_kill++;
1665 1665
1666 if (is_timeout(assoc->last_pinged, PING_INTERVAL)) { 1666 if (is_timeout(assoc->last_pinged, PING_INTERVAL)) {
1667 getnodes(dht, assoc->ip_port, client->public_key, public_key, NULL); 1667 getnodes(dht, assoc->ip_port, client->public_key, public_key, nullptr);
1668 assoc->last_pinged = temp_time; 1668 assoc->last_pinged = temp_time;
1669 } 1669 }
1670 1670
@@ -1696,7 +1696,7 @@ static uint8_t do_ping_and_sendnode_requests(DHT *dht, uint64_t *lastgetnode, co
1696 rand_node += rand() % (num_nodes - (rand_node + 1)); 1696 rand_node += rand() % (num_nodes - (rand_node + 1));
1697 } 1697 }
1698 1698
1699 getnodes(dht, assoc_list[rand_node]->ip_port, client_list[rand_node]->public_key, public_key, NULL); 1699 getnodes(dht, assoc_list[rand_node]->ip_port, client_list[rand_node]->public_key, public_key, nullptr);
1700 1700
1701 *lastgetnode = temp_time; 1701 *lastgetnode = temp_time;
1702 ++*bootstrap_times; 1702 ++*bootstrap_times;
@@ -1715,7 +1715,7 @@ static void do_DHT_friends(DHT *dht)
1715 1715
1716 for (size_t j = 0; j < dht_friend->num_to_bootstrap; ++j) { 1716 for (size_t j = 0; j < dht_friend->num_to_bootstrap; ++j) {
1717 getnodes(dht, dht_friend->to_bootstrap[j].ip_port, dht_friend->to_bootstrap[j].public_key, dht_friend->public_key, 1717 getnodes(dht, dht_friend->to_bootstrap[j].ip_port, dht_friend->to_bootstrap[j].public_key, dht_friend->public_key,
1718 NULL); 1718 nullptr);
1719 } 1719 }
1720 1720
1721 dht_friend->num_to_bootstrap = 0; 1721 dht_friend->num_to_bootstrap = 0;
@@ -1732,7 +1732,7 @@ static void do_DHT_friends(DHT *dht)
1732static void do_Close(DHT *dht) 1732static void do_Close(DHT *dht)
1733{ 1733{
1734 for (size_t i = 0; i < dht->num_to_bootstrap; ++i) { 1734 for (size_t i = 0; i < dht->num_to_bootstrap; ++i) {
1735 getnodes(dht, dht->to_bootstrap[i].ip_port, dht->to_bootstrap[i].public_key, dht->self_public_key, NULL); 1735 getnodes(dht, dht->to_bootstrap[i].ip_port, dht->to_bootstrap[i].public_key, dht->self_public_key, nullptr);
1736 } 1736 }
1737 1737
1738 dht->num_to_bootstrap = 0; 1738 dht->num_to_bootstrap = 0;
@@ -1767,18 +1767,18 @@ static void do_Close(DHT *dht)
1767 1767
1768void DHT_getnodes(DHT *dht, const IP_Port *from_ipp, const uint8_t *from_id, const uint8_t *which_id) 1768void DHT_getnodes(DHT *dht, const IP_Port *from_ipp, const uint8_t *from_id, const uint8_t *which_id)
1769{ 1769{
1770 getnodes(dht, *from_ipp, from_id, which_id, NULL); 1770 getnodes(dht, *from_ipp, from_id, which_id, nullptr);
1771} 1771}
1772 1772
1773void DHT_bootstrap(DHT *dht, IP_Port ip_port, const uint8_t *public_key) 1773void DHT_bootstrap(DHT *dht, IP_Port ip_port, const uint8_t *public_key)
1774{ 1774{
1775 getnodes(dht, ip_port, public_key, dht->self_public_key, NULL); 1775 getnodes(dht, ip_port, public_key, dht->self_public_key, nullptr);
1776} 1776}
1777int DHT_bootstrap_from_address(DHT *dht, const char *address, uint8_t ipv6enabled, 1777int DHT_bootstrap_from_address(DHT *dht, const char *address, uint8_t ipv6enabled,
1778 uint16_t port, const uint8_t *public_key) 1778 uint16_t port, const uint8_t *public_key)
1779{ 1779{
1780 IP_Port ip_port_v64; 1780 IP_Port ip_port_v64;
1781 IP *ip_extra = NULL; 1781 IP *ip_extra = nullptr;
1782 IP_Port ip_port_v4; 1782 IP_Port ip_port_v4;
1783 ip_init(&ip_port_v64.ip, ipv6enabled); 1783 ip_init(&ip_port_v64.ip, ipv6enabled);
1784 1784
@@ -1793,7 +1793,7 @@ int DHT_bootstrap_from_address(DHT *dht, const char *address, uint8_t ipv6enable
1793 ip_port_v64.port = port; 1793 ip_port_v64.port = port;
1794 DHT_bootstrap(dht, ip_port_v64, public_key); 1794 DHT_bootstrap(dht, ip_port_v64, public_key);
1795 1795
1796 if ((ip_extra != NULL) && ip_isset(ip_extra)) { 1796 if ((ip_extra != nullptr) && ip_isset(ip_extra)) {
1797 ip_port_v4.port = port; 1797 ip_port_v4.port = port;
1798 DHT_bootstrap(dht, ip_port_v4, public_key); 1798 DHT_bootstrap(dht, ip_port_v4, public_key);
1799 } 1799 }
@@ -2319,7 +2319,7 @@ static IPPTsPng *get_closelist_IPPTsPng(DHT *dht, const uint8_t *public_key, Fam
2319 } 2319 }
2320 } 2320 }
2321 2321
2322 return NULL; 2322 return nullptr;
2323} 2323}
2324 2324
2325/* 2325/*
@@ -2391,7 +2391,7 @@ static int handle_hardening(void *object, IP_Port source, const uint8_t *source_
2391 2391
2392 uint16_t length_nodes = length - 1 - CRYPTO_PUBLIC_KEY_SIZE; 2392 uint16_t length_nodes = length - 1 - CRYPTO_PUBLIC_KEY_SIZE;
2393 Node_format nodes[MAX_SENT_NODES]; 2393 Node_format nodes[MAX_SENT_NODES];
2394 int num_nodes = unpack_nodes(nodes, MAX_SENT_NODES, 0, packet + 1 + CRYPTO_PUBLIC_KEY_SIZE, length_nodes, 0); 2394 int num_nodes = unpack_nodes(nodes, MAX_SENT_NODES, nullptr, packet + 1 + CRYPTO_PUBLIC_KEY_SIZE, length_nodes, 0);
2395 2395
2396 /* TODO(irungentoo): MAX_SENT_NODES nodes should be returned at all times 2396 /* TODO(irungentoo): MAX_SENT_NODES nodes should be returned at all times
2397 (right now we have a small network size so it could cause problems for testing and etc..) */ 2397 (right now we have a small network size so it could cause problems for testing and etc..) */
@@ -2406,7 +2406,7 @@ static int handle_hardening(void *object, IP_Port source, const uint8_t *source_
2406 2406
2407 IPPTsPng *temp = get_closelist_IPPTsPng(dht, packet + 1, nodes[0].ip_port.ip.family); 2407 IPPTsPng *temp = get_closelist_IPPTsPng(dht, packet + 1, nodes[0].ip_port.ip.family);
2408 2408
2409 if (temp == NULL) { 2409 if (temp == nullptr) {
2410 return 1; 2410 return 1;
2411 } 2411 }
2412 2412
@@ -2465,21 +2465,21 @@ static uint16_t list_nodes(Client_data *list, size_t length, Node_format *nodes,
2465 uint16_t count = 0; 2465 uint16_t count = 0;
2466 2466
2467 for (size_t i = length; i != 0; --i) { 2467 for (size_t i = length; i != 0; --i) {
2468 IPPTsPng *assoc = NULL; 2468 IPPTsPng *assoc = nullptr;
2469 2469
2470 if (!is_timeout(list[i - 1].assoc4.timestamp, BAD_NODE_TIMEOUT)) { 2470 if (!is_timeout(list[i - 1].assoc4.timestamp, BAD_NODE_TIMEOUT)) {
2471 assoc = &list[i - 1].assoc4; 2471 assoc = &list[i - 1].assoc4;
2472 } 2472 }
2473 2473
2474 if (!is_timeout(list[i - 1].assoc6.timestamp, BAD_NODE_TIMEOUT)) { 2474 if (!is_timeout(list[i - 1].assoc6.timestamp, BAD_NODE_TIMEOUT)) {
2475 if (assoc == NULL) { 2475 if (assoc == nullptr) {
2476 assoc = &list[i - 1].assoc6; 2476 assoc = &list[i - 1].assoc6;
2477 } else if (rand() % 2) { 2477 } else if (rand() % 2) {
2478 assoc = &list[i - 1].assoc6; 2478 assoc = &list[i - 1].assoc6;
2479 } 2479 }
2480 } 2480 }
2481 2481
2482 if (assoc != NULL) { 2482 if (assoc != nullptr) {
2483 memcpy(nodes[count].public_key, list[i - 1].public_key, CRYPTO_PUBLIC_KEY_SIZE); 2483 memcpy(nodes[count].public_key, list[i - 1].public_key, CRYPTO_PUBLIC_KEY_SIZE);
2484 nodes[count].ip_port = assoc->ip_port; 2484 nodes[count].ip_port = assoc->ip_port;
2485 ++count; 2485 ++count;
@@ -2635,14 +2635,14 @@ DHT *new_DHT(Logger *log, Networking_Core *net, bool holepunching_enabled)
2635 /* init time */ 2635 /* init time */
2636 unix_time_update(); 2636 unix_time_update();
2637 2637
2638 if (net == NULL) { 2638 if (net == nullptr) {
2639 return NULL; 2639 return nullptr;
2640 } 2640 }
2641 2641
2642 DHT *dht = (DHT *)calloc(1, sizeof(DHT)); 2642 DHT *dht = (DHT *)calloc(1, sizeof(DHT));
2643 2643
2644 if (dht == NULL) { 2644 if (dht == nullptr) {
2645 return NULL; 2645 return nullptr;
2646 } 2646 }
2647 2647
2648 dht->log = log; 2648 dht->log = log;
@@ -2652,9 +2652,9 @@ DHT *new_DHT(Logger *log, Networking_Core *net, bool holepunching_enabled)
2652 2652
2653 dht->ping = ping_new(dht); 2653 dht->ping = ping_new(dht);
2654 2654
2655 if (dht->ping == NULL) { 2655 if (dht->ping == nullptr) {
2656 kill_DHT(dht); 2656 kill_DHT(dht);
2657 return NULL; 2657 return nullptr;
2658 } 2658 }
2659 2659
2660 networking_registerhandler(dht->net, NET_PACKET_GET_NODES, &handle_getnodes, dht); 2660 networking_registerhandler(dht->net, NET_PACKET_GET_NODES, &handle_getnodes, dht);
@@ -2673,9 +2673,9 @@ DHT *new_DHT(Logger *log, Networking_Core *net, bool holepunching_enabled)
2673 uint8_t random_key_bytes[CRYPTO_PUBLIC_KEY_SIZE]; 2673 uint8_t random_key_bytes[CRYPTO_PUBLIC_KEY_SIZE];
2674 random_bytes(random_key_bytes, sizeof(random_key_bytes)); 2674 random_bytes(random_key_bytes, sizeof(random_key_bytes));
2675 2675
2676 if (DHT_addfriend(dht, random_key_bytes, 0, 0, 0, 0) != 0) { 2676 if (DHT_addfriend(dht, random_key_bytes, nullptr, nullptr, 0, nullptr) != 0) {
2677 kill_DHT(dht); 2677 kill_DHT(dht);
2678 return NULL; 2678 return nullptr;
2679 } 2679 }
2680 } 2680 }
2681 2681
@@ -2706,10 +2706,10 @@ void do_DHT(DHT *dht)
2706} 2706}
2707void kill_DHT(DHT *dht) 2707void kill_DHT(DHT *dht)
2708{ 2708{
2709 networking_registerhandler(dht->net, NET_PACKET_GET_NODES, NULL, NULL); 2709 networking_registerhandler(dht->net, NET_PACKET_GET_NODES, nullptr, nullptr);
2710 networking_registerhandler(dht->net, NET_PACKET_SEND_NODES_IPV6, NULL, NULL); 2710 networking_registerhandler(dht->net, NET_PACKET_SEND_NODES_IPV6, nullptr, nullptr);
2711 cryptopacket_registerhandler(dht, CRYPTO_PACKET_NAT_PING, NULL, NULL); 2711 cryptopacket_registerhandler(dht, CRYPTO_PACKET_NAT_PING, nullptr, nullptr);
2712 cryptopacket_registerhandler(dht, CRYPTO_PACKET_HARDENING, NULL, NULL); 2712 cryptopacket_registerhandler(dht, CRYPTO_PACKET_HARDENING, nullptr, nullptr);
2713 ping_array_kill(dht->dht_ping_array); 2713 ping_array_kill(dht->dht_ping_array);
2714 ping_array_kill(dht->dht_harden_ping_array); 2714 ping_array_kill(dht->dht_harden_ping_array);
2715 ping_kill(dht->ping); 2715 ping_kill(dht->ping);
@@ -2817,7 +2817,7 @@ void DHT_save(DHT *dht, uint8_t *data)
2817/* Start sending packets after DHT loaded_friends_list and loaded_clients_list are set */ 2817/* Start sending packets after DHT loaded_friends_list and loaded_clients_list are set */
2818int DHT_connect_after_load(DHT *dht) 2818int DHT_connect_after_load(DHT *dht)
2819{ 2819{
2820 if (dht == NULL) { 2820 if (dht == nullptr) {
2821 return -1; 2821 return -1;
2822 } 2822 }
2823 2823
@@ -2828,7 +2828,7 @@ int DHT_connect_after_load(DHT *dht)
2828 /* DHT is connected, stop. */ 2828 /* DHT is connected, stop. */
2829 if (DHT_non_lan_connected(dht)) { 2829 if (DHT_non_lan_connected(dht)) {
2830 free(dht->loaded_nodes_list); 2830 free(dht->loaded_nodes_list);
2831 dht->loaded_nodes_list = NULL; 2831 dht->loaded_nodes_list = nullptr;
2832 dht->loaded_num_nodes = 0; 2832 dht->loaded_num_nodes = 0;
2833 return 0; 2833 return 0;
2834 } 2834 }
@@ -2857,7 +2857,7 @@ static int dht_load_state_callback(void *outer, const uint8_t *data, uint32_t le
2857 // Copy to loaded_clients_list 2857 // Copy to loaded_clients_list
2858 dht->loaded_nodes_list = (Node_format *)calloc(MAX_SAVED_DHT_NODES, sizeof(Node_format)); 2858 dht->loaded_nodes_list = (Node_format *)calloc(MAX_SAVED_DHT_NODES, sizeof(Node_format));
2859 2859
2860 int num = unpack_nodes(dht->loaded_nodes_list, MAX_SAVED_DHT_NODES, NULL, data, length, 0); 2860 int num = unpack_nodes(dht->loaded_nodes_list, MAX_SAVED_DHT_NODES, nullptr, data, length, 0);
2861 2861
2862 if (num > 0) { 2862 if (num > 0) {
2863 dht->loaded_num_nodes = num; 2863 dht->loaded_num_nodes = num;
diff --git a/toxcore/LAN_discovery.c b/toxcore/LAN_discovery.c
index c0724ad9..742b91ab 100644
--- a/toxcore/LAN_discovery.c
+++ b/toxcore/LAN_discovery.c
@@ -52,7 +52,7 @@ static void fetch_broadcast_info(uint16_t port)
52 IP_ADAPTER_INFO *pAdapterInfo = (IP_ADAPTER_INFO *)malloc(sizeof(IP_ADAPTER_INFO)); 52 IP_ADAPTER_INFO *pAdapterInfo = (IP_ADAPTER_INFO *)malloc(sizeof(IP_ADAPTER_INFO));
53 unsigned long ulOutBufLen = sizeof(IP_ADAPTER_INFO); 53 unsigned long ulOutBufLen = sizeof(IP_ADAPTER_INFO);
54 54
55 if (pAdapterInfo == NULL) { 55 if (pAdapterInfo == nullptr) {
56 return; 56 return;
57 } 57 }
58 58
@@ -60,7 +60,7 @@ static void fetch_broadcast_info(uint16_t port)
60 free(pAdapterInfo); 60 free(pAdapterInfo);
61 pAdapterInfo = (IP_ADAPTER_INFO *)malloc(ulOutBufLen); 61 pAdapterInfo = (IP_ADAPTER_INFO *)malloc(ulOutBufLen);
62 62
63 if (pAdapterInfo == NULL) { 63 if (pAdapterInfo == nullptr) {
64 return; 64 return;
65 } 65 }
66 } 66 }
@@ -405,5 +405,5 @@ void lan_discovery_init(DHT *dht)
405 405
406void lan_discovery_kill(DHT *dht) 406void lan_discovery_kill(DHT *dht)
407{ 407{
408 networking_registerhandler(dht_get_net(dht), NET_PACKET_LAN_DISCOVERY, NULL, NULL); 408 networking_registerhandler(dht_get_net(dht), NET_PACKET_LAN_DISCOVERY, nullptr, nullptr);
409} 409}
diff --git a/toxcore/Messenger.c b/toxcore/Messenger.c
index bc7d055b..c665a1f8 100644
--- a/toxcore/Messenger.c
+++ b/toxcore/Messenger.c
@@ -57,13 +57,13 @@ static int realloc_friendlist(Messenger *m, uint32_t num)
57{ 57{
58 if (num == 0) { 58 if (num == 0) {
59 free(m->friendlist); 59 free(m->friendlist);
60 m->friendlist = NULL; 60 m->friendlist = nullptr;
61 return 0; 61 return 0;
62 } 62 }
63 63
64 Friend *newfriendlist = (Friend *)realloc(m->friendlist, num * sizeof(Friend)); 64 Friend *newfriendlist = (Friend *)realloc(m->friendlist, num * sizeof(Friend));
65 65
66 if (newfriendlist == NULL) { 66 if (newfriendlist == nullptr) {
67 return -1; 67 return -1;
68 } 68 }
69 69
@@ -322,8 +322,8 @@ static int clear_receipts(Messenger *m, int32_t friendnumber)
322 receipts = temp_r; 322 receipts = temp_r;
323 } 323 }
324 324
325 m->friendlist[friendnumber].receipts_start = NULL; 325 m->friendlist[friendnumber].receipts_start = nullptr;
326 m->friendlist[friendnumber].receipts_end = NULL; 326 m->friendlist[friendnumber].receipts_end = nullptr;
327 return 0; 327 return 0;
328} 328}
329 329
@@ -349,7 +349,7 @@ static int add_receipt(Messenger *m, int32_t friendnumber, uint32_t packet_num,
349 } 349 }
350 350
351 m->friendlist[friendnumber].receipts_end = new_receipts; 351 m->friendlist[friendnumber].receipts_end = new_receipts;
352 new_receipts->next = NULL; 352 new_receipts->next = nullptr;
353 return 0; 353 return 0;
354} 354}
355/* 355/*
@@ -393,7 +393,7 @@ static int do_receipts(Messenger *m, int32_t friendnumber, void *userdata)
393 } 393 }
394 394
395 if (!m->friendlist[friendnumber].receipts_start) { 395 if (!m->friendlist[friendnumber].receipts_start) {
396 m->friendlist[friendnumber].receipts_end = NULL; 396 m->friendlist[friendnumber].receipts_end = nullptr;
397 } 397 }
398 398
399 return 0; 399 return 0;
@@ -416,7 +416,8 @@ int m_delfriend(Messenger *m, int32_t friendnumber)
416 416
417 clear_receipts(m, friendnumber); 417 clear_receipts(m, friendnumber);
418 remove_request_received(m->fr, m->friendlist[friendnumber].real_pk); 418 remove_request_received(m->fr, m->friendlist[friendnumber].real_pk);
419 friend_connection_callbacks(m->fr_c, m->friendlist[friendnumber].friendcon_id, MESSENGER_CALLBACK_INDEX, 0, 0, 0, 0, 0); 419 friend_connection_callbacks(m->fr_c, m->friendlist[friendnumber].friendcon_id, MESSENGER_CALLBACK_INDEX, nullptr,
420 nullptr, nullptr, nullptr, 0);
420 421
421 if (friend_con_connected(m->fr_c, m->friendlist[friendnumber].friendcon_id) == FRIENDCONN_STATUS_CONNECTED) { 422 if (friend_con_connected(m->fr_c, m->friendlist[friendnumber].friendcon_id) == FRIENDCONN_STATUS_CONNECTED) {
422 send_offline_packet(m, m->friendlist[friendnumber].friendcon_id); 423 send_offline_packet(m, m->friendlist[friendnumber].friendcon_id);
@@ -601,7 +602,7 @@ int setname(Messenger *m, const uint8_t *name, uint16_t length)
601 */ 602 */
602uint16_t getself_name(const Messenger *m, uint8_t *name) 603uint16_t getself_name(const Messenger *m, uint8_t *name)
603{ 604{
604 if (name == NULL) { 605 if (name == nullptr) {
605 return 0; 606 return 0;
606 } 607 }
607 608
@@ -1283,7 +1284,7 @@ int file_control(const Messenger *m, int32_t friendnumber, uint32_t filenumber,
1283 } 1284 }
1284 } 1285 }
1285 1286
1286 if (send_file_control_packet(m, friendnumber, send_receive, file_number, control, 0, 0)) { 1287 if (send_file_control_packet(m, friendnumber, send_receive, file_number, control, nullptr, 0)) {
1287 if (control == FILECONTROL_KILL) { 1288 if (control == FILECONTROL_KILL) {
1288 ft->status = FILESTATUS_NONE; 1289 ft->status = FILESTATUS_NONE;
1289 1290
@@ -1556,7 +1557,7 @@ static void do_reqchunk_filecb(Messenger *m, int32_t friendnumber, void *userdat
1556 1557
1557 if (ft->size == 0) { 1558 if (ft->size == 0) {
1558 /* Send 0 data to friend if file is 0 length. */ 1559 /* Send 0 data to friend if file is 0 length. */
1559 file_data(m, friendnumber, i, 0, 0, 0); 1560 file_data(m, friendnumber, i, 0, nullptr, 0);
1560 break; 1561 break;
1561 } 1562 }
1562 1563
@@ -1619,7 +1620,7 @@ static struct File_Transfers *get_file_transfer(uint8_t receive_send, uint8_t fi
1619 } 1620 }
1620 1621
1621 if (ft->status == FILESTATUS_NONE) { 1622 if (ft->status == FILESTATUS_NONE) {
1622 return NULL; 1623 return nullptr;
1623 } 1624 }
1624 1625
1625 return ft; 1626 return ft;
@@ -1639,10 +1640,10 @@ static int handle_filecontrol(Messenger *m, int32_t friendnumber, uint8_t receiv
1639 uint32_t real_filenumber; 1640 uint32_t real_filenumber;
1640 struct File_Transfers *ft = get_file_transfer(receive_send, filenumber, &real_filenumber, &m->friendlist[friendnumber]); 1641 struct File_Transfers *ft = get_file_transfer(receive_send, filenumber, &real_filenumber, &m->friendlist[friendnumber]);
1641 1642
1642 if (ft == NULL) { 1643 if (ft == nullptr) {
1643 LOGGER_DEBUG(m->log, "file control (friend %d, file %d): file transfer does not exist; telling the other to kill it", 1644 LOGGER_DEBUG(m->log, "file control (friend %d, file %d): file transfer does not exist; telling the other to kill it",
1644 friendnumber, filenumber); 1645 friendnumber, filenumber);
1645 send_file_control_packet(m, friendnumber, !receive_send, filenumber, FILECONTROL_KILL, 0, 0); 1646 send_file_control_packet(m, friendnumber, !receive_send, filenumber, FILECONTROL_KILL, nullptr, 0);
1646 return -1; 1647 return -1;
1647 } 1648 }
1648 1649
@@ -1919,7 +1920,7 @@ static int friend_already_added(const uint8_t *real_pk, void *data)
1919Messenger *new_messenger(Messenger_Options *options, unsigned int *error) 1920Messenger *new_messenger(Messenger_Options *options, unsigned int *error)
1920{ 1921{
1921 if (!options) { 1922 if (!options) {
1922 return NULL; 1923 return nullptr;
1923 } 1924 }
1924 1925
1925 if (error) { 1926 if (error) {
@@ -1929,22 +1930,22 @@ Messenger *new_messenger(Messenger_Options *options, unsigned int *error)
1929 Messenger *m = (Messenger *)calloc(1, sizeof(Messenger)); 1930 Messenger *m = (Messenger *)calloc(1, sizeof(Messenger));
1930 1931
1931 if (!m) { 1932 if (!m) {
1932 return NULL; 1933 return nullptr;
1933 } 1934 }
1934 1935
1935 m->fr = friendreq_new(); 1936 m->fr = friendreq_new();
1936 1937
1937 if (!m->fr) { 1938 if (!m->fr) {
1938 free(m); 1939 free(m);
1939 return NULL; 1940 return nullptr;
1940 } 1941 }
1941 1942
1942 Logger *log = NULL; 1943 Logger *log = nullptr;
1943 1944
1944 if (options->log_callback) { 1945 if (options->log_callback) {
1945 log = logger_new(); 1946 log = logger_new();
1946 1947
1947 if (log != NULL) { 1948 if (log != nullptr) {
1948 logger_callback_log(log, options->log_callback, m, options->log_user_data); 1949 logger_callback_log(log, options->log_callback, m, options->log_user_data);
1949 } 1950 }
1950 } 1951 }
@@ -1961,7 +1962,7 @@ Messenger *new_messenger(Messenger_Options *options, unsigned int *error)
1961 m->net = new_networking_ex(log, ip, options->port_range[0], options->port_range[1], &net_err); 1962 m->net = new_networking_ex(log, ip, options->port_range[0], options->port_range[1], &net_err);
1962 } 1963 }
1963 1964
1964 if (m->net == NULL) { 1965 if (m->net == nullptr) {
1965 friendreq_kill(m->fr); 1966 friendreq_kill(m->fr);
1966 free(m); 1967 free(m);
1967 1968
@@ -1969,26 +1970,26 @@ Messenger *new_messenger(Messenger_Options *options, unsigned int *error)
1969 *error = MESSENGER_ERROR_PORT; 1970 *error = MESSENGER_ERROR_PORT;
1970 } 1971 }
1971 1972
1972 return NULL; 1973 return nullptr;
1973 } 1974 }
1974 1975
1975 m->dht = new_DHT(m->log, m->net, options->hole_punching_enabled); 1976 m->dht = new_DHT(m->log, m->net, options->hole_punching_enabled);
1976 1977
1977 if (m->dht == NULL) { 1978 if (m->dht == nullptr) {
1978 kill_networking(m->net); 1979 kill_networking(m->net);
1979 friendreq_kill(m->fr); 1980 friendreq_kill(m->fr);
1980 free(m); 1981 free(m);
1981 return NULL; 1982 return nullptr;
1982 } 1983 }
1983 1984
1984 m->net_crypto = new_net_crypto(m->log, m->dht, &options->proxy_info); 1985 m->net_crypto = new_net_crypto(m->log, m->dht, &options->proxy_info);
1985 1986
1986 if (m->net_crypto == NULL) { 1987 if (m->net_crypto == nullptr) {
1987 kill_networking(m->net); 1988 kill_networking(m->net);
1988 kill_DHT(m->dht); 1989 kill_DHT(m->dht);
1989 friendreq_kill(m->fr); 1990 friendreq_kill(m->fr);
1990 free(m); 1991 free(m);
1991 return NULL; 1992 return nullptr;
1992 } 1993 }
1993 1994
1994 m->onion = new_onion(m->dht); 1995 m->onion = new_onion(m->dht);
@@ -2006,14 +2007,14 @@ Messenger *new_messenger(Messenger_Options *options, unsigned int *error)
2006 kill_networking(m->net); 2007 kill_networking(m->net);
2007 friendreq_kill(m->fr); 2008 friendreq_kill(m->fr);
2008 free(m); 2009 free(m);
2009 return NULL; 2010 return nullptr;
2010 } 2011 }
2011 2012
2012 if (options->tcp_server_port) { 2013 if (options->tcp_server_port) {
2013 m->tcp_server = new_TCP_server(options->ipv6enabled, 1, &options->tcp_server_port, dht_get_self_secret_key(m->dht), 2014 m->tcp_server = new_TCP_server(options->ipv6enabled, 1, &options->tcp_server_port, dht_get_self_secret_key(m->dht),
2014 m->onion); 2015 m->onion);
2015 2016
2016 if (m->tcp_server == NULL) { 2017 if (m->tcp_server == nullptr) {
2017 kill_friend_connections(m->fr_c); 2018 kill_friend_connections(m->fr_c);
2018 kill_onion(m->onion); 2019 kill_onion(m->onion);
2019 kill_onion_announce(m->onion_a); 2020 kill_onion_announce(m->onion_a);
@@ -2028,7 +2029,7 @@ Messenger *new_messenger(Messenger_Options *options, unsigned int *error)
2028 *error = MESSENGER_ERROR_TCP_SERVER; 2029 *error = MESSENGER_ERROR_TCP_SERVER;
2029 } 2030 }
2030 2031
2031 return NULL; 2032 return nullptr;
2032 } 2033 }
2033 } 2034 }
2034 2035
@@ -2292,7 +2293,7 @@ static int m_handle_packet(void *object, int i, const uint8_t *temp, uint16_t le
2292 memcpy(ft->id, data + 1 + sizeof(uint32_t) + sizeof(uint64_t), FILE_ID_LENGTH); 2293 memcpy(ft->id, data + 1 + sizeof(uint32_t) + sizeof(uint64_t), FILE_ID_LENGTH);
2293 2294
2294 VLA(uint8_t, filename_terminated, filename_length + 1); 2295 VLA(uint8_t, filename_terminated, filename_length + 1);
2295 uint8_t *filename = NULL; 2296 uint8_t *filename = nullptr;
2296 2297
2297 if (filename_length) { 2298 if (filename_length) {
2298 /* Force NULL terminate file name. */ 2299 /* Force NULL terminate file name. */
@@ -2368,7 +2369,7 @@ static int m_handle_packet(void *object, int i, const uint8_t *temp, uint16_t le
2368 const uint8_t *file_data; 2369 const uint8_t *file_data;
2369 2370
2370 if (file_data_length == 0) { 2371 if (file_data_length == 0) {
2371 file_data = NULL; 2372 file_data = nullptr;
2372 } else { 2373 } else {
2373 file_data = data + 1; 2374 file_data = data + 1;
2374 } 2375 }
@@ -2386,7 +2387,7 @@ static int m_handle_packet(void *object, int i, const uint8_t *temp, uint16_t le
2386 2387
2387 if (file_data_length && (ft->transferred >= ft->size || file_data_length != MAX_FILE_DATA_SIZE)) { 2388 if (file_data_length && (ft->transferred >= ft->size || file_data_length != MAX_FILE_DATA_SIZE)) {
2388 file_data_length = 0; 2389 file_data_length = 0;
2389 file_data = NULL; 2390 file_data = nullptr;
2390 position = ft->transferred; 2391 position = ft->transferred;
2391 2392
2392 /* Full file received. */ 2393 /* Full file received. */
@@ -2480,7 +2481,7 @@ static void do_friends(Messenger *m, void *userdata)
2480 do_receipts(m, i, userdata); 2481 do_receipts(m, i, userdata);
2481 do_reqchunk_filecb(m, i, userdata); 2482 do_reqchunk_filecb(m, i, userdata);
2482 2483
2483 m->friendlist[i].last_seen_time = (uint64_t) time(NULL); 2484 m->friendlist[i].last_seen_time = (uint64_t) time(nullptr);
2484 } 2485 }
2485 } 2486 }
2486} 2487}
@@ -2585,7 +2586,7 @@ void do_messenger(Messenger *m, void *userdata)
2585 2586
2586 for (client = 0; client < LCLIENT_LIST; client++) { 2587 for (client = 0; client < LCLIENT_LIST; client++) {
2587 const Client_data *cptr = dht_get_close_client(m->dht, client); 2588 const Client_data *cptr = dht_get_close_client(m->dht, client);
2588 const IPPTsPng *assoc = NULL; 2589 const IPPTsPng *assoc = nullptr;
2589 uint32_t a; 2590 uint32_t a;
2590 2591
2591 for (a = 0, assoc = &cptr->assoc4; a < 2; a++, assoc = &cptr->assoc6) { 2592 for (a = 0, assoc = &cptr->assoc4; a < 2; a++, assoc = &cptr->assoc6) {
@@ -2647,7 +2648,7 @@ void do_messenger(Messenger *m, void *userdata)
2647 if (dht2m[friend_idx] >= 0) { 2648 if (dht2m[friend_idx] >= 0) {
2648 msgfptr = &m->friendlist[dht2m[friend_idx]]; 2649 msgfptr = &m->friendlist[dht2m[friend_idx]];
2649 } else { 2650 } else {
2650 msgfptr = NULL; 2651 msgfptr = nullptr;
2651 } 2652 }
2652 2653
2653 dhtfptr = dht_get_friend(m->dht, friend_idx); 2654 dhtfptr = dht_get_friend(m->dht, friend_idx);
@@ -2665,7 +2666,7 @@ void do_messenger(Messenger *m, void *userdata)
2665 2666
2666 for (client = 0; client < MAX_FRIEND_CLIENTS; client++) { 2667 for (client = 0; client < MAX_FRIEND_CLIENTS; client++) {
2667 Client_data *cptr = &dhtfptr->client_list[client]; 2668 Client_data *cptr = &dhtfptr->client_list[client];
2668 IPPTsPng *assoc = NULL; 2669 IPPTsPng *assoc = nullptr;
2669 uint32_t a; 2670 uint32_t a;
2670 2671
2671 for (a = 0, assoc = &cptr->assoc4; a < 2; a++, assoc = &cptr->assoc6) { 2672 for (a = 0, assoc = &cptr->assoc4; a < 2; a++, assoc = &cptr->assoc6) {
@@ -3074,7 +3075,7 @@ static int messenger_load_state_callback(void *outer, const uint8_t *data, uint3
3074 break; 3075 break;
3075 } 3076 }
3076 3077
3077 unpack_nodes(m->loaded_relays, NUM_SAVED_TCP_RELAYS, 0, data, length, 1); 3078 unpack_nodes(m->loaded_relays, NUM_SAVED_TCP_RELAYS, nullptr, data, length, 1);
3078 m->has_added_relays = 0; 3079 m->has_added_relays = 0;
3079 3080
3080 break; 3081 break;
@@ -3087,7 +3088,7 @@ static int messenger_load_state_callback(void *outer, const uint8_t *data, uint3
3087 break; 3088 break;
3088 } 3089 }
3089 3090
3090 int i, num = unpack_nodes(nodes, NUM_SAVED_PATH_NODES, 0, data, length, 0); 3091 int i, num = unpack_nodes(nodes, NUM_SAVED_PATH_NODES, nullptr, data, length, 0);
3091 3092
3092 for (i = 0; i < num; ++i) { 3093 for (i = 0; i < num; ++i) {
3093 onion_add_bs_path_node(m->onion_c, nodes[i].ip_port, nodes[i].public_key); 3094 onion_add_bs_path_node(m->onion_c, nodes[i].ip_port, nodes[i].public_key);
diff --git a/toxcore/TCP_client.c b/toxcore/TCP_client.c
index b4092f80..c3d6f63d 100644
--- a/toxcore/TCP_client.c
+++ b/toxcore/TCP_client.c
@@ -382,7 +382,7 @@ static int client_send_pending_data(TCP_Client_Connection *con)
382 con->priority_queue_start = p; 382 con->priority_queue_start = p;
383 383
384 if (!p) { 384 if (!p) {
385 con->priority_queue_end = NULL; 385 con->priority_queue_end = nullptr;
386 return 0; 386 return 0;
387 } 387 }
388 388
@@ -401,7 +401,7 @@ static bool client_add_priority(TCP_Client_Connection *con, const uint8_t *packe
401 return 0; 401 return 0;
402 } 402 }
403 403
404 new_list->next = NULL; 404 new_list->next = nullptr;
405 new_list->size = size; 405 new_list->size = size;
406 new_list->sent = sent; 406 new_list->sent = sent;
407 memcpy(new_list->data, packet, size); 407 memcpy(new_list->data, packet, size);
@@ -694,16 +694,16 @@ TCP_Client_Connection *new_TCP_connection(IP_Port ip_port, const uint8_t *public
694 const uint8_t *self_secret_key, TCP_Proxy_Info *proxy_info) 694 const uint8_t *self_secret_key, TCP_Proxy_Info *proxy_info)
695{ 695{
696 if (networking_at_startup() != 0) { 696 if (networking_at_startup() != 0) {
697 return NULL; 697 return nullptr;
698 } 698 }
699 699
700 if (ip_port.ip.family != TOX_AF_INET && ip_port.ip.family != TOX_AF_INET6) { 700 if (ip_port.ip.family != TOX_AF_INET && ip_port.ip.family != TOX_AF_INET6) {
701 return NULL; 701 return nullptr;
702 } 702 }
703 703
704 TCP_Proxy_Info default_proxyinfo; 704 TCP_Proxy_Info default_proxyinfo;
705 705
706 if (proxy_info == NULL) { 706 if (proxy_info == nullptr) {
707 default_proxyinfo.proxy_type = TCP_PROXY_NONE; 707 default_proxyinfo.proxy_type = TCP_PROXY_NONE;
708 proxy_info = &default_proxyinfo; 708 proxy_info = &default_proxyinfo;
709 } 709 }
@@ -717,24 +717,24 @@ TCP_Client_Connection *new_TCP_connection(IP_Port ip_port, const uint8_t *public
717 Socket sock = net_socket(family, TOX_SOCK_STREAM, TOX_PROTO_TCP); 717 Socket sock = net_socket(family, TOX_SOCK_STREAM, TOX_PROTO_TCP);
718 718
719 if (!sock_valid(sock)) { 719 if (!sock_valid(sock)) {
720 return NULL; 720 return nullptr;
721 } 721 }
722 722
723 if (!set_socket_nosigpipe(sock)) { 723 if (!set_socket_nosigpipe(sock)) {
724 kill_sock(sock); 724 kill_sock(sock);
725 return 0; 725 return nullptr;
726 } 726 }
727 727
728 if (!(set_socket_nonblock(sock) && connect_sock_to(sock, ip_port, proxy_info))) { 728 if (!(set_socket_nonblock(sock) && connect_sock_to(sock, ip_port, proxy_info))) {
729 kill_sock(sock); 729 kill_sock(sock);
730 return NULL; 730 return nullptr;
731 } 731 }
732 732
733 TCP_Client_Connection *temp = (TCP_Client_Connection *)calloc(sizeof(TCP_Client_Connection), 1); 733 TCP_Client_Connection *temp = (TCP_Client_Connection *)calloc(sizeof(TCP_Client_Connection), 1);
734 734
735 if (temp == NULL) { 735 if (temp == nullptr) {
736 kill_sock(sock); 736 kill_sock(sock);
737 return NULL; 737 return nullptr;
738 } 738 }
739 739
740 temp->sock = sock; 740 temp->sock = sock;
@@ -761,7 +761,7 @@ TCP_Client_Connection *new_TCP_connection(IP_Port ip_port, const uint8_t *public
761 if (generate_handshake(temp) == -1) { 761 if (generate_handshake(temp) == -1) {
762 kill_sock(sock); 762 kill_sock(sock);
763 free(temp); 763 free(temp);
764 return NULL; 764 return nullptr;
765 } 765 }
766 766
767 break; 767 break;
@@ -1062,7 +1062,7 @@ void do_TCP_connection(TCP_Client_Connection *TCP_connection, void *userdata)
1062 */ 1062 */
1063void kill_TCP_connection(TCP_Client_Connection *TCP_connection) 1063void kill_TCP_connection(TCP_Client_Connection *TCP_connection)
1064{ 1064{
1065 if (TCP_connection == NULL) { 1065 if (TCP_connection == nullptr) {
1066 return; 1066 return;
1067 } 1067 }
1068 1068
diff --git a/toxcore/TCP_connection.c b/toxcore/TCP_connection.c
index a43069da..3ce75948 100644
--- a/toxcore/TCP_connection.c
+++ b/toxcore/TCP_connection.c
@@ -78,7 +78,7 @@ const uint8_t *tcp_connections_public_key(const TCP_Connections *tcp_c)
78 array, \ 78 array, \
79 (num) * sizeof(element_type)), \ 79 (num) * sizeof(element_type)), \
80 temp_pointer ? (array = temp_pointer, 0) : -1) \ 80 temp_pointer ? (array = temp_pointer, 0) : -1) \
81 : (free(array), array = NULL, 0)) 81 : (free(array), array = nullptr, 0))
82 82
83 83
84/* return 1 if the connections_number is not valid. 84/* return 1 if the connections_number is not valid.
@@ -90,7 +90,7 @@ static bool connections_number_not_valid(const TCP_Connections *tcp_c, int conne
90 return 1; 90 return 1;
91 } 91 }
92 92
93 if (tcp_c->connections == NULL) { 93 if (tcp_c->connections == nullptr) {
94 return 1; 94 return 1;
95 } 95 }
96 96
@@ -110,7 +110,7 @@ static bool tcp_connections_number_not_valid(const TCP_Connections *tcp_c, int t
110 return 1; 110 return 1;
111 } 111 }
112 112
113 if (tcp_c->tcp_connections == NULL) { 113 if (tcp_c->tcp_connections == nullptr) {
114 return 1; 114 return 1;
115 } 115 }
116 116
@@ -239,7 +239,7 @@ static int wipe_tcp_connection(TCP_Connections *tcp_c, int tcp_connections_numbe
239static TCP_Connection_to *get_connection(const TCP_Connections *tcp_c, int connections_number) 239static TCP_Connection_to *get_connection(const TCP_Connections *tcp_c, int connections_number)
240{ 240{
241 if (connections_number_not_valid(tcp_c, connections_number)) { 241 if (connections_number_not_valid(tcp_c, connections_number)) {
242 return 0; 242 return nullptr;
243 } 243 }
244 244
245 return &tcp_c->connections[connections_number]; 245 return &tcp_c->connections[connections_number];
@@ -248,7 +248,7 @@ static TCP_Connection_to *get_connection(const TCP_Connections *tcp_c, int conne
248static TCP_con *get_tcp_connection(const TCP_Connections *tcp_c, int tcp_connections_number) 248static TCP_con *get_tcp_connection(const TCP_Connections *tcp_c, int tcp_connections_number)
249{ 249{
250 if (tcp_connections_number_not_valid(tcp_c, tcp_connections_number)) { 250 if (tcp_connections_number_not_valid(tcp_c, tcp_connections_number)) {
251 return 0; 251 return nullptr;
252 } 252 }
253 253
254 return &tcp_c->tcp_connections[tcp_connections_number]; 254 return &tcp_c->tcp_connections[tcp_connections_number];
@@ -824,7 +824,7 @@ static int sleep_tcp_relay_connection(TCP_Connections *tcp_c, int tcp_connection
824 memcpy(tcp_con->relay_pk, tcp_con_public_key(tcp_con->connection), CRYPTO_PUBLIC_KEY_SIZE); 824 memcpy(tcp_con->relay_pk, tcp_con_public_key(tcp_con->connection), CRYPTO_PUBLIC_KEY_SIZE);
825 825
826 kill_TCP_connection(tcp_con->connection); 826 kill_TCP_connection(tcp_con->connection);
827 tcp_con->connection = NULL; 827 tcp_con->connection = nullptr;
828 828
829 unsigned int i; 829 unsigned int i;
830 830
@@ -922,7 +922,7 @@ static int tcp_response_callback(void *object, uint8_t connection_id, const uint
922 922
923 TCP_Connection_to *con_to = get_connection(tcp_c, connections_number); 923 TCP_Connection_to *con_to = get_connection(tcp_c, connections_number);
924 924
925 if (con_to == NULL) { 925 if (con_to == nullptr) {
926 return -1; 926 return -1;
927 } 927 }
928 928
@@ -1368,14 +1368,14 @@ int set_tcp_onion_status(TCP_Connections *tcp_c, bool status)
1368 */ 1368 */
1369TCP_Connections *new_tcp_connections(const uint8_t *secret_key, TCP_Proxy_Info *proxy_info) 1369TCP_Connections *new_tcp_connections(const uint8_t *secret_key, TCP_Proxy_Info *proxy_info)
1370{ 1370{
1371 if (secret_key == NULL) { 1371 if (secret_key == nullptr) {
1372 return NULL; 1372 return nullptr;
1373 } 1373 }
1374 1374
1375 TCP_Connections *temp = (TCP_Connections *)calloc(1, sizeof(TCP_Connections)); 1375 TCP_Connections *temp = (TCP_Connections *)calloc(1, sizeof(TCP_Connections));
1376 1376
1377 if (temp == NULL) { 1377 if (temp == nullptr) {
1378 return NULL; 1378 return nullptr;
1379 } 1379 }
1380 1380
1381 memcpy(temp->self_secret_key, secret_key, CRYPTO_SECRET_KEY_SIZE); 1381 memcpy(temp->self_secret_key, secret_key, CRYPTO_SECRET_KEY_SIZE);
@@ -1400,7 +1400,7 @@ static void do_tcp_conns(TCP_Connections *tcp_c, void *userdata)
1400 tcp_con = get_tcp_connection(tcp_c, i); 1400 tcp_con = get_tcp_connection(tcp_c, i);
1401 1401
1402 // Make sure the TCP connection wasn't dropped in any of the callbacks. 1402 // Make sure the TCP connection wasn't dropped in any of the callbacks.
1403 assert(tcp_con != NULL); 1403 assert(tcp_con != nullptr);
1404 1404
1405 if (tcp_con_status(tcp_con->connection) == TCP_CLIENT_DISCONNECTED) { 1405 if (tcp_con_status(tcp_con->connection) == TCP_CLIENT_DISCONNECTED) {
1406 if (tcp_con->status == TCP_CONN_CONNECTED) { 1406 if (tcp_con->status == TCP_CONN_CONNECTED) {
diff --git a/toxcore/TCP_server.c b/toxcore/TCP_server.c
index e86776e5..d5772cc1 100644
--- a/toxcore/TCP_server.c
+++ b/toxcore/TCP_server.c
@@ -111,7 +111,7 @@ static int realloc_connection(TCP_Server *TCP_server, uint32_t num)
111{ 111{
112 if (num == 0) { 112 if (num == 0) {
113 free(TCP_server->accepted_connection_array); 113 free(TCP_server->accepted_connection_array);
114 TCP_server->accepted_connection_array = NULL; 114 TCP_server->accepted_connection_array = nullptr;
115 TCP_server->size_accepted_connections = 0; 115 TCP_server->size_accepted_connections = 0;
116 return 0; 116 return 0;
117 } 117 }
@@ -124,7 +124,7 @@ static int realloc_connection(TCP_Server *TCP_server, uint32_t num)
124 TCP_server->accepted_connection_array, 124 TCP_server->accepted_connection_array,
125 num * sizeof(TCP_Secure_Connection)); 125 num * sizeof(TCP_Secure_Connection));
126 126
127 if (new_connections == NULL) { 127 if (new_connections == nullptr) {
128 return -1; 128 return -1;
129 } 129 }
130 130
@@ -403,7 +403,7 @@ static int send_pending_data(TCP_Secure_Connection *con)
403 con->priority_queue_start = p; 403 con->priority_queue_start = p;
404 404
405 if (!p) { 405 if (!p) {
406 con->priority_queue_end = NULL; 406 con->priority_queue_end = nullptr;
407 return 0; 407 return 0;
408 } 408 }
409 409
@@ -422,7 +422,7 @@ static bool add_priority(TCP_Secure_Connection *con, const uint8_t *packet, uint
422 return 0; 422 return 0;
423 } 423 }
424 424
425 new_list->next = NULL; 425 new_list->next = nullptr;
426 new_list->size = size; 426 new_list->size = size;
427 new_list->sent = sent; 427 new_list->sent = sent;
428 memcpy(new_list->data, packet, size); 428 memcpy(new_list->data, packet, size);
@@ -1034,25 +1034,25 @@ static Socket new_listening_TCP_socket(int family, uint16_t port)
1034TCP_Server *new_TCP_server(uint8_t ipv6_enabled, uint16_t num_sockets, const uint16_t *ports, const uint8_t *secret_key, 1034TCP_Server *new_TCP_server(uint8_t ipv6_enabled, uint16_t num_sockets, const uint16_t *ports, const uint8_t *secret_key,
1035 Onion *onion) 1035 Onion *onion)
1036{ 1036{
1037 if (num_sockets == 0 || ports == NULL) { 1037 if (num_sockets == 0 || ports == nullptr) {
1038 return NULL; 1038 return nullptr;
1039 } 1039 }
1040 1040
1041 if (networking_at_startup() != 0) { 1041 if (networking_at_startup() != 0) {
1042 return NULL; 1042 return nullptr;
1043 } 1043 }
1044 1044
1045 TCP_Server *temp = (TCP_Server *)calloc(1, sizeof(TCP_Server)); 1045 TCP_Server *temp = (TCP_Server *)calloc(1, sizeof(TCP_Server));
1046 1046
1047 if (temp == NULL) { 1047 if (temp == nullptr) {
1048 return NULL; 1048 return nullptr;
1049 } 1049 }
1050 1050
1051 temp->socks_listening = (Socket *)calloc(num_sockets, sizeof(Socket)); 1051 temp->socks_listening = (Socket *)calloc(num_sockets, sizeof(Socket));
1052 1052
1053 if (temp->socks_listening == NULL) { 1053 if (temp->socks_listening == nullptr) {
1054 free(temp); 1054 free(temp);
1055 return NULL; 1055 return nullptr;
1056 } 1056 }
1057 1057
1058#ifdef TCP_SERVER_USE_EPOLL 1058#ifdef TCP_SERVER_USE_EPOLL
@@ -1061,7 +1061,7 @@ TCP_Server *new_TCP_server(uint8_t ipv6_enabled, uint16_t num_sockets, const uin
1061 if (temp->efd == -1) { 1061 if (temp->efd == -1) {
1062 free(temp->socks_listening); 1062 free(temp->socks_listening);
1063 free(temp); 1063 free(temp);
1064 return NULL; 1064 return nullptr;
1065 } 1065 }
1066 1066
1067#endif 1067#endif
@@ -1101,7 +1101,7 @@ TCP_Server *new_TCP_server(uint8_t ipv6_enabled, uint16_t num_sockets, const uin
1101 if (temp->num_listening_socks == 0) { 1101 if (temp->num_listening_socks == 0) {
1102 free(temp->socks_listening); 1102 free(temp->socks_listening);
1103 free(temp); 1103 free(temp);
1104 return NULL; 1104 return nullptr;
1105 } 1105 }
1106 1106
1107 if (onion) { 1107 if (onion) {
@@ -1429,7 +1429,7 @@ void kill_TCP_server(TCP_Server *TCP_server)
1429 } 1429 }
1430 1430
1431 if (TCP_server->onion) { 1431 if (TCP_server->onion) {
1432 set_callback_handle_recv_1(TCP_server->onion, NULL, NULL); 1432 set_callback_handle_recv_1(TCP_server->onion, nullptr, nullptr);
1433 } 1433 }
1434 1434
1435 bs_list_free(&TCP_server->accepted_key_list); 1435 bs_list_free(&TCP_server->accepted_key_list);
diff --git a/toxcore/ccompat.h b/toxcore/ccompat.h
index 05212ec5..dfbfe3eb 100644
--- a/toxcore/ccompat.h
+++ b/toxcore/ccompat.h
@@ -45,4 +45,8 @@
45 45
46#endif 46#endif
47 47
48#ifndef __cplusplus
49#define nullptr NULL
50#endif
51
48#endif /* CCOMPAT_H */ 52#endif /* CCOMPAT_H */
diff --git a/toxcore/friend_connection.c b/toxcore/friend_connection.c
index 2ebc0d9b..9381262b 100644
--- a/toxcore/friend_connection.c
+++ b/toxcore/friend_connection.c
@@ -97,7 +97,7 @@ static uint8_t friendconn_id_not_valid(const Friend_Connections *fr_c, int frien
97 return 1; 97 return 1;
98 } 98 }
99 99
100 if (fr_c->conns == NULL) { 100 if (fr_c->conns == nullptr) {
101 return 1; 101 return 1;
102 } 102 }
103 103
@@ -118,13 +118,13 @@ static int realloc_friendconns(Friend_Connections *fr_c, uint32_t num)
118{ 118{
119 if (num == 0) { 119 if (num == 0) {
120 free(fr_c->conns); 120 free(fr_c->conns);
121 fr_c->conns = NULL; 121 fr_c->conns = nullptr;
122 return 0; 122 return 0;
123 } 123 }
124 124
125 Friend_Conn *newgroup_cons = (Friend_Conn *)realloc(fr_c->conns, num * sizeof(Friend_Conn)); 125 Friend_Conn *newgroup_cons = (Friend_Conn *)realloc(fr_c->conns, num * sizeof(Friend_Conn));
126 126
127 if (newgroup_cons == NULL) { 127 if (newgroup_cons == nullptr) {
128 return -1; 128 return -1;
129 } 129 }
130 130
@@ -189,7 +189,7 @@ static int wipe_friend_conn(Friend_Connections *fr_c, int friendcon_id)
189static Friend_Conn *get_conn(const Friend_Connections *fr_c, int friendcon_id) 189static Friend_Conn *get_conn(const Friend_Connections *fr_c, int friendcon_id)
190{ 190{
191 if (friendconn_id_not_valid(fr_c, friendcon_id)) { 191 if (friendconn_id_not_valid(fr_c, friendcon_id)) {
192 return 0; 192 return nullptr;
193 } 193 }
194 194
195 return &fr_c->conns[friendcon_id]; 195 return &fr_c->conns[friendcon_id];
@@ -483,7 +483,7 @@ static int handle_packet(void *object, int number, const uint8_t *data, uint16_t
483 Node_format nodes[MAX_SHARED_RELAYS]; 483 Node_format nodes[MAX_SHARED_RELAYS];
484 int n; 484 int n;
485 485
486 if ((n = unpack_nodes(nodes, MAX_SHARED_RELAYS, NULL, data + 1, length - 1, 1)) == -1) { 486 if ((n = unpack_nodes(nodes, MAX_SHARED_RELAYS, nullptr, data + 1, length - 1, 1)) == -1) {
487 return -1; 487 return -1;
488 } 488 }
489 489
@@ -873,13 +873,13 @@ int send_friend_request_packet(Friend_Connections *fr_c, int friendcon_id, uint3
873Friend_Connections *new_friend_connections(Onion_Client *onion_c, bool local_discovery_enabled) 873Friend_Connections *new_friend_connections(Onion_Client *onion_c, bool local_discovery_enabled)
874{ 874{
875 if (!onion_c) { 875 if (!onion_c) {
876 return NULL; 876 return nullptr;
877 } 877 }
878 878
879 Friend_Connections *temp = (Friend_Connections *)calloc(1, sizeof(Friend_Connections)); 879 Friend_Connections *temp = (Friend_Connections *)calloc(1, sizeof(Friend_Connections));
880 880
881 if (temp == NULL) { 881 if (temp == nullptr) {
882 return NULL; 882 return nullptr;
883 } 883 }
884 884
885 temp->dht = onion_get_dht(onion_c); 885 temp->dht = onion_get_dht(onion_c);
diff --git a/toxcore/group.c b/toxcore/group.c
index 2186aa73..c929d995 100644
--- a/toxcore/group.c
+++ b/toxcore/group.c
@@ -38,7 +38,7 @@ static uint8_t groupnumber_not_valid(const Group_Chats *g_c, int groupnumber)
38 return 1; 38 return 1;
39 } 39 }
40 40
41 if (g_c->chats == NULL) { 41 if (g_c->chats == nullptr) {
42 return 1; 42 return 1;
43 } 43 }
44 44
@@ -59,13 +59,13 @@ static int realloc_groupchats(Group_Chats *g_c, uint32_t num)
59{ 59{
60 if (num == 0) { 60 if (num == 0) {
61 free(g_c->chats); 61 free(g_c->chats);
62 g_c->chats = NULL; 62 g_c->chats = nullptr;
63 return 0; 63 return 0;
64 } 64 }
65 65
66 Group_c *newgroup_chats = (Group_c *)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 == nullptr) {
69 return -1; 69 return -1;
70 } 70 }
71 71
@@ -132,7 +132,7 @@ static int wipe_group_chat(Group_Chats *g_c, int groupnumber)
132static Group_c *get_group_c(const Group_Chats *g_c, int groupnumber) 132static Group_c *get_group_c(const Group_Chats *g_c, int groupnumber)
133{ 133{
134 if (groupnumber_not_valid(g_c, groupnumber)) { 134 if (groupnumber_not_valid(g_c, groupnumber)) {
135 return 0; 135 return nullptr;
136 } 136 }
137 137
138 return &g_c->chats[groupnumber]; 138 return &g_c->chats[groupnumber];
@@ -438,7 +438,7 @@ static int addpeer(Group_Chats *g_c, int groupnumber, const uint8_t *real_pk, co
438 438
439 Group_Peer *temp = (Group_Peer *)realloc(g->group, sizeof(Group_Peer) * (g->numpeers + 1)); 439 Group_Peer *temp = (Group_Peer *)realloc(g->group, sizeof(Group_Peer) * (g->numpeers + 1));
440 440
441 if (temp == NULL) { 441 if (temp == nullptr) {
442 return -1; 442 return -1;
443 } 443 }
444 444
@@ -527,7 +527,7 @@ static int delpeer(Group_Chats *g_c, int groupnumber, int peer_index, void *user
527 527
528 if (g->numpeers == 0) { 528 if (g->numpeers == 0) {
529 free(g->group); 529 free(g->group);
530 g->group = NULL; 530 g->group = nullptr;
531 } else { 531 } else {
532 if (g->numpeers != (uint32_t)peer_index) { 532 if (g->numpeers != (uint32_t)peer_index) {
533 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));
@@ -535,7 +535,7 @@ static int delpeer(Group_Chats *g_c, int groupnumber, int peer_index, void *user
535 535
536 Group_Peer *temp = (Group_Peer *)realloc(g->group, sizeof(Group_Peer) * (g->numpeers)); 536 Group_Peer *temp = (Group_Peer *)realloc(g->group, sizeof(Group_Peer) * (g->numpeers));
537 537
538 if (temp == NULL) { 538 if (temp == nullptr) {
539 return -1; 539 return -1;
540 } 540 }
541 541
@@ -744,13 +744,13 @@ int add_groupchat(Group_Chats *g_c, uint8_t type)
744 g->identifier[0] = type; 744 g->identifier[0] = type;
745 g->peer_number = 0; /* Founder is peer 0. */ 745 g->peer_number = 0; /* Founder is peer 0. */
746 memcpy(g->real_pk, nc_get_self_public_key(g_c->m->net_crypto), CRYPTO_PUBLIC_KEY_SIZE); 746 memcpy(g->real_pk, nc_get_self_public_key(g_c->m->net_crypto), CRYPTO_PUBLIC_KEY_SIZE);
747 int peer_index = addpeer(g_c, groupnumber, g->real_pk, dht_get_self_public_key(g_c->m->dht), 0, NULL, false); 747 int peer_index = addpeer(g_c, groupnumber, g->real_pk, dht_get_self_public_key(g_c->m->dht), 0, nullptr, false);
748 748
749 if (peer_index == -1) { 749 if (peer_index == -1) {
750 return -1; 750 return -1;
751 } 751 }
752 752
753 setnick(g_c, groupnumber, peer_index, g_c->m->name, g_c->m->name_length, NULL, false); 753 setnick(g_c, groupnumber, peer_index, g_c->m->name, g_c->m->name_length, nullptr, false);
754 754
755 return groupnumber; 755 return groupnumber;
756} 756}
@@ -1223,7 +1223,7 @@ static int send_message_group(const Group_Chats *g_c, int groupnumber, uint8_t m
1223#define GROUP_MESSAGE_PING_ID 0 1223#define GROUP_MESSAGE_PING_ID 0
1224static int group_ping_send(const Group_Chats *g_c, int groupnumber) 1224static int group_ping_send(const Group_Chats *g_c, int groupnumber)
1225{ 1225{
1226 if (send_message_group(g_c, groupnumber, GROUP_MESSAGE_PING_ID, 0, 0) > 0) { 1226 if (send_message_group(g_c, groupnumber, GROUP_MESSAGE_PING_ID, nullptr, 0) > 0) {
1227 return 0; 1227 return 0;
1228 } 1228 }
1229 1229
@@ -2349,7 +2349,7 @@ void *group_get_object(const Group_Chats *g_c, int groupnumber)
2349 Group_c *g = get_group_c(g_c, groupnumber); 2349 Group_c *g = get_group_c(g_c, groupnumber);
2350 2350
2351 if (!g) { 2351 if (!g) {
2352 return NULL; 2352 return nullptr;
2353 } 2353 }
2354 2354
2355 return g->object; 2355 return g->object;
@@ -2365,11 +2365,11 @@ void *group_peer_get_object(const Group_Chats *g_c, int groupnumber, int peernum
2365 Group_c *g = get_group_c(g_c, groupnumber); 2365 Group_c *g = get_group_c(g_c, groupnumber);
2366 2366
2367 if (!g) { 2367 if (!g) {
2368 return NULL; 2368 return nullptr;
2369 } 2369 }
2370 2370
2371 if ((uint32_t)peernumber >= g->numpeers) { 2371 if ((uint32_t)peernumber >= g->numpeers) {
2372 return NULL; 2372 return nullptr;
2373 } 2373 }
2374 2374
2375 return g->group[peernumber].object; 2375 return g->group[peernumber].object;
@@ -2410,7 +2410,7 @@ static int groupchat_clear_timedout(Group_Chats *g_c, int groupnumber, void *use
2410 delpeer(g_c, groupnumber, i, userdata); 2410 delpeer(g_c, groupnumber, i, userdata);
2411 } 2411 }
2412 2412
2413 if (g->group == NULL || i >= g->numpeers) { 2413 if (g->group == nullptr || i >= g->numpeers) {
2414 break; 2414 break;
2415 } 2415 }
2416 } 2416 }
@@ -2441,13 +2441,13 @@ void send_name_all_groups(Group_Chats *g_c)
2441Group_Chats *new_groupchats(Messenger *m) 2441Group_Chats *new_groupchats(Messenger *m)
2442{ 2442{
2443 if (!m) { 2443 if (!m) {
2444 return NULL; 2444 return nullptr;
2445 } 2445 }
2446 2446
2447 Group_Chats *temp = (Group_Chats *)calloc(1, sizeof(Group_Chats)); 2447 Group_Chats *temp = (Group_Chats *)calloc(1, sizeof(Group_Chats));
2448 2448
2449 if (temp == NULL) { 2449 if (temp == nullptr) {
2450 return NULL; 2450 return nullptr;
2451 } 2451 }
2452 2452
2453 temp->m = m; 2453 temp->m = m;
@@ -2489,8 +2489,8 @@ void kill_groupchats(Group_Chats *g_c)
2489 del_groupchat(g_c, i); 2489 del_groupchat(g_c, i);
2490 } 2490 }
2491 2491
2492 m_callback_conference_invite(g_c->m, NULL); 2492 m_callback_conference_invite(g_c->m, nullptr);
2493 g_c->m->conferences_object = NULL; 2493 g_c->m->conferences_object = nullptr;
2494 free(g_c); 2494 free(g_c);
2495} 2495}
2496 2496
diff --git a/toxcore/list.c b/toxcore/list.c
index 36d609fb..8fd1f5fb 100644
--- a/toxcore/list.c
+++ b/toxcore/list.c
@@ -29,6 +29,8 @@
29 29
30#include "list.h" 30#include "list.h"
31 31
32#include "ccompat.h"
33
32/* Basically, the elements in the list are placed in order so that they can be searched for easily 34/* Basically, the elements in the list are placed in order so that they can be searched for easily
33 * -each element is seen as a big-endian integer when ordering them 35 * -each element is seen as a big-endian integer when ordering them
34 * -the ids array is maintained so that each id always matches 36 * -the ids array is maintained so that each id always matches
@@ -148,8 +150,8 @@ int bs_list_init(BS_LIST *list, uint32_t element_size, uint32_t initial_capacity
148 list->n = 0; 150 list->n = 0;
149 list->element_size = element_size; 151 list->element_size = element_size;
150 list->capacity = 0; 152 list->capacity = 0;
151 list->data = NULL; 153 list->data = nullptr;
152 list->ids = NULL; 154 list->ids = nullptr;
153 155
154 if (initial_capacity != 0) { 156 if (initial_capacity != 0) {
155 if (!resize(list, initial_capacity)) { 157 if (!resize(list, initial_capacity)) {
@@ -166,10 +168,10 @@ void bs_list_free(BS_LIST *list)
166{ 168{
167 //free both arrays 169 //free both arrays
168 free(list->data); 170 free(list->data);
169 list->data = NULL; 171 list->data = nullptr;
170 172
171 free(list->ids); 173 free(list->ids);
172 list->ids = NULL; 174 list->ids = nullptr;
173} 175}
174 176
175int bs_list_find(const BS_LIST *list, const uint8_t *data) 177int bs_list_find(const BS_LIST *list, const uint8_t *data)
diff --git a/toxcore/net_crypto.c b/toxcore/net_crypto.c
index f03ddb87..5027ce25 100644
--- a/toxcore/net_crypto.c
+++ b/toxcore/net_crypto.c
@@ -180,7 +180,7 @@ static uint8_t crypt_connection_id_not_valid(const Net_Crypto *c, int crypt_conn
180 return 1; 180 return 1;
181 } 181 }
182 182
183 if (c->crypto_connections == NULL) { 183 if (c->crypto_connections == nullptr) {
184 return 1; 184 return 1;
185 } 185 }
186 186
@@ -551,7 +551,7 @@ static int handle_crypto_handshake(const Net_Crypto *c, uint8_t *nonce, uint8_t
551static Crypto_Connection *get_crypto_connection(const Net_Crypto *c, int crypt_connection_id) 551static Crypto_Connection *get_crypto_connection(const Net_Crypto *c, int crypt_connection_id)
552{ 552{
553 if (crypt_connection_id_not_valid(c, crypt_connection_id)) { 553 if (crypt_connection_id_not_valid(c, crypt_connection_id)) {
554 return 0; 554 return nullptr;
555 } 555 }
556 556
557 return &c->crypto_connections[crypt_connection_id]; 557 return &c->crypto_connections[crypt_connection_id];
@@ -567,7 +567,7 @@ static int add_ip_port_connection(Net_Crypto *c, int crypt_connection_id, IP_Por
567{ 567{
568 Crypto_Connection *conn = get_crypto_connection(c, crypt_connection_id); 568 Crypto_Connection *conn = get_crypto_connection(c, crypt_connection_id);
569 569
570 if (conn == 0) { 570 if (conn == nullptr) {
571 return -1; 571 return -1;
572 } 572 }
573 573
@@ -607,7 +607,7 @@ static IP_Port return_ip_port_connection(Net_Crypto *c, int crypt_connection_id)
607 607
608 Crypto_Connection *conn = get_crypto_connection(c, crypt_connection_id); 608 Crypto_Connection *conn = get_crypto_connection(c, crypt_connection_id);
609 609
610 if (conn == 0) { 610 if (conn == nullptr) {
611 return empty; 611 return empty;
612 } 612 }
613 613
@@ -647,7 +647,7 @@ static int send_packet_to(Net_Crypto *c, int crypt_connection_id, const uint8_t
647// TODO(irungentoo): TCP, etc... 647// TODO(irungentoo): TCP, etc...
648 Crypto_Connection *conn = get_crypto_connection(c, crypt_connection_id); 648 Crypto_Connection *conn = get_crypto_connection(c, crypt_connection_id);
649 649
650 if (conn == 0) { 650 if (conn == nullptr) {
651 return -1; 651 return -1;
652 } 652 }
653 653
@@ -659,7 +659,7 @@ static int send_packet_to(Net_Crypto *c, int crypt_connection_id, const uint8_t
659 // TODO(irungentoo): on bad networks, direct connections might not last indefinitely. 659 // TODO(irungentoo): on bad networks, direct connections might not last indefinitely.
660 if (ip_port.ip.family != 0) { 660 if (ip_port.ip.family != 0) {
661 bool direct_connected = 0; 661 bool direct_connected = 0;
662 crypto_connection_status(c, crypt_connection_id, &direct_connected, NULL); 662 crypto_connection_status(c, crypt_connection_id, &direct_connected, nullptr);
663 663
664 if (direct_connected) { 664 if (direct_connected) {
665 if ((uint32_t)sendpacket(dht_get_net(c->dht), ip_port, data, length) == length) { 665 if ((uint32_t)sendpacket(dht_get_net(c->dht), ip_port, data, length) == length) {
@@ -733,7 +733,7 @@ static int add_data_to_buffer(Packets_Array *array, uint32_t number, const Packe
733 733
734 Packet_Data *new_d = (Packet_Data *)malloc(sizeof(Packet_Data)); 734 Packet_Data *new_d = (Packet_Data *)malloc(sizeof(Packet_Data));
735 735
736 if (new_d == NULL) { 736 if (new_d == nullptr) {
737 return -1; 737 return -1;
738 } 738 }
739 739
@@ -784,7 +784,7 @@ static int64_t add_data_end_of_buffer(Packets_Array *array, const Packet_Data *d
784 784
785 Packet_Data *new_d = (Packet_Data *)malloc(sizeof(Packet_Data)); 785 Packet_Data *new_d = (Packet_Data *)malloc(sizeof(Packet_Data));
786 786
787 if (new_d == NULL) { 787 if (new_d == nullptr) {
788 return -1; 788 return -1;
789 } 789 }
790 790
@@ -816,7 +816,7 @@ static int64_t read_data_beg_buffer(Packets_Array *array, Packet_Data *data)
816 uint32_t id = array->buffer_start; 816 uint32_t id = array->buffer_start;
817 ++array->buffer_start; 817 ++array->buffer_start;
818 free(array->buffer[num]); 818 free(array->buffer[num]);
819 array->buffer[num] = NULL; 819 array->buffer[num] = nullptr;
820 return id; 820 return id;
821} 821}
822 822
@@ -840,7 +840,7 @@ static int clear_buffer_until(Packets_Array *array, uint32_t number)
840 840
841 if (array->buffer[num]) { 841 if (array->buffer[num]) {
842 free(array->buffer[num]); 842 free(array->buffer[num]);
843 array->buffer[num] = NULL; 843 array->buffer[num] = nullptr;
844 } 844 }
845 } 845 }
846 846
@@ -857,7 +857,7 @@ static int clear_buffer(Packets_Array *array)
857 857
858 if (array->buffer[num]) { 858 if (array->buffer[num]) {
859 free(array->buffer[num]); 859 free(array->buffer[num]);
860 array->buffer[num] = NULL; 860 array->buffer[num] = nullptr;
861 } 861 }
862 } 862 }
863 863
@@ -996,7 +996,7 @@ static int handle_request_packet(Packets_Array *send_array, const uint8_t *data,
996 } 996 }
997 997
998 free(send_array->buffer[num]); 998 free(send_array->buffer[num]);
999 send_array->buffer[num] = NULL; 999 send_array->buffer[num] = nullptr;
1000 } 1000 }
1001 } 1001 }
1002 1002
@@ -1038,7 +1038,7 @@ static int send_data_packet(Net_Crypto *c, int crypt_connection_id, const uint8_
1038 1038
1039 Crypto_Connection *conn = get_crypto_connection(c, crypt_connection_id); 1039 Crypto_Connection *conn = get_crypto_connection(c, crypt_connection_id);
1040 1040
1041 if (conn == 0) { 1041 if (conn == nullptr) {
1042 return -1; 1042 return -1;
1043 } 1043 }
1044 1044
@@ -1087,14 +1087,14 @@ static int reset_max_speed_reached(Net_Crypto *c, int crypt_connection_id)
1087{ 1087{
1088 Crypto_Connection *conn = get_crypto_connection(c, crypt_connection_id); 1088 Crypto_Connection *conn = get_crypto_connection(c, crypt_connection_id);
1089 1089
1090 if (conn == 0) { 1090 if (conn == nullptr) {
1091 return -1; 1091 return -1;
1092 } 1092 }
1093 1093
1094 /* If last packet send failed, try to send packet again. 1094 /* If last packet send failed, try to send packet again.
1095 If sending it fails we won't be able to send the new packet. */ 1095 If sending it fails we won't be able to send the new packet. */
1096 if (conn->maximum_speed_reached) { 1096 if (conn->maximum_speed_reached) {
1097 Packet_Data *dt = NULL; 1097 Packet_Data *dt = nullptr;
1098 uint32_t packet_num = conn->send_array.buffer_end - 1; 1098 uint32_t packet_num = conn->send_array.buffer_end - 1;
1099 int ret = get_data_pointer(&conn->send_array, &dt, packet_num); 1099 int ret = get_data_pointer(&conn->send_array, &dt, packet_num);
1100 1100
@@ -1133,7 +1133,7 @@ static int64_t send_lossless_packet(Net_Crypto *c, int crypt_connection_id, cons
1133 1133
1134 Crypto_Connection *conn = get_crypto_connection(c, crypt_connection_id); 1134 Crypto_Connection *conn = get_crypto_connection(c, crypt_connection_id);
1135 1135
1136 if (conn == 0) { 1136 if (conn == nullptr) {
1137 return -1; 1137 return -1;
1138 } 1138 }
1139 1139
@@ -1162,7 +1162,7 @@ static int64_t send_lossless_packet(Net_Crypto *c, int crypt_connection_id, cons
1162 } 1162 }
1163 1163
1164 if (send_data_packet_helper(c, crypt_connection_id, conn->recv_array.buffer_start, packet_num, data, length) == 0) { 1164 if (send_data_packet_helper(c, crypt_connection_id, conn->recv_array.buffer_start, packet_num, data, length) == 0) {
1165 Packet_Data *dt1 = NULL; 1165 Packet_Data *dt1 = nullptr;
1166 1166
1167 if (get_data_pointer(&conn->send_array, &dt1, packet_num) == 1) { 1167 if (get_data_pointer(&conn->send_array, &dt1, packet_num) == 1) {
1168 dt1->sent_time = current_time_monotonic(); 1168 dt1->sent_time = current_time_monotonic();
@@ -1203,7 +1203,7 @@ static int handle_data_packet(const Net_Crypto *c, int crypt_connection_id, uint
1203 1203
1204 Crypto_Connection *conn = get_crypto_connection(c, crypt_connection_id); 1204 Crypto_Connection *conn = get_crypto_connection(c, crypt_connection_id);
1205 1205
1206 if (conn == 0) { 1206 if (conn == nullptr) {
1207 return -1; 1207 return -1;
1208 } 1208 }
1209 1209
@@ -1238,7 +1238,7 @@ static int send_request_packet(Net_Crypto *c, int crypt_connection_id)
1238{ 1238{
1239 Crypto_Connection *conn = get_crypto_connection(c, crypt_connection_id); 1239 Crypto_Connection *conn = get_crypto_connection(c, crypt_connection_id);
1240 1240
1241 if (conn == 0) { 1241 if (conn == nullptr) {
1242 return -1; 1242 return -1;
1243 } 1243 }
1244 1244
@@ -1266,7 +1266,7 @@ static int send_requested_packets(Net_Crypto *c, int crypt_connection_id, uint32
1266 1266
1267 Crypto_Connection *conn = get_crypto_connection(c, crypt_connection_id); 1267 Crypto_Connection *conn = get_crypto_connection(c, crypt_connection_id);
1268 1268
1269 if (conn == 0) { 1269 if (conn == nullptr) {
1270 return -1; 1270 return -1;
1271 } 1271 }
1272 1272
@@ -1318,13 +1318,13 @@ static int new_temp_packet(const Net_Crypto *c, int crypt_connection_id, const u
1318 1318
1319 Crypto_Connection *conn = get_crypto_connection(c, crypt_connection_id); 1319 Crypto_Connection *conn = get_crypto_connection(c, crypt_connection_id);
1320 1320
1321 if (conn == 0) { 1321 if (conn == nullptr) {
1322 return -1; 1322 return -1;
1323 } 1323 }
1324 1324
1325 uint8_t *temp_packet = (uint8_t *)malloc(length); 1325 uint8_t *temp_packet = (uint8_t *)malloc(length);
1326 1326
1327 if (temp_packet == 0) { 1327 if (temp_packet == nullptr) {
1328 return -1; 1328 return -1;
1329 } 1329 }
1330 1330
@@ -1349,7 +1349,7 @@ static int clear_temp_packet(const Net_Crypto *c, int crypt_connection_id)
1349{ 1349{
1350 Crypto_Connection *conn = get_crypto_connection(c, crypt_connection_id); 1350 Crypto_Connection *conn = get_crypto_connection(c, crypt_connection_id);
1351 1351
1352 if (conn == 0) { 1352 if (conn == nullptr) {
1353 return -1; 1353 return -1;
1354 } 1354 }
1355 1355
@@ -1357,7 +1357,7 @@ static int clear_temp_packet(const Net_Crypto *c, int crypt_connection_id)
1357 free(conn->temp_packet); 1357 free(conn->temp_packet);
1358 } 1358 }
1359 1359
1360 conn->temp_packet = 0; 1360 conn->temp_packet = nullptr;
1361 conn->temp_packet_length = 0; 1361 conn->temp_packet_length = 0;
1362 conn->temp_packet_sent_time = 0; 1362 conn->temp_packet_sent_time = 0;
1363 conn->temp_packet_num_sent = 0; 1363 conn->temp_packet_num_sent = 0;
@@ -1374,7 +1374,7 @@ static int send_temp_packet(Net_Crypto *c, int crypt_connection_id)
1374{ 1374{
1375 Crypto_Connection *conn = get_crypto_connection(c, crypt_connection_id); 1375 Crypto_Connection *conn = get_crypto_connection(c, crypt_connection_id);
1376 1376
1377 if (conn == 0) { 1377 if (conn == nullptr) {
1378 return -1; 1378 return -1;
1379 } 1379 }
1380 1380
@@ -1402,7 +1402,7 @@ static int create_send_handshake(Net_Crypto *c, int crypt_connection_id, const u
1402{ 1402{
1403 Crypto_Connection *conn = get_crypto_connection(c, crypt_connection_id); 1403 Crypto_Connection *conn = get_crypto_connection(c, crypt_connection_id);
1404 1404
1405 if (conn == 0) { 1405 if (conn == nullptr) {
1406 return -1; 1406 return -1;
1407 } 1407 }
1408 1408
@@ -1430,7 +1430,7 @@ static int send_kill_packet(Net_Crypto *c, int crypt_connection_id)
1430{ 1430{
1431 Crypto_Connection *conn = get_crypto_connection(c, crypt_connection_id); 1431 Crypto_Connection *conn = get_crypto_connection(c, crypt_connection_id);
1432 1432
1433 if (conn == 0) { 1433 if (conn == nullptr) {
1434 return -1; 1434 return -1;
1435 } 1435 }
1436 1436
@@ -1443,7 +1443,7 @@ static void connection_kill(Net_Crypto *c, int crypt_connection_id, void *userda
1443{ 1443{
1444 Crypto_Connection *conn = get_crypto_connection(c, crypt_connection_id); 1444 Crypto_Connection *conn = get_crypto_connection(c, crypt_connection_id);
1445 1445
1446 if (conn == 0) { 1446 if (conn == nullptr) {
1447 return; 1447 return;
1448 } 1448 }
1449 1449
@@ -1469,7 +1469,7 @@ static int handle_data_packet_core(Net_Crypto *c, int crypt_connection_id, const
1469 1469
1470 Crypto_Connection *conn = get_crypto_connection(c, crypt_connection_id); 1470 Crypto_Connection *conn = get_crypto_connection(c, crypt_connection_id);
1471 1471
1472 if (conn == 0) { 1472 if (conn == nullptr) {
1473 return -1; 1473 return -1;
1474 } 1474 }
1475 1475
@@ -1571,7 +1571,7 @@ static int handle_data_packet_core(Net_Crypto *c, int crypt_connection_id, const
1571 /* conn might get killed in callback. */ 1571 /* conn might get killed in callback. */
1572 conn = get_crypto_connection(c, crypt_connection_id); 1572 conn = get_crypto_connection(c, crypt_connection_id);
1573 1573
1574 if (conn == 0) { 1574 if (conn == nullptr) {
1575 return -1; 1575 return -1;
1576 } 1576 }
1577 } 1577 }
@@ -1616,7 +1616,7 @@ static int handle_packet_connection(Net_Crypto *c, int crypt_connection_id, cons
1616 1616
1617 Crypto_Connection *conn = get_crypto_connection(c, crypt_connection_id); 1617 Crypto_Connection *conn = get_crypto_connection(c, crypt_connection_id);
1618 1618
1619 if (conn == 0) { 1619 if (conn == nullptr) {
1620 return -1; 1620 return -1;
1621 } 1621 }
1622 1622
@@ -1702,14 +1702,14 @@ static int realloc_cryptoconnection(Net_Crypto *c, uint32_t num)
1702{ 1702{
1703 if (num == 0) { 1703 if (num == 0) {
1704 free(c->crypto_connections); 1704 free(c->crypto_connections);
1705 c->crypto_connections = NULL; 1705 c->crypto_connections = nullptr;
1706 return 0; 1706 return 0;
1707 } 1707 }
1708 1708
1709 Crypto_Connection *newcrypto_connections = (Crypto_Connection *)realloc(c->crypto_connections, 1709 Crypto_Connection *newcrypto_connections = (Crypto_Connection *)realloc(c->crypto_connections,
1710 num * sizeof(Crypto_Connection)); 1710 num * sizeof(Crypto_Connection));
1711 1711
1712 if (newcrypto_connections == NULL) { 1712 if (newcrypto_connections == nullptr) {
1713 return -1; 1713 return -1;
1714 } 1714 }
1715 1715
@@ -1756,7 +1756,7 @@ static int create_crypto_connection(Net_Crypto *c)
1756 c->crypto_connections[id].packet_send_rate_requested = 0; 1756 c->crypto_connections[id].packet_send_rate_requested = 0;
1757 c->crypto_connections[id].last_packets_left_requested_rem = 0; 1757 c->crypto_connections[id].last_packets_left_requested_rem = 0;
1758 1758
1759 if (pthread_mutex_init(&c->crypto_connections[id].mutex, NULL) != 0) { 1759 if (pthread_mutex_init(&c->crypto_connections[id].mutex, nullptr) != 0) {
1760 pthread_mutex_unlock(&c->connections_mutex); 1760 pthread_mutex_unlock(&c->connections_mutex);
1761 return -1; 1761 return -1;
1762 } 1762 }
@@ -1831,7 +1831,7 @@ static int crypto_connection_add_source(Net_Crypto *c, int crypt_connection_id,
1831{ 1831{
1832 Crypto_Connection *conn = get_crypto_connection(c, crypt_connection_id); 1832 Crypto_Connection *conn = get_crypto_connection(c, crypt_connection_id);
1833 1833
1834 if (conn == 0) { 1834 if (conn == nullptr) {
1835 return -1; 1835 return -1;
1836 } 1836 }
1837 1837
@@ -1884,7 +1884,7 @@ static int handle_new_connection_handshake(Net_Crypto *c, IP_Port source, const
1884 New_Connection n_c; 1884 New_Connection n_c;
1885 n_c.cookie = (uint8_t *)malloc(COOKIE_LENGTH); 1885 n_c.cookie = (uint8_t *)malloc(COOKIE_LENGTH);
1886 1886
1887 if (n_c.cookie == NULL) { 1887 if (n_c.cookie == nullptr) {
1888 return -1; 1888 return -1;
1889 } 1889 }
1890 1890
@@ -1892,7 +1892,7 @@ static int handle_new_connection_handshake(Net_Crypto *c, IP_Port source, const
1892 n_c.cookie_length = COOKIE_LENGTH; 1892 n_c.cookie_length = COOKIE_LENGTH;
1893 1893
1894 if (handle_crypto_handshake(c, n_c.recv_nonce, n_c.peersessionpublic_key, n_c.public_key, n_c.dht_public_key, 1894 if (handle_crypto_handshake(c, n_c.recv_nonce, n_c.peersessionpublic_key, n_c.public_key, n_c.dht_public_key,
1895 n_c.cookie, data, length, 0) != 0) { 1895 n_c.cookie, data, length, nullptr) != 0) {
1896 free(n_c.cookie); 1896 free(n_c.cookie);
1897 return -1; 1897 return -1;
1898 } 1898 }
@@ -2009,7 +2009,7 @@ int new_crypto_connection(Net_Crypto *c, const uint8_t *real_public_key, const u
2009 2009
2010 Crypto_Connection *conn = &c->crypto_connections[crypt_connection_id]; 2010 Crypto_Connection *conn = &c->crypto_connections[crypt_connection_id];
2011 2011
2012 if (conn == 0) { 2012 if (conn == nullptr) {
2013 return -1; 2013 return -1;
2014 } 2014 }
2015 2015
@@ -2059,7 +2059,7 @@ int set_direct_ip_port(Net_Crypto *c, int crypt_connection_id, IP_Port ip_port,
2059{ 2059{
2060 Crypto_Connection *conn = get_crypto_connection(c, crypt_connection_id); 2060 Crypto_Connection *conn = get_crypto_connection(c, crypt_connection_id);
2061 2061
2062 if (conn == 0) { 2062 if (conn == nullptr) {
2063 return -1; 2063 return -1;
2064 } 2064 }
2065 2065
@@ -2095,7 +2095,7 @@ static int tcp_data_callback(void *object, int id, const uint8_t *data, uint16_t
2095 2095
2096 Crypto_Connection *conn = get_crypto_connection(c, id); 2096 Crypto_Connection *conn = get_crypto_connection(c, id);
2097 2097
2098 if (conn == 0) { 2098 if (conn == nullptr) {
2099 return -1; 2099 return -1;
2100 } 2100 }
2101 2101
@@ -2155,7 +2155,7 @@ int add_tcp_relay_peer(Net_Crypto *c, int crypt_connection_id, IP_Port ip_port,
2155{ 2155{
2156 Crypto_Connection *conn = get_crypto_connection(c, crypt_connection_id); 2156 Crypto_Connection *conn = get_crypto_connection(c, crypt_connection_id);
2157 2157
2158 if (conn == 0) { 2158 if (conn == nullptr) {
2159 return -1; 2159 return -1;
2160 } 2160 }
2161 2161
@@ -2239,13 +2239,13 @@ static void do_tcp(Net_Crypto *c, void *userdata)
2239 for (i = 0; i < c->crypto_connections_length; ++i) { 2239 for (i = 0; i < c->crypto_connections_length; ++i) {
2240 Crypto_Connection *conn = get_crypto_connection(c, i); 2240 Crypto_Connection *conn = get_crypto_connection(c, i);
2241 2241
2242 if (conn == 0) { 2242 if (conn == nullptr) {
2243 return; 2243 return;
2244 } 2244 }
2245 2245
2246 if (conn->status == CRYPTO_CONN_ESTABLISHED) { 2246 if (conn->status == CRYPTO_CONN_ESTABLISHED) {
2247 bool direct_connected = 0; 2247 bool direct_connected = 0;
2248 crypto_connection_status(c, i, &direct_connected, NULL); 2248 crypto_connection_status(c, i, &direct_connected, nullptr);
2249 2249
2250 if (direct_connected) { 2250 if (direct_connected) {
2251 pthread_mutex_lock(&c->tcp_mutex); 2251 pthread_mutex_lock(&c->tcp_mutex);
@@ -2275,7 +2275,7 @@ int connection_status_handler(const Net_Crypto *c, int crypt_connection_id,
2275{ 2275{
2276 Crypto_Connection *conn = get_crypto_connection(c, crypt_connection_id); 2276 Crypto_Connection *conn = get_crypto_connection(c, crypt_connection_id);
2277 2277
2278 if (conn == 0) { 2278 if (conn == nullptr) {
2279 return -1; 2279 return -1;
2280 } 2280 }
2281 2281
@@ -2298,7 +2298,7 @@ int connection_data_handler(const Net_Crypto *c, int crypt_connection_id, int (*
2298{ 2298{
2299 Crypto_Connection *conn = get_crypto_connection(c, crypt_connection_id); 2299 Crypto_Connection *conn = get_crypto_connection(c, crypt_connection_id);
2300 2300
2301 if (conn == 0) { 2301 if (conn == nullptr) {
2302 return -1; 2302 return -1;
2303 } 2303 }
2304 2304
@@ -2322,7 +2322,7 @@ int connection_lossy_data_handler(Net_Crypto *c, int crypt_connection_id,
2322{ 2322{
2323 Crypto_Connection *conn = get_crypto_connection(c, crypt_connection_id); 2323 Crypto_Connection *conn = get_crypto_connection(c, crypt_connection_id);
2324 2324
2325 if (conn == 0) { 2325 if (conn == nullptr) {
2326 return -1; 2326 return -1;
2327 } 2327 }
2328 2328
@@ -2348,7 +2348,7 @@ int nc_dht_pk_callback(Net_Crypto *c, int crypt_connection_id, void (*function)(
2348{ 2348{
2349 Crypto_Connection *conn = get_crypto_connection(c, crypt_connection_id); 2349 Crypto_Connection *conn = get_crypto_connection(c, crypt_connection_id);
2350 2350
2351 if (conn == 0) { 2351 if (conn == nullptr) {
2352 return -1; 2352 return -1;
2353 } 2353 }
2354 2354
@@ -2405,7 +2405,7 @@ static int udp_handle_packet(void *object, IP_Port source, const uint8_t *packet
2405 2405
2406 Crypto_Connection *conn = get_crypto_connection(c, crypt_connection_id); 2406 Crypto_Connection *conn = get_crypto_connection(c, crypt_connection_id);
2407 2407
2408 if (conn == 0) { 2408 if (conn == nullptr) {
2409 return -1; 2409 return -1;
2410 } 2410 }
2411 2411
@@ -2449,7 +2449,7 @@ static void send_crypto_packets(Net_Crypto *c)
2449 for (i = 0; i < c->crypto_connections_length; ++i) { 2449 for (i = 0; i < c->crypto_connections_length; ++i) {
2450 Crypto_Connection *conn = get_crypto_connection(c, i); 2450 Crypto_Connection *conn = get_crypto_connection(c, i);
2451 2451
2452 if (conn == 0) { 2452 if (conn == nullptr) {
2453 return; 2453 return;
2454 } 2454 }
2455 2455
@@ -2527,7 +2527,7 @@ static void send_crypto_packets(Net_Crypto *c)
2527 conn->last_num_packets_resent[n_p_pos] = packets_resent; 2527 conn->last_num_packets_resent[n_p_pos] = packets_resent;
2528 2528
2529 bool direct_connected = 0; 2529 bool direct_connected = 0;
2530 crypto_connection_status(c, i, &direct_connected, NULL); 2530 crypto_connection_status(c, i, &direct_connected, nullptr);
2531 2531
2532 if (direct_connected && conn->last_tcp_sent + CONGESTION_EVENT_TIMEOUT > temp_time) { 2532 if (direct_connected && conn->last_tcp_sent + CONGESTION_EVENT_TIMEOUT > temp_time) {
2533 /* When switching from TCP to UDP, don't change the packet send rate for CONGESTION_EVENT_TIMEOUT ms. */ 2533 /* When switching from TCP to UDP, don't change the packet send rate for CONGESTION_EVENT_TIMEOUT ms. */
@@ -2688,7 +2688,7 @@ uint32_t crypto_num_free_sendqueue_slots(const Net_Crypto *c, int crypt_connecti
2688{ 2688{
2689 Crypto_Connection *conn = get_crypto_connection(c, crypt_connection_id); 2689 Crypto_Connection *conn = get_crypto_connection(c, crypt_connection_id);
2690 2690
2691 if (conn == 0) { 2691 if (conn == nullptr) {
2692 return 0; 2692 return 0;
2693 } 2693 }
2694 2694
@@ -2725,7 +2725,7 @@ int64_t write_cryptpacket(Net_Crypto *c, int crypt_connection_id, const uint8_t
2725 2725
2726 Crypto_Connection *conn = get_crypto_connection(c, crypt_connection_id); 2726 Crypto_Connection *conn = get_crypto_connection(c, crypt_connection_id);
2727 2727
2728 if (conn == 0) { 2728 if (conn == nullptr) {
2729 return -1; 2729 return -1;
2730 } 2730 }
2731 2731
@@ -2763,7 +2763,7 @@ int cryptpacket_received(Net_Crypto *c, int crypt_connection_id, uint32_t packet
2763{ 2763{
2764 Crypto_Connection *conn = get_crypto_connection(c, crypt_connection_id); 2764 Crypto_Connection *conn = get_crypto_connection(c, crypt_connection_id);
2765 2765
2766 if (conn == 0) { 2766 if (conn == nullptr) {
2767 return -1; 2767 return -1;
2768 } 2768 }
2769 2769
@@ -2872,7 +2872,7 @@ unsigned int crypto_connection_status(const Net_Crypto *c, int crypt_connection_
2872{ 2872{
2873 Crypto_Connection *conn = get_crypto_connection(c, crypt_connection_id); 2873 Crypto_Connection *conn = get_crypto_connection(c, crypt_connection_id);
2874 2874
2875 if (conn == 0) { 2875 if (conn == nullptr) {
2876 return CRYPTO_CONN_NO_CONNECTION; 2876 return CRYPTO_CONN_NO_CONNECTION;
2877 } 2877 }
2878 2878
@@ -2929,33 +2929,33 @@ Net_Crypto *new_net_crypto(Logger *log, DHT *dht, TCP_Proxy_Info *proxy_info)
2929{ 2929{
2930 unix_time_update(); 2930 unix_time_update();
2931 2931
2932 if (dht == NULL) { 2932 if (dht == nullptr) {
2933 return NULL; 2933 return nullptr;
2934 } 2934 }
2935 2935
2936 Net_Crypto *temp = (Net_Crypto *)calloc(1, sizeof(Net_Crypto)); 2936 Net_Crypto *temp = (Net_Crypto *)calloc(1, sizeof(Net_Crypto));
2937 2937
2938 if (temp == NULL) { 2938 if (temp == nullptr) {
2939 return NULL; 2939 return nullptr;
2940 } 2940 }
2941 2941
2942 temp->log = log; 2942 temp->log = log;
2943 2943
2944 temp->tcp_c = new_tcp_connections(dht_get_self_secret_key(dht), proxy_info); 2944 temp->tcp_c = new_tcp_connections(dht_get_self_secret_key(dht), proxy_info);
2945 2945
2946 if (temp->tcp_c == NULL) { 2946 if (temp->tcp_c == nullptr) {
2947 free(temp); 2947 free(temp);
2948 return NULL; 2948 return nullptr;
2949 } 2949 }
2950 2950
2951 set_packet_tcp_connection_callback(temp->tcp_c, &tcp_data_callback, temp); 2951 set_packet_tcp_connection_callback(temp->tcp_c, &tcp_data_callback, temp);
2952 set_oob_packet_tcp_connection_callback(temp->tcp_c, &tcp_oob_callback, temp); 2952 set_oob_packet_tcp_connection_callback(temp->tcp_c, &tcp_oob_callback, temp);
2953 2953
2954 if (create_recursive_mutex(&temp->tcp_mutex) != 0 || 2954 if (create_recursive_mutex(&temp->tcp_mutex) != 0 ||
2955 pthread_mutex_init(&temp->connections_mutex, NULL) != 0) { 2955 pthread_mutex_init(&temp->connections_mutex, nullptr) != 0) {
2956 kill_tcp_connections(temp->tcp_c); 2956 kill_tcp_connections(temp->tcp_c);
2957 free(temp); 2957 free(temp);
2958 return NULL; 2958 return nullptr;
2959 } 2959 }
2960 2960
2961 temp->dht = dht; 2961 temp->dht = dht;
@@ -2983,7 +2983,7 @@ static void kill_timedout(Net_Crypto *c, void *userdata)
2983 for (i = 0; i < c->crypto_connections_length; ++i) { 2983 for (i = 0; i < c->crypto_connections_length; ++i) {
2984 Crypto_Connection *conn = get_crypto_connection(c, i); 2984 Crypto_Connection *conn = get_crypto_connection(c, i);
2985 2985
2986 if (conn == 0) { 2986 if (conn == nullptr) {
2987 return; 2987 return;
2988 } 2988 }
2989 2989
@@ -3039,10 +3039,10 @@ void kill_net_crypto(Net_Crypto *c)
3039 3039
3040 kill_tcp_connections(c->tcp_c); 3040 kill_tcp_connections(c->tcp_c);
3041 bs_list_free(&c->ip_port_list); 3041 bs_list_free(&c->ip_port_list);
3042 networking_registerhandler(dht_get_net(c->dht), NET_PACKET_COOKIE_REQUEST, NULL, NULL); 3042 networking_registerhandler(dht_get_net(c->dht), NET_PACKET_COOKIE_REQUEST, nullptr, nullptr);
3043 networking_registerhandler(dht_get_net(c->dht), NET_PACKET_COOKIE_RESPONSE, NULL, NULL); 3043 networking_registerhandler(dht_get_net(c->dht), NET_PACKET_COOKIE_RESPONSE, nullptr, nullptr);
3044 networking_registerhandler(dht_get_net(c->dht), NET_PACKET_CRYPTO_HS, NULL, NULL); 3044 networking_registerhandler(dht_get_net(c->dht), NET_PACKET_CRYPTO_HS, nullptr, nullptr);
3045 networking_registerhandler(dht_get_net(c->dht), NET_PACKET_CRYPTO_DATA, NULL, NULL); 3045 networking_registerhandler(dht_get_net(c->dht), NET_PACKET_CRYPTO_DATA, nullptr, nullptr);
3046 crypto_memzero(c, sizeof(Net_Crypto)); 3046 crypto_memzero(c, sizeof(Net_Crypto));
3047 free(c); 3047 free(c);
3048} 3048}
diff --git a/toxcore/network.c b/toxcore/network.c
index 56f9aea0..63784475 100644
--- a/toxcore/network.c
+++ b/toxcore/network.c
@@ -82,8 +82,8 @@ static const char *inet_ntop(Family family, const void *addr, char *buf, size_t
82 82
83 DWORD len = bufsize; 83 DWORD len = bufsize;
84 84
85 if (WSAAddressToString((LPSOCKADDR)&saddr, sizeof(saddr), NULL, buf, &len)) { 85 if (WSAAddressToString((LPSOCKADDR)&saddr, sizeof(saddr), nullptr, buf, &len)) {
86 return NULL; 86 return nullptr;
87 } 87 }
88 88
89 return buf; 89 return buf;
@@ -96,14 +96,14 @@ static const char *inet_ntop(Family family, const void *addr, char *buf, size_t
96 96
97 DWORD len = bufsize; 97 DWORD len = bufsize;
98 98
99 if (WSAAddressToString((LPSOCKADDR)&saddr, sizeof(saddr), NULL, buf, &len)) { 99 if (WSAAddressToString((LPSOCKADDR)&saddr, sizeof(saddr), nullptr, buf, &len)) {
100 return NULL; 100 return nullptr;
101 } 101 }
102 102
103 return buf; 103 return buf;
104 } 104 }
105 105
106 return NULL; 106 return nullptr;
107} 107}
108 108
109static int inet_pton(Family family, const char *addrString, void *addrbuf) 109static int inet_pton(Family family, const char *addrString, void *addrbuf)
@@ -114,7 +114,7 @@ static int inet_pton(Family family, const char *addrString, void *addrbuf)
114 114
115 INT len = sizeof(saddr); 115 INT len = sizeof(saddr);
116 116
117 if (WSAStringToAddress((LPTSTR)addrString, AF_INET, NULL, (LPSOCKADDR)&saddr, &len)) { 117 if (WSAStringToAddress((LPTSTR)addrString, AF_INET, nullptr, (LPSOCKADDR)&saddr, &len)) {
118 return 0; 118 return 0;
119 } 119 }
120 120
@@ -127,7 +127,7 @@ static int inet_pton(Family family, const char *addrString, void *addrbuf)
127 127
128 INT len = sizeof(saddr); 128 INT len = sizeof(saddr);
129 129
130 if (WSAStringToAddress((LPTSTR)addrString, AF_INET6, NULL, (LPSOCKADDR)&saddr, &len)) { 130 if (WSAStringToAddress((LPTSTR)addrString, AF_INET6, nullptr, (LPSOCKADDR)&saddr, &len)) {
131 return 0; 131 return 0;
132 } 132 }
133 133
@@ -306,7 +306,7 @@ static uint64_t current_time_actual(void)
306 return time / 10; 306 return time / 10;
307#else 307#else
308 struct timeval a; 308 struct timeval a;
309 gettimeofday(&a, NULL); 309 gettimeofday(&a, nullptr);
310 time = 1000000ULL * a.tv_sec + a.tv_usec; 310 time = 1000000ULL * a.tv_sec + a.tv_usec;
311 return time; 311 return time;
312#endif 312#endif
@@ -624,7 +624,7 @@ static void at_shutdown(void)
624 */ 624 */
625Networking_Core *new_networking(Logger *log, IP ip, uint16_t port) 625Networking_Core *new_networking(Logger *log, IP ip, uint16_t port)
626{ 626{
627 return new_networking_ex(log, ip, port, port + (TOX_PORTRANGE_TO - TOX_PORTRANGE_FROM), 0); 627 return new_networking_ex(log, ip, port, port + (TOX_PORTRANGE_TO - TOX_PORTRANGE_FROM), nullptr);
628} 628}
629 629
630/* Initialize networking. 630/* Initialize networking.
@@ -663,17 +663,17 @@ Networking_Core *new_networking_ex(Logger *log, IP ip, uint16_t port_from, uint1
663 /* maybe check for invalid IPs like 224+.x.y.z? if there is any IP set ever */ 663 /* maybe check for invalid IPs like 224+.x.y.z? if there is any IP set ever */
664 if (ip.family != TOX_AF_INET && ip.family != TOX_AF_INET6) { 664 if (ip.family != TOX_AF_INET && ip.family != TOX_AF_INET6) {
665 LOGGER_ERROR(log, "Invalid address family: %u\n", ip.family); 665 LOGGER_ERROR(log, "Invalid address family: %u\n", ip.family);
666 return NULL; 666 return nullptr;
667 } 667 }
668 668
669 if (networking_at_startup() != 0) { 669 if (networking_at_startup() != 0) {
670 return NULL; 670 return nullptr;
671 } 671 }
672 672
673 Networking_Core *temp = (Networking_Core *)calloc(1, sizeof(Networking_Core)); 673 Networking_Core *temp = (Networking_Core *)calloc(1, sizeof(Networking_Core));
674 674
675 if (temp == NULL) { 675 if (temp == nullptr) {
676 return NULL; 676 return nullptr;
677 } 677 }
678 678
679 temp->log = log; 679 temp->log = log;
@@ -693,7 +693,7 @@ Networking_Core *new_networking_ex(Logger *log, IP ip, uint16_t port_from, uint1
693 *error = 1; 693 *error = 1;
694 } 694 }
695 695
696 return NULL; 696 return nullptr;
697 } 697 }
698 698
699 /* Functions to increase the size of the send and receive UDP buffers. 699 /* Functions to increase the size of the send and receive UDP buffers.
@@ -714,7 +714,7 @@ Networking_Core *new_networking_ex(Logger *log, IP ip, uint16_t port_from, uint1
714 *error = 1; 714 *error = 1;
715 } 715 }
716 716
717 return NULL; 717 return nullptr;
718 } 718 }
719 719
720 /* Set socket nonblocking. */ 720 /* Set socket nonblocking. */
@@ -725,11 +725,11 @@ Networking_Core *new_networking_ex(Logger *log, IP ip, uint16_t port_from, uint1
725 *error = 1; 725 *error = 1;
726 } 726 }
727 727
728 return NULL; 728 return nullptr;
729 } 729 }
730 730
731 /* Bind our socket to port PORT and the given IP address (usually 0.0.0.0 or ::) */ 731 /* Bind our socket to port PORT and the given IP address (usually 0.0.0.0 or ::) */
732 uint16_t *portptr = NULL; 732 uint16_t *portptr = nullptr;
733 struct sockaddr_storage addr; 733 struct sockaddr_storage addr;
734 size_t addrsize; 734 size_t addrsize;
735 735
@@ -758,7 +758,7 @@ Networking_Core *new_networking_ex(Logger *log, IP ip, uint16_t port_from, uint1
758 portptr = &addr6->sin6_port; 758 portptr = &addr6->sin6_port;
759 } else { 759 } else {
760 free(temp); 760 free(temp);
761 return NULL; 761 return nullptr;
762 } 762 }
763 763
764 if (ip.family == TOX_AF_INET6) { 764 if (ip.family == TOX_AF_INET6) {
@@ -841,7 +841,7 @@ Networking_Core *new_networking_ex(Logger *log, IP ip, uint16_t port_from, uint1
841 *error = 1; 841 *error = 1;
842 } 842 }
843 843
844 return NULL; 844 return nullptr;
845} 845}
846 846
847Networking_Core *new_networking_no_udp(Logger *log) 847Networking_Core *new_networking_no_udp(Logger *log)
@@ -849,8 +849,8 @@ Networking_Core *new_networking_no_udp(Logger *log)
849 /* this is the easiest way to completely disable UDP without changing too much code. */ 849 /* this is the easiest way to completely disable UDP without changing too much code. */
850 Networking_Core *net = (Networking_Core *)calloc(1, sizeof(Networking_Core)); 850 Networking_Core *net = (Networking_Core *)calloc(1, sizeof(Networking_Core));
851 851
852 if (net == NULL) { 852 if (net == nullptr) {
853 return NULL; 853 return nullptr;
854 } 854 }
855 855
856 net->log = log; 856 net->log = log;
@@ -1076,12 +1076,12 @@ int ip_parse_addr(const IP *ip, char *address, size_t length)
1076 1076
1077 if (ip->family == TOX_AF_INET) { 1077 if (ip->family == TOX_AF_INET) {
1078 const struct in_addr *addr = (const struct in_addr *)&ip->ip4; 1078 const struct in_addr *addr = (const struct in_addr *)&ip->ip4;
1079 return inet_ntop(ip->family, addr, address, length) != NULL; 1079 return inet_ntop(ip->family, addr, address, length) != nullptr;
1080 } 1080 }
1081 1081
1082 if (ip->family == TOX_AF_INET6) { 1082 if (ip->family == TOX_AF_INET6) {
1083 const struct in6_addr *addr = (const struct in6_addr *)&ip->ip6; 1083 const struct in6_addr *addr = (const struct in6_addr *)&ip->ip6;
1084 return inet_ntop(ip->family, addr, address, length) != NULL; 1084 return inet_ntop(ip->family, addr, address, length) != nullptr;
1085 } 1085 }
1086 1086
1087 return 0; 1087 return 0;
@@ -1151,8 +1151,8 @@ int addr_resolve(const char *address, IP *to, IP *extra)
1151 Family tox_family = to->family; 1151 Family tox_family = to->family;
1152 Family family = make_family(tox_family); 1152 Family family = make_family(tox_family);
1153 1153
1154 struct addrinfo *server = NULL; 1154 struct addrinfo *server = nullptr;
1155 struct addrinfo *walker = NULL; 1155 struct addrinfo *walker = nullptr;
1156 struct addrinfo hints; 1156 struct addrinfo hints;
1157 int rc; 1157 int rc;
1158 int result = 0; 1158 int result = 0;
@@ -1166,7 +1166,7 @@ int addr_resolve(const char *address, IP *to, IP *extra)
1166 return 0; 1166 return 0;
1167 } 1167 }
1168 1168
1169 rc = getaddrinfo(address, NULL, &hints, &server); 1169 rc = getaddrinfo(address, nullptr, &hints, &server);
1170 1170
1171 // Lookup failed. 1171 // Lookup failed.
1172 if (rc != 0) { 1172 if (rc != 0) {
@@ -1178,7 +1178,7 @@ int addr_resolve(const char *address, IP *to, IP *extra)
1178 IP ip6; 1178 IP ip6;
1179 ip_init(&ip6, 1); // ipv6enabled = 1 1179 ip_init(&ip6, 1); // ipv6enabled = 1
1180 1180
1181 for (walker = server; (walker != NULL) && !done; walker = walker->ai_next) { 1181 for (walker = server; (walker != nullptr) && !done; walker = walker->ai_next) {
1182 switch (walker->ai_family) { 1182 switch (walker->ai_family) {
1183 case AF_INET: 1183 case AF_INET:
1184 if (walker->ai_family == family) { /* AF_INET requested, done */ 1184 if (walker->ai_family == family) { /* AF_INET requested, done */
@@ -1218,7 +1218,7 @@ int addr_resolve(const char *address, IP *to, IP *extra)
1218 if (result & TOX_ADDR_RESOLVE_INET6) { 1218 if (result & TOX_ADDR_RESOLVE_INET6) {
1219 ip_copy(to, &ip6); 1219 ip_copy(to, &ip6);
1220 1220
1221 if ((result & TOX_ADDR_RESOLVE_INET) && (extra != NULL)) { 1221 if ((result & TOX_ADDR_RESOLVE_INET) && (extra != nullptr)) {
1222 ip_copy(extra, &ip4); 1222 ip_copy(extra, &ip4);
1223 } 1223 }
1224 } else if (result & TOX_ADDR_RESOLVE_INET) { 1224 } else if (result & TOX_ADDR_RESOLVE_INET) {
@@ -1287,8 +1287,8 @@ int net_connect(Socket sock, IP_Port ip_port)
1287int32_t net_getipport(const char *node, IP_Port **res, int tox_type) 1287int32_t net_getipport(const char *node, IP_Port **res, int tox_type)
1288{ 1288{
1289 struct addrinfo *infos; 1289 struct addrinfo *infos;
1290 int ret = getaddrinfo(node, NULL, NULL, &infos); 1290 int ret = getaddrinfo(node, nullptr, nullptr, &infos);
1291 *res = NULL; 1291 *res = nullptr;
1292 1292
1293 if (ret != 0) { 1293 if (ret != 0) {
1294 return -1; 1294 return -1;
@@ -1300,7 +1300,7 @@ int32_t net_getipport(const char *node, IP_Port **res, int tox_type)
1300 struct addrinfo *cur; 1300 struct addrinfo *cur;
1301 int32_t count = 0; 1301 int32_t count = 0;
1302 1302
1303 for (cur = infos; count < MAX_COUNT && cur != NULL; cur = cur->ai_next) { 1303 for (cur = infos; count < MAX_COUNT && cur != nullptr; cur = cur->ai_next) {
1304 if (cur->ai_socktype && type > 0 && cur->ai_socktype != type) { 1304 if (cur->ai_socktype && type > 0 && cur->ai_socktype != type) {
1305 continue; 1305 continue;
1306 } 1306 }
@@ -1321,14 +1321,14 @@ int32_t net_getipport(const char *node, IP_Port **res, int tox_type)
1321 1321
1322 *res = (IP_Port *)malloc(sizeof(IP_Port) * count); 1322 *res = (IP_Port *)malloc(sizeof(IP_Port) * count);
1323 1323
1324 if (*res == NULL) { 1324 if (*res == nullptr) {
1325 freeaddrinfo(infos); 1325 freeaddrinfo(infos);
1326 return -1; 1326 return -1;
1327 } 1327 }
1328 1328
1329 IP_Port *ip_port = *res; 1329 IP_Port *ip_port = *res;
1330 1330
1331 for (cur = infos; cur != NULL; cur = cur->ai_next) { 1331 for (cur = infos; cur != nullptr; cur = cur->ai_next) {
1332 if (cur->ai_socktype && type > 0 && cur->ai_socktype != type) { 1332 if (cur->ai_socktype && type > 0 && cur->ai_socktype != type) {
1333 continue; 1333 continue;
1334 } 1334 }
diff --git a/toxcore/network.h b/toxcore/network.h
index d3b80218..a698fdc9 100644
--- a/toxcore/network.h
+++ b/toxcore/network.h
@@ -125,17 +125,16 @@ typedef enum NET_PACKET_TYPE {
125#define TCP_INET6 (TOX_AF_INET6 + 3) 125#define TCP_INET6 (TOX_AF_INET6 + 3)
126#define TCP_FAMILY (TOX_AF_INET6 + 4) 126#define TCP_FAMILY (TOX_AF_INET6 + 4)
127 127
128typedef union { 128typedef union IP4 {
129 uint32_t uint32; 129 uint32_t uint32;
130 uint16_t uint16[2]; 130 uint16_t uint16[2];
131 uint8_t uint8[4]; 131 uint8_t uint8[4];
132} 132} IP4;
133IP4;
134 133
135IP4 get_ip4_loopback(void); 134IP4 get_ip4_loopback(void);
136extern const IP4 IP4_BROADCAST; 135extern const IP4 IP4_BROADCAST;
137 136
138typedef union { 137typedef union IP6 {
139 uint8_t uint8[16]; 138 uint8_t uint8[16];
140 uint16_t uint16[8]; 139 uint16_t uint16[8];
141 uint32_t uint32[4]; 140 uint32_t uint32[4];
@@ -146,7 +145,7 @@ IP6 get_ip6_loopback(void);
146extern const IP6 IP6_BROADCAST; 145extern const IP6 IP6_BROADCAST;
147 146
148#define IP_DEFINED 147#define IP_DEFINED
149typedef struct { 148typedef struct IP {
150 uint8_t family; 149 uint8_t family;
151 GNU_EXTENSION union { 150 GNU_EXTENSION union {
152 IP4 ip4; 151 IP4 ip4;
diff --git a/toxcore/onion.c b/toxcore/onion.c
index 2279d4e3..ffe99c2d 100644
--- a/toxcore/onion.c
+++ b/toxcore/onion.c
@@ -635,14 +635,14 @@ void set_callback_handle_recv_1(Onion *onion, int (*function)(void *, IP_Port, c
635 635
636Onion *new_onion(DHT *dht) 636Onion *new_onion(DHT *dht)
637{ 637{
638 if (dht == NULL) { 638 if (dht == nullptr) {
639 return NULL; 639 return nullptr;
640 } 640 }
641 641
642 Onion *onion = (Onion *)calloc(1, sizeof(Onion)); 642 Onion *onion = (Onion *)calloc(1, sizeof(Onion));
643 643
644 if (onion == NULL) { 644 if (onion == nullptr) {
645 return NULL; 645 return nullptr;
646 } 646 }
647 647
648 onion->dht = dht; 648 onion->dht = dht;
@@ -663,17 +663,17 @@ Onion *new_onion(DHT *dht)
663 663
664void kill_onion(Onion *onion) 664void kill_onion(Onion *onion)
665{ 665{
666 if (onion == NULL) { 666 if (onion == nullptr) {
667 return; 667 return;
668 } 668 }
669 669
670 networking_registerhandler(onion->net, NET_PACKET_ONION_SEND_INITIAL, NULL, NULL); 670 networking_registerhandler(onion->net, NET_PACKET_ONION_SEND_INITIAL, nullptr, nullptr);
671 networking_registerhandler(onion->net, NET_PACKET_ONION_SEND_1, NULL, NULL); 671 networking_registerhandler(onion->net, NET_PACKET_ONION_SEND_1, nullptr, nullptr);
672 networking_registerhandler(onion->net, NET_PACKET_ONION_SEND_2, NULL, NULL); 672 networking_registerhandler(onion->net, NET_PACKET_ONION_SEND_2, nullptr, nullptr);
673 673
674 networking_registerhandler(onion->net, NET_PACKET_ONION_RECV_3, NULL, NULL); 674 networking_registerhandler(onion->net, NET_PACKET_ONION_RECV_3, nullptr, nullptr);
675 networking_registerhandler(onion->net, NET_PACKET_ONION_RECV_2, NULL, NULL); 675 networking_registerhandler(onion->net, NET_PACKET_ONION_RECV_2, nullptr, nullptr);
676 networking_registerhandler(onion->net, NET_PACKET_ONION_RECV_1, NULL, NULL); 676 networking_registerhandler(onion->net, NET_PACKET_ONION_RECV_1, nullptr, nullptr);
677 677
678 free(onion); 678 free(onion);
679} 679}
diff --git a/toxcore/onion_announce.c b/toxcore/onion_announce.c
index 0ff22a3d..585e78a1 100644
--- a/toxcore/onion_announce.c
+++ b/toxcore/onion_announce.c
@@ -493,14 +493,14 @@ static int handle_data_request(void *object, IP_Port source, const uint8_t *pack
493 493
494Onion_Announce *new_onion_announce(DHT *dht) 494Onion_Announce *new_onion_announce(DHT *dht)
495{ 495{
496 if (dht == NULL) { 496 if (dht == nullptr) {
497 return NULL; 497 return nullptr;
498 } 498 }
499 499
500 Onion_Announce *onion_a = (Onion_Announce *)calloc(1, sizeof(Onion_Announce)); 500 Onion_Announce *onion_a = (Onion_Announce *)calloc(1, sizeof(Onion_Announce));
501 501
502 if (onion_a == NULL) { 502 if (onion_a == nullptr) {
503 return NULL; 503 return nullptr;
504 } 504 }
505 505
506 onion_a->dht = dht; 506 onion_a->dht = dht;
@@ -515,11 +515,11 @@ Onion_Announce *new_onion_announce(DHT *dht)
515 515
516void kill_onion_announce(Onion_Announce *onion_a) 516void kill_onion_announce(Onion_Announce *onion_a)
517{ 517{
518 if (onion_a == NULL) { 518 if (onion_a == nullptr) {
519 return; 519 return;
520 } 520 }
521 521
522 networking_registerhandler(onion_a->net, NET_PACKET_ANNOUNCE_REQUEST, NULL, NULL); 522 networking_registerhandler(onion_a->net, NET_PACKET_ANNOUNCE_REQUEST, nullptr, nullptr);
523 networking_registerhandler(onion_a->net, NET_PACKET_ONION_DATA_REQUEST, NULL, NULL); 523 networking_registerhandler(onion_a->net, NET_PACKET_ONION_DATA_REQUEST, nullptr, nullptr);
524 free(onion_a); 524 free(onion_a);
525} 525}
diff --git a/toxcore/onion_client.c b/toxcore/onion_client.c
index c652d7f3..4c5258e3 100644
--- a/toxcore/onion_client.c
+++ b/toxcore/onion_client.c
@@ -579,7 +579,7 @@ static int client_send_announce_request(Onion_Client *onion_c, uint32_t num, IP_
579 579
580 uint8_t zero_ping_id[ONION_PING_ID_SIZE] = {0}; 580 uint8_t zero_ping_id[ONION_PING_ID_SIZE] = {0};
581 581
582 if (ping_id == NULL) { 582 if (ping_id == nullptr) {
583 ping_id = zero_ping_id; 583 ping_id = zero_ping_id;
584 } 584 }
585 585
@@ -670,8 +670,8 @@ static int client_add_to_list(Onion_Client *onion_c, uint32_t num, const uint8_t
670 return -1; 670 return -1;
671 } 671 }
672 672
673 Onion_Node *list_nodes = NULL; 673 Onion_Node *list_nodes = nullptr;
674 const uint8_t *reference_id = NULL; 674 const uint8_t *reference_id = nullptr;
675 unsigned int list_length; 675 unsigned int list_length;
676 676
677 if (num == 0) { 677 if (num == 0) {
@@ -772,12 +772,12 @@ static int client_ping_nodes(Onion_Client *onion_c, uint32_t num, const Node_for
772 return 0; 772 return 0;
773 } 773 }
774 774
775 Onion_Node *list_nodes = NULL; 775 Onion_Node *list_nodes = nullptr;
776 const uint8_t *reference_id = NULL; 776 const uint8_t *reference_id = nullptr;
777 unsigned int list_length; 777 unsigned int list_length;
778 778
779 Last_Pinged *last_pinged = NULL; 779 Last_Pinged *last_pinged = nullptr;
780 uint8_t *last_pinged_index = NULL; 780 uint8_t *last_pinged_index = nullptr;
781 781
782 if (num == 0) { 782 if (num == 0) {
783 list_nodes = onion_c->clients_announce_list; 783 list_nodes = onion_c->clients_announce_list;
@@ -816,7 +816,7 @@ static int client_ping_nodes(Onion_Client *onion_c, uint32_t num, const Node_for
816 } 816 }
817 817
818 if (j == list_length && good_to_ping(last_pinged, last_pinged_index, nodes[i].public_key)) { 818 if (j == list_length && good_to_ping(last_pinged, last_pinged_index, nodes[i].public_key)) {
819 client_send_announce_request(onion_c, num, nodes[i].ip_port, nodes[i].public_key, NULL, ~0); 819 client_send_announce_request(onion_c, num, nodes[i].ip_port, nodes[i].public_key, nullptr, ~0);
820 } 820 }
821 } 821 }
822 } 822 }
@@ -875,7 +875,7 @@ static int handle_announce_response(void *object, IP_Port source, const uint8_t
875 875
876 if (len_nodes != 0) { 876 if (len_nodes != 0) {
877 Node_format nodes[MAX_SENT_NODES]; 877 Node_format nodes[MAX_SENT_NODES];
878 int num_nodes = unpack_nodes(nodes, MAX_SENT_NODES, 0, plain + 1 + ONION_PING_ID_SIZE, len_nodes, 0); 878 int num_nodes = unpack_nodes(nodes, MAX_SENT_NODES, nullptr, plain + 1 + ONION_PING_ID_SIZE, len_nodes, 0);
879 879
880 if (num_nodes <= 0) { 880 if (num_nodes <= 0) {
881 return 1; 881 return 1;
@@ -974,7 +974,7 @@ static int handle_dhtpk_announce(void *object, const uint8_t *source_pubkey, con
974 974
975 if (len_nodes != 0) { 975 if (len_nodes != 0) {
976 Node_format nodes[MAX_SENT_NODES]; 976 Node_format nodes[MAX_SENT_NODES];
977 int num_nodes = unpack_nodes(nodes, MAX_SENT_NODES, 0, data + 1 + sizeof(uint64_t) + CRYPTO_PUBLIC_KEY_SIZE, 977 int num_nodes = unpack_nodes(nodes, MAX_SENT_NODES, nullptr, data + 1 + sizeof(uint64_t) + CRYPTO_PUBLIC_KEY_SIZE,
978 len_nodes, 1); 978 len_nodes, 1);
979 979
980 if (num_nodes <= 0) { 980 if (num_nodes <= 0) {
@@ -1260,13 +1260,13 @@ static int realloc_onion_friends(Onion_Client *onion_c, uint32_t num)
1260{ 1260{
1261 if (num == 0) { 1261 if (num == 0) {
1262 free(onion_c->friends_list); 1262 free(onion_c->friends_list);
1263 onion_c->friends_list = NULL; 1263 onion_c->friends_list = nullptr;
1264 return 0; 1264 return 0;
1265 } 1265 }
1266 1266
1267 Onion_Friend *newonion_friends = (Onion_Friend *)realloc(onion_c->friends_list, num * sizeof(Onion_Friend)); 1267 Onion_Friend *newonion_friends = (Onion_Friend *)realloc(onion_c->friends_list, num * sizeof(Onion_Friend));
1268 1268
1269 if (newonion_friends == NULL) { 1269 if (newonion_friends == nullptr) {
1270 return -1; 1270 return -1;
1271 } 1271 }
1272 1272
@@ -1586,7 +1586,8 @@ static void do_friend(Onion_Client *onion_c, uint16_t friendnum)
1586 1586
1587 if (is_timeout(list_nodes[i].last_pinged, interval) 1587 if (is_timeout(list_nodes[i].last_pinged, interval)
1588 || (ping_random && rand() % (MAX_ONION_CLIENTS - i) == 0)) { 1588 || (ping_random && rand() % (MAX_ONION_CLIENTS - i) == 0)) {
1589 if (client_send_announce_request(onion_c, friendnum + 1, list_nodes[i].ip_port, list_nodes[i].public_key, 0, ~0) == 0) { 1589 if (client_send_announce_request(onion_c, friendnum + 1, list_nodes[i].ip_port,
1590 list_nodes[i].public_key, nullptr, ~0) == 0) {
1590 list_nodes[i].last_pinged = unix_time(); 1591 list_nodes[i].last_pinged = unix_time();
1591 ++list_nodes[i].unsuccessful_pings; 1592 ++list_nodes[i].unsuccessful_pings;
1592 ping_random = false; 1593 ping_random = false;
@@ -1610,7 +1611,7 @@ static void do_friend(Onion_Client *onion_c, uint16_t friendnum)
1610 for (j = 0; j < n; ++j) { 1611 for (j = 0; j < n; ++j) {
1611 unsigned int num = rand() % num_nodes; 1612 unsigned int num = rand() % num_nodes;
1612 client_send_announce_request(onion_c, friendnum + 1, onion_c->path_nodes[num].ip_port, 1613 client_send_announce_request(onion_c, friendnum + 1, onion_c->path_nodes[num].ip_port,
1613 onion_c->path_nodes[num].public_key, 0, ~0); 1614 onion_c->path_nodes[num].public_key, nullptr, ~0);
1614 } 1615 }
1615 1616
1616 ++onion_c->friends_list[friendnum].run_count; 1617 ++onion_c->friends_list[friendnum].run_count;
@@ -1729,7 +1730,7 @@ static void do_announce(Onion_Client *onion_c)
1729 if (num_nodes != 0) { 1730 if (num_nodes != 0) {
1730 for (i = 0; i < (MAX_ONION_CLIENTS_ANNOUNCE / 2); ++i) { 1731 for (i = 0; i < (MAX_ONION_CLIENTS_ANNOUNCE / 2); ++i) {
1731 unsigned int num = rand() % num_nodes; 1732 unsigned int num = rand() % num_nodes;
1732 client_send_announce_request(onion_c, 0, path_nodes[num].ip_port, path_nodes[num].public_key, 0, ~0); 1733 client_send_announce_request(onion_c, 0, path_nodes[num].ip_port, path_nodes[num].public_key, nullptr, ~0);
1733 } 1734 }
1734 } 1735 }
1735 } 1736 }
@@ -1846,21 +1847,21 @@ void do_onion_client(Onion_Client *onion_c)
1846 1847
1847Onion_Client *new_onion_client(Net_Crypto *c) 1848Onion_Client *new_onion_client(Net_Crypto *c)
1848{ 1849{
1849 if (c == NULL) { 1850 if (c == nullptr) {
1850 return NULL; 1851 return nullptr;
1851 } 1852 }
1852 1853
1853 Onion_Client *onion_c = (Onion_Client *)calloc(1, sizeof(Onion_Client)); 1854 Onion_Client *onion_c = (Onion_Client *)calloc(1, sizeof(Onion_Client));
1854 1855
1855 if (onion_c == NULL) { 1856 if (onion_c == nullptr) {
1856 return NULL; 1857 return nullptr;
1857 } 1858 }
1858 1859
1859 onion_c->announce_ping_array = ping_array_new(ANNOUNCE_ARRAY_SIZE, ANNOUNCE_TIMEOUT); 1860 onion_c->announce_ping_array = ping_array_new(ANNOUNCE_ARRAY_SIZE, ANNOUNCE_TIMEOUT);
1860 1861
1861 if (onion_c->announce_ping_array == NULL) { 1862 if (onion_c->announce_ping_array == nullptr) {
1862 free(onion_c); 1863 free(onion_c);
1863 return NULL; 1864 return nullptr;
1864 } 1865 }
1865 1866
1866 onion_c->dht = nc_get_dht(c); 1867 onion_c->dht = nc_get_dht(c);
@@ -1879,17 +1880,17 @@ Onion_Client *new_onion_client(Net_Crypto *c)
1879 1880
1880void kill_onion_client(Onion_Client *onion_c) 1881void kill_onion_client(Onion_Client *onion_c)
1881{ 1882{
1882 if (onion_c == NULL) { 1883 if (onion_c == nullptr) {
1883 return; 1884 return;
1884 } 1885 }
1885 1886
1886 ping_array_kill(onion_c->announce_ping_array); 1887 ping_array_kill(onion_c->announce_ping_array);
1887 realloc_onion_friends(onion_c, 0); 1888 realloc_onion_friends(onion_c, 0);
1888 networking_registerhandler(onion_c->net, NET_PACKET_ANNOUNCE_RESPONSE, NULL, NULL); 1889 networking_registerhandler(onion_c->net, NET_PACKET_ANNOUNCE_RESPONSE, nullptr, nullptr);
1889 networking_registerhandler(onion_c->net, NET_PACKET_ONION_DATA_RESPONSE, NULL, NULL); 1890 networking_registerhandler(onion_c->net, NET_PACKET_ONION_DATA_RESPONSE, nullptr, nullptr);
1890 oniondata_registerhandler(onion_c, ONION_DATA_DHTPK, NULL, NULL); 1891 oniondata_registerhandler(onion_c, ONION_DATA_DHTPK, nullptr, nullptr);
1891 cryptopacket_registerhandler(onion_c->dht, CRYPTO_PACKET_DHTPK, NULL, NULL); 1892 cryptopacket_registerhandler(onion_c->dht, CRYPTO_PACKET_DHTPK, nullptr, nullptr);
1892 set_onion_packet_tcp_connection_callback(nc_get_tcp_c(onion_c->c), NULL, NULL); 1893 set_onion_packet_tcp_connection_callback(nc_get_tcp_c(onion_c->c), nullptr, nullptr);
1893 crypto_memzero(onion_c, sizeof(Onion_Client)); 1894 crypto_memzero(onion_c, sizeof(Onion_Client));
1894 free(onion_c); 1895 free(onion_c);
1895} 1896}
diff --git a/toxcore/ping.c b/toxcore/ping.c
index 1e5892eb..bede07a1 100644
--- a/toxcore/ping.c
+++ b/toxcore/ping.c
@@ -355,15 +355,15 @@ Ping *ping_new(DHT *dht)
355{ 355{
356 Ping *ping = (Ping *)calloc(1, sizeof(Ping)); 356 Ping *ping = (Ping *)calloc(1, sizeof(Ping));
357 357
358 if (ping == NULL) { 358 if (ping == nullptr) {
359 return NULL; 359 return nullptr;
360 } 360 }
361 361
362 ping->ping_array = ping_array_new(PING_NUM_MAX, PING_TIMEOUT); 362 ping->ping_array = ping_array_new(PING_NUM_MAX, PING_TIMEOUT);
363 363
364 if (ping->ping_array == NULL) { 364 if (ping->ping_array == nullptr) {
365 free(ping); 365 free(ping);
366 return NULL; 366 return nullptr;
367 } 367 }
368 368
369 ping->dht = dht; 369 ping->dht = dht;
@@ -375,8 +375,8 @@ Ping *ping_new(DHT *dht)
375 375
376void ping_kill(Ping *ping) 376void ping_kill(Ping *ping)
377{ 377{
378 networking_registerhandler(dht_get_net(ping->dht), NET_PACKET_PING_REQUEST, NULL, NULL); 378 networking_registerhandler(dht_get_net(ping->dht), NET_PACKET_PING_REQUEST, nullptr, nullptr);
379 networking_registerhandler(dht_get_net(ping->dht), NET_PACKET_PING_RESPONSE, NULL, NULL); 379 networking_registerhandler(dht_get_net(ping->dht), NET_PACKET_PING_RESPONSE, nullptr, nullptr);
380 ping_array_kill(ping->ping_array); 380 ping_array_kill(ping->ping_array);
381 381
382 free(ping); 382 free(ping);
diff --git a/toxcore/ping_array.c b/toxcore/ping_array.c
index 627f8d5a..a54ebfe2 100644
--- a/toxcore/ping_array.c
+++ b/toxcore/ping_array.c
@@ -57,20 +57,20 @@ struct Ping_Array {
57Ping_Array *ping_array_new(uint32_t size, uint32_t timeout) 57Ping_Array *ping_array_new(uint32_t size, uint32_t timeout)
58{ 58{
59 if (size == 0 || timeout == 0) { 59 if (size == 0 || timeout == 0) {
60 return NULL; 60 return nullptr;
61 } 61 }
62 62
63 Ping_Array *empty_array = (Ping_Array *)calloc(1, sizeof(Ping_Array)); 63 Ping_Array *empty_array = (Ping_Array *)calloc(1, sizeof(Ping_Array));
64 64
65 if (empty_array == NULL) { 65 if (empty_array == nullptr) {
66 return NULL; 66 return nullptr;
67 } 67 }
68 68
69 empty_array->entries = (Ping_Array_Entry *)calloc(size, sizeof(Ping_Array_Entry)); 69 empty_array->entries = (Ping_Array_Entry *)calloc(size, sizeof(Ping_Array_Entry));
70 70
71 if (empty_array->entries == NULL) { 71 if (empty_array->entries == nullptr) {
72 free(empty_array); 72 free(empty_array);
73 return NULL; 73 return nullptr;
74 } 74 }
75 75
76 empty_array->last_deleted = empty_array->last_added = 0; 76 empty_array->last_deleted = empty_array->last_added = 0;
@@ -82,7 +82,7 @@ Ping_Array *ping_array_new(uint32_t size, uint32_t timeout)
82static void clear_entry(Ping_Array *array, uint32_t index) 82static void clear_entry(Ping_Array *array, uint32_t index)
83{ 83{
84 free(array->entries[index].data); 84 free(array->entries[index].data);
85 array->entries[index].data = NULL; 85 array->entries[index].data = nullptr;
86 array->entries[index].length = 86 array->entries[index].length =
87 array->entries[index].time = 87 array->entries[index].time =
88 array->entries[index].ping_id = 0; 88 array->entries[index].ping_id = 0;
@@ -128,14 +128,14 @@ uint64_t ping_array_add(Ping_Array *array, const uint8_t *data, uint32_t length)
128 ping_array_clear_timedout(array); 128 ping_array_clear_timedout(array);
129 uint32_t index = array->last_added % array->total_size; 129 uint32_t index = array->last_added % array->total_size;
130 130
131 if (array->entries[index].data != NULL) { 131 if (array->entries[index].data != nullptr) {
132 array->last_deleted = array->last_added - array->total_size; 132 array->last_deleted = array->last_added - array->total_size;
133 clear_entry(array, index); 133 clear_entry(array, index);
134 } 134 }
135 135
136 array->entries[index].data = malloc(length); 136 array->entries[index].data = malloc(length);
137 137
138 if (array->entries[index].data == NULL) { 138 if (array->entries[index].data == nullptr) {
139 return 0; 139 return 0;
140 } 140 }
141 141
@@ -184,7 +184,7 @@ int32_t ping_array_check(Ping_Array *array, uint8_t *data, size_t length, uint64
184 return -1; 184 return -1;
185 } 185 }
186 186
187 if (array->entries[index].data == NULL) { 187 if (array->entries[index].data == nullptr) {
188 return -1; 188 return -1;
189 } 189 }
190 190
diff --git a/toxcore/tox.c b/toxcore/tox.c
index 11967f84..7dd4a7b5 100644
--- a/toxcore/tox.c
+++ b/toxcore/tox.c
@@ -84,32 +84,32 @@ Tox *tox_new(const struct Tox_Options *options, TOX_ERR_NEW *error)
84 84
85 bool load_savedata_sk = 0, load_savedata_tox = 0; 85 bool load_savedata_sk = 0, load_savedata_tox = 0;
86 86
87 if (options == NULL) { 87 if (options == nullptr) {
88 m_options.ipv6enabled = TOX_ENABLE_IPV6_DEFAULT; 88 m_options.ipv6enabled = TOX_ENABLE_IPV6_DEFAULT;
89 } else { 89 } else {
90 if (tox_options_get_savedata_type(options) != TOX_SAVEDATA_TYPE_NONE) { 90 if (tox_options_get_savedata_type(options) != TOX_SAVEDATA_TYPE_NONE) {
91 if (tox_options_get_savedata_data(options) == NULL || tox_options_get_savedata_length(options) == 0) { 91 if (tox_options_get_savedata_data(options) == nullptr || tox_options_get_savedata_length(options) == 0) {
92 SET_ERROR_PARAMETER(error, TOX_ERR_NEW_LOAD_BAD_FORMAT); 92 SET_ERROR_PARAMETER(error, TOX_ERR_NEW_LOAD_BAD_FORMAT);
93 return NULL; 93 return nullptr;
94 } 94 }
95 } 95 }
96 96
97 if (tox_options_get_savedata_type(options) == TOX_SAVEDATA_TYPE_SECRET_KEY) { 97 if (tox_options_get_savedata_type(options) == TOX_SAVEDATA_TYPE_SECRET_KEY) {
98 if (tox_options_get_savedata_length(options) != TOX_SECRET_KEY_SIZE) { 98 if (tox_options_get_savedata_length(options) != TOX_SECRET_KEY_SIZE) {
99 SET_ERROR_PARAMETER(error, TOX_ERR_NEW_LOAD_BAD_FORMAT); 99 SET_ERROR_PARAMETER(error, TOX_ERR_NEW_LOAD_BAD_FORMAT);
100 return NULL; 100 return nullptr;
101 } 101 }
102 102
103 load_savedata_sk = 1; 103 load_savedata_sk = 1;
104 } else if (tox_options_get_savedata_type(options) == TOX_SAVEDATA_TYPE_TOX_SAVE) { 104 } else if (tox_options_get_savedata_type(options) == TOX_SAVEDATA_TYPE_TOX_SAVE) {
105 if (tox_options_get_savedata_length(options) < TOX_ENC_SAVE_MAGIC_LENGTH) { 105 if (tox_options_get_savedata_length(options) < TOX_ENC_SAVE_MAGIC_LENGTH) {
106 SET_ERROR_PARAMETER(error, TOX_ERR_NEW_LOAD_BAD_FORMAT); 106 SET_ERROR_PARAMETER(error, TOX_ERR_NEW_LOAD_BAD_FORMAT);
107 return NULL; 107 return nullptr;
108 } 108 }
109 109
110 if (crypto_memcmp(tox_options_get_savedata_data(options), TOX_ENC_SAVE_MAGIC_NUMBER, TOX_ENC_SAVE_MAGIC_LENGTH) == 0) { 110 if (crypto_memcmp(tox_options_get_savedata_data(options), TOX_ENC_SAVE_MAGIC_NUMBER, TOX_ENC_SAVE_MAGIC_LENGTH) == 0) {
111 SET_ERROR_PARAMETER(error, TOX_ERR_NEW_LOAD_ENCRYPTED); 111 SET_ERROR_PARAMETER(error, TOX_ERR_NEW_LOAD_ENCRYPTED);
112 return NULL; 112 return nullptr;
113 } 113 }
114 114
115 load_savedata_tox = 1; 115 load_savedata_tox = 1;
@@ -141,13 +141,13 @@ Tox *tox_new(const struct Tox_Options *options, TOX_ERR_NEW *error)
141 141
142 default: 142 default:
143 SET_ERROR_PARAMETER(error, TOX_ERR_NEW_PROXY_BAD_TYPE); 143 SET_ERROR_PARAMETER(error, TOX_ERR_NEW_PROXY_BAD_TYPE);
144 return NULL; 144 return nullptr;
145 } 145 }
146 146
147 if (m_options.proxy_info.proxy_type != TCP_PROXY_NONE) { 147 if (m_options.proxy_info.proxy_type != TCP_PROXY_NONE) {
148 if (tox_options_get_proxy_port(options) == 0) { 148 if (tox_options_get_proxy_port(options) == 0) {
149 SET_ERROR_PARAMETER(error, TOX_ERR_NEW_PROXY_BAD_PORT); 149 SET_ERROR_PARAMETER(error, TOX_ERR_NEW_PROXY_BAD_PORT);
150 return NULL; 150 return nullptr;
151 } 151 }
152 152
153 ip_init(&m_options.proxy_info.ip_port.ip, m_options.ipv6enabled); 153 ip_init(&m_options.proxy_info.ip_port.ip, m_options.ipv6enabled);
@@ -156,10 +156,10 @@ Tox *tox_new(const struct Tox_Options *options, TOX_ERR_NEW *error)
156 m_options.proxy_info.ip_port.ip.family = TOX_AF_UNSPEC; 156 m_options.proxy_info.ip_port.ip.family = TOX_AF_UNSPEC;
157 } 157 }
158 158
159 if (!addr_resolve_or_parse_ip(tox_options_get_proxy_host(options), &m_options.proxy_info.ip_port.ip, NULL)) { 159 if (!addr_resolve_or_parse_ip(tox_options_get_proxy_host(options), &m_options.proxy_info.ip_port.ip, nullptr)) {
160 SET_ERROR_PARAMETER(error, TOX_ERR_NEW_PROXY_BAD_HOST); 160 SET_ERROR_PARAMETER(error, TOX_ERR_NEW_PROXY_BAD_HOST);
161 // TODO(irungentoo): TOX_ERR_NEW_PROXY_NOT_FOUND if domain. 161 // TODO(irungentoo): TOX_ERR_NEW_PROXY_NOT_FOUND if domain.
162 return NULL; 162 return nullptr;
163 } 163 }
164 164
165 m_options.proxy_info.ip_port.port = net_htons(tox_options_get_proxy_port(options)); 165 m_options.proxy_info.ip_port.port = net_htons(tox_options_get_proxy_port(options));
@@ -180,7 +180,7 @@ Tox *tox_new(const struct Tox_Options *options, TOX_ERR_NEW *error)
180 SET_ERROR_PARAMETER(error, TOX_ERR_NEW_MALLOC); 180 SET_ERROR_PARAMETER(error, TOX_ERR_NEW_MALLOC);
181 } 181 }
182 182
183 return NULL; 183 return nullptr;
184 } 184 }
185 185
186 if (load_savedata_tox 186 if (load_savedata_tox
@@ -198,7 +198,7 @@ Tox *tox_new(const struct Tox_Options *options, TOX_ERR_NEW *error)
198 198
199void tox_kill(Tox *tox) 199void tox_kill(Tox *tox)
200{ 200{
201 if (tox == NULL) { 201 if (tox == nullptr) {
202 return; 202 return;
203 } 203 }
204 204
diff --git a/toxcore/tox_api.c b/toxcore/tox_api.c
index b6c8c386..89da8583 100644
--- a/toxcore/tox_api.c
+++ b/toxcore/tox_api.c
@@ -1,5 +1,7 @@
1#include "tox.h" 1#include "tox.h"
2 2
3#include "ccompat.h"
4
3#include <stdlib.h> 5#include <stdlib.h>
4#include <string.h> 6#include <string.h>
5 7
@@ -88,7 +90,7 @@ struct Tox_Options *tox_options_new(TOX_ERR_OPTIONS_NEW *error)
88 } 90 }
89 91
90 SET_ERROR_PARAMETER(error, TOX_ERR_OPTIONS_NEW_MALLOC); 92 SET_ERROR_PARAMETER(error, TOX_ERR_OPTIONS_NEW_MALLOC);
91 return NULL; 93 return nullptr;
92} 94}
93 95
94void tox_options_free(struct Tox_Options *options) 96void tox_options_free(struct Tox_Options *options)
diff --git a/toxcore/util.c b/toxcore/util.c
index 85584f09..ff612b1a 100644
--- a/toxcore/util.c
+++ b/toxcore/util.c
@@ -48,7 +48,7 @@ static uint64_t unix_base_time_value;
48void unix_time_update(void) 48void unix_time_update(void)
49{ 49{
50 if (unix_base_time_value == 0) { 50 if (unix_base_time_value == 0) {
51 unix_base_time_value = ((uint64_t)time(NULL) - (current_time_monotonic() / 1000ULL)); 51 unix_base_time_value = ((uint64_t)time(nullptr) - (current_time_monotonic() / 1000ULL));
52 } 52 }
53 53
54 unix_time_value = (current_time_monotonic() / 1000ULL) + unix_base_time_value; 54 unix_time_value = (current_time_monotonic() / 1000ULL) + unix_base_time_value;