diff options
author | iphydf <iphydf@users.noreply.github.com> | 2018-01-28 21:30:39 +0000 |
---|---|---|
committer | iphydf <iphydf@users.noreply.github.com> | 2018-01-30 23:35:50 +0000 |
commit | 92ffad1a72bc8c422426d52ac408bd71242dd047 (patch) | |
tree | f592f353068dd2043525dd2cc04d6124a4ed4bc4 /toxcore/onion_client.c | |
parent | 623e9ac331df7323660e21c8a2226523a5ee713b (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/onion_client.c')
-rw-r--r-- | toxcore/onion_client.c | 55 |
1 files changed, 28 insertions, 27 deletions
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 | ||
1847 | Onion_Client *new_onion_client(Net_Crypto *c) | 1848 | Onion_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 | ||
1880 | void kill_onion_client(Onion_Client *onion_c) | 1881 | void 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 | } |