Use nullptr as NULL pointer constant instead of NULL or 0.

This changes only code, no string literals or comments.
This commit is contained in:
iphydf 2018-01-28 21:30:39 +00:00
parent 623e9ac331
commit 92ffad1a72
No known key found for this signature in database
GPG Key ID: 3855DBA2D74403C9
73 changed files with 1041 additions and 877 deletions

View File

@ -148,7 +148,6 @@ if(NOT "${CMAKE_CXX_COMPILER_ID}" STREQUAL "MSVC")
# Downgrade to warning so we still see it.
add_flag("-Wno-error=unused-variable")
add_cxxflag("-Wno-error=zero-as-null-pointer-constant")
endif()
endif()
@ -466,12 +465,13 @@ function(auto_test target)
endif()
endfunction()
if(BUILD_TOXAV)
if(BUILD_TOXAV AND CHECK_FOUND)
add_definitions(-D__STDC_LIMIT_MACROS=1)
add_executable(auto_monolith_test
auto_tests/monolith_test.cpp
${ANDROID_CPU_FEATURES})
target_link_modules(auto_monolith_test
${CHECK_LIBRARIES}
${LIBSODIUM_LIBRARIES}
${OPUS_LIBRARIES}
${VPX_LIBRARIES}

View File

@ -1,5 +1,3 @@
load("//tools:no_undefined.bzl", "cc_library")
cc_library(
name = "helpers",
testonly = True,
@ -26,4 +24,29 @@ cc_library(
"//c-toxcore/toxencryptsave",
"@check",
],
) for src in glob(["*_test.c*"])]
) for src in glob(["*_test.c"])]
cc_library(
name = "monolith",
hdrs = glob([
"*.c",
"*.h",
]),
)
cc_test(
name = "monolith_test",
size = "small",
srcs = ["monolith_test.cpp"],
copts = [
"-Wno-parentheses",
"-Wno-sign-compare",
],
deps = [
":helpers",
":monolith",
"//c-toxcore/other:monolith",
"//c-toxcore/testing:misc_tools",
"@check",
],
)

View File

@ -1,4 +1,6 @@
#ifndef _XOPEN_SOURCE
#define _XOPEN_SOURCE 600
#endif
#ifdef HAVE_CONFIG_H
#include "config.h"
@ -29,6 +31,7 @@
# undef TOX_AF_INET6
# define TOX_AF_INET6 TOX_AF_INET
# define get_ip6_loopback get_ip4_loopback
# define IP6 IP4
#endif
static inline IP get_loopback()
@ -51,8 +54,8 @@ START_TEST(test_basic)
uint8_t self_public_key[CRYPTO_PUBLIC_KEY_SIZE];
uint8_t self_secret_key[CRYPTO_SECRET_KEY_SIZE];
crypto_new_keypair(self_public_key, self_secret_key);
TCP_Server *tcp_s = new_TCP_server(USE_IPV6, NUM_PORTS, ports, self_secret_key, NULL);
ck_assert_msg(tcp_s != NULL, "Failed to create TCP relay server");
TCP_Server *tcp_s = new_TCP_server(USE_IPV6, NUM_PORTS, ports, self_secret_key, nullptr);
ck_assert_msg(tcp_s != nullptr, "Failed to create TCP relay server");
ck_assert_msg(tcp_server_listen_count(tcp_s) == NUM_PORTS, "Failed to bind to all ports");
Socket sock = net_socket(TOX_AF_INET6, TOX_SOCK_STREAM, TOX_PROTO_TCP);
@ -236,8 +239,8 @@ START_TEST(test_some)
uint8_t self_public_key[CRYPTO_PUBLIC_KEY_SIZE];
uint8_t self_secret_key[CRYPTO_SECRET_KEY_SIZE];
crypto_new_keypair(self_public_key, self_secret_key);
TCP_Server *tcp_s = new_TCP_server(USE_IPV6, NUM_PORTS, ports, self_secret_key, NULL);
ck_assert_msg(tcp_s != NULL, "Failed to create TCP relay server");
TCP_Server *tcp_s = new_TCP_server(USE_IPV6, NUM_PORTS, ports, self_secret_key, nullptr);
ck_assert_msg(tcp_s != nullptr, "Failed to create TCP relay server");
ck_assert_msg(tcp_server_listen_count(tcp_s) == NUM_PORTS, "Failed to bind to all ports");
struct sec_TCP_con *con1 = new_TCP_con(tcp_s);
@ -413,8 +416,8 @@ START_TEST(test_client)
uint8_t self_public_key[CRYPTO_PUBLIC_KEY_SIZE];
uint8_t self_secret_key[CRYPTO_SECRET_KEY_SIZE];
crypto_new_keypair(self_public_key, self_secret_key);
TCP_Server *tcp_s = new_TCP_server(USE_IPV6, NUM_PORTS, ports, self_secret_key, NULL);
ck_assert_msg(tcp_s != NULL, "Failed to create TCP relay server");
TCP_Server *tcp_s = new_TCP_server(USE_IPV6, NUM_PORTS, ports, self_secret_key, nullptr);
ck_assert_msg(tcp_s != nullptr, "Failed to create TCP relay server");
ck_assert_msg(tcp_server_listen_count(tcp_s) == NUM_PORTS, "Failed to bind to all ports");
uint8_t f_public_key[CRYPTO_PUBLIC_KEY_SIZE];
@ -424,23 +427,23 @@ START_TEST(test_client)
ip_port_tcp_s.port = net_htons(ports[rand() % NUM_PORTS]);
ip_port_tcp_s.ip = get_loopback();
TCP_Client_Connection *conn = new_TCP_connection(ip_port_tcp_s, self_public_key, f_public_key, f_secret_key, 0);
TCP_Client_Connection *conn = new_TCP_connection(ip_port_tcp_s, self_public_key, f_public_key, f_secret_key, nullptr);
c_sleep(50);
do_TCP_connection(conn, NULL);
do_TCP_connection(conn, nullptr);
ck_assert_msg(tcp_con_status(conn) == TCP_CLIENT_UNCONFIRMED, "Wrong status. Expected: %u, is: %u",
TCP_CLIENT_UNCONFIRMED, tcp_con_status(conn));
c_sleep(50);
do_TCP_server(tcp_s);
c_sleep(50);
do_TCP_connection(conn, NULL);
do_TCP_connection(conn, nullptr);
ck_assert_msg(tcp_con_status(conn) == TCP_CLIENT_CONFIRMED, "Wrong status. Expected: %u, is: %u", TCP_CLIENT_CONFIRMED,
tcp_con_status(conn));
c_sleep(500);
do_TCP_connection(conn, NULL);
do_TCP_connection(conn, nullptr);
ck_assert_msg(tcp_con_status(conn) == TCP_CLIENT_CONFIRMED, "Wrong status. Expected: %u, is: %u", TCP_CLIENT_CONFIRMED,
tcp_con_status(conn));
c_sleep(500);
do_TCP_connection(conn, NULL);
do_TCP_connection(conn, nullptr);
ck_assert_msg(tcp_con_status(conn) == TCP_CLIENT_CONFIRMED, "Wrong status. Expected: %u, is: %u", TCP_CLIENT_CONFIRMED,
tcp_con_status(conn));
do_TCP_server(tcp_s);
@ -452,20 +455,21 @@ START_TEST(test_client)
uint8_t f2_secret_key[CRYPTO_SECRET_KEY_SIZE];
crypto_new_keypair(f2_public_key, f2_secret_key);
ip_port_tcp_s.port = net_htons(ports[rand() % NUM_PORTS]);
TCP_Client_Connection *conn2 = new_TCP_connection(ip_port_tcp_s, self_public_key, f2_public_key, f2_secret_key, 0);
TCP_Client_Connection *conn2 = new_TCP_connection(
ip_port_tcp_s, self_public_key, f2_public_key, f2_secret_key, nullptr);
routing_response_handler(conn, response_callback, (char *)conn + 2);
routing_status_handler(conn, status_callback, (void *)2);
routing_data_handler(conn, data_callback, (void *)3);
oob_data_handler(conn, oob_data_callback, (void *)4);
oob_data_callback_good = response_callback_good = status_callback_good = data_callback_good = 0;
c_sleep(50);
do_TCP_connection(conn, NULL);
do_TCP_connection(conn2, NULL);
do_TCP_connection(conn, nullptr);
do_TCP_connection(conn2, nullptr);
c_sleep(50);
do_TCP_server(tcp_s);
c_sleep(50);
do_TCP_connection(conn, NULL);
do_TCP_connection(conn2, NULL);
do_TCP_connection(conn, nullptr);
do_TCP_connection(conn2, nullptr);
c_sleep(50);
uint8_t data[5] = {1, 2, 3, 4, 5};
memcpy(oob_pubkey, f2_public_key, CRYPTO_PUBLIC_KEY_SIZE);
@ -475,8 +479,8 @@ START_TEST(test_client)
c_sleep(50);
do_TCP_server(tcp_s);
c_sleep(50);
do_TCP_connection(conn, NULL);
do_TCP_connection(conn2, NULL);
do_TCP_connection(conn, nullptr);
do_TCP_connection(conn2, nullptr);
ck_assert_msg(oob_data_callback_good == 1, "oob callback not called");
ck_assert_msg(response_callback_good == 1, "response callback not called");
ck_assert_msg(public_key_cmp(response_callback_public_key, f2_public_key) == 0, "wrong public key");
@ -489,16 +493,16 @@ START_TEST(test_client)
c_sleep(50);
do_TCP_server(tcp_s);
c_sleep(50);
do_TCP_connection(conn, NULL);
do_TCP_connection(conn2, NULL);
do_TCP_connection(conn, nullptr);
do_TCP_connection(conn2, nullptr);
ck_assert_msg(data_callback_good == 1, "data callback not called");
status_callback_good = 0;
send_disconnect_request(conn2, 0);
c_sleep(50);
do_TCP_server(tcp_s);
c_sleep(50);
do_TCP_connection(conn, NULL);
do_TCP_connection(conn2, NULL);
do_TCP_connection(conn, nullptr);
do_TCP_connection(conn2, nullptr);
ck_assert_msg(status_callback_good == 1, "status callback not called");
ck_assert_msg(status_callback_status == 1, "wrong status");
kill_TCP_server(tcp_s);
@ -521,17 +525,17 @@ START_TEST(test_client_invalid)
ip_port_tcp_s.port = net_htons(ports[rand() % NUM_PORTS]);
ip_port_tcp_s.ip = get_loopback();
TCP_Client_Connection *conn = new_TCP_connection(ip_port_tcp_s, self_public_key, f_public_key, f_secret_key, 0);
TCP_Client_Connection *conn = new_TCP_connection(ip_port_tcp_s, self_public_key, f_public_key, f_secret_key, nullptr);
c_sleep(50);
do_TCP_connection(conn, NULL);
do_TCP_connection(conn, nullptr);
ck_assert_msg(tcp_con_status(conn) == TCP_CLIENT_CONNECTING, "Wrong status. Expected: %u, is: %u",
TCP_CLIENT_CONNECTING, tcp_con_status(conn));
c_sleep(5000);
do_TCP_connection(conn, NULL);
do_TCP_connection(conn, nullptr);
ck_assert_msg(tcp_con_status(conn) == TCP_CLIENT_CONNECTING, "Wrong status. Expected: %u, is: %u",
TCP_CLIENT_CONNECTING, tcp_con_status(conn));
c_sleep(6000);
do_TCP_connection(conn, NULL);
do_TCP_connection(conn, nullptr);
ck_assert_msg(tcp_con_status(conn) == TCP_CLIENT_DISCONNECTED, "Wrong status. Expected: %u, is: %u",
TCP_CLIENT_DISCONNECTED, tcp_con_status(conn));
@ -572,7 +576,7 @@ START_TEST(test_tcp_connection)
uint8_t self_public_key[CRYPTO_PUBLIC_KEY_SIZE];
uint8_t self_secret_key[CRYPTO_SECRET_KEY_SIZE];
crypto_new_keypair(self_public_key, self_secret_key);
TCP_Server *tcp_s = new_TCP_server(USE_IPV6, NUM_PORTS, ports, self_secret_key, NULL);
TCP_Server *tcp_s = new_TCP_server(USE_IPV6, NUM_PORTS, ports, self_secret_key, nullptr);
ck_assert_msg(public_key_cmp(tcp_server_public_key(tcp_s), self_public_key) == 0, "Wrong public key");
TCP_Proxy_Info proxy_info;
@ -607,18 +611,18 @@ START_TEST(test_tcp_connection)
c_sleep(50);
do_TCP_server(tcp_s);
c_sleep(50);
do_tcp_connections(tc_1, NULL);
do_tcp_connections(tc_2, NULL);
do_tcp_connections(tc_1, nullptr);
do_tcp_connections(tc_2, nullptr);
c_sleep(50);
do_TCP_server(tcp_s);
c_sleep(50);
do_tcp_connections(tc_1, NULL);
do_tcp_connections(tc_2, NULL);
do_tcp_connections(tc_1, nullptr);
do_tcp_connections(tc_2, nullptr);
c_sleep(50);
do_TCP_server(tcp_s);
c_sleep(50);
do_tcp_connections(tc_1, NULL);
do_tcp_connections(tc_2, NULL);
do_tcp_connections(tc_1, nullptr);
do_tcp_connections(tc_2, nullptr);
int ret = send_packet_tcp_connection(tc_1, 0, (const uint8_t *)"Gentoo", 6);
ck_assert_msg(ret == 0, "could not send packet.");
@ -628,8 +632,8 @@ START_TEST(test_tcp_connection)
do_TCP_server(tcp_s);
c_sleep(50);
do_tcp_connections(tc_1, NULL);
do_tcp_connections(tc_2, NULL);
do_tcp_connections(tc_1, nullptr);
do_tcp_connections(tc_2, nullptr);
ck_assert_msg(tcp_data_callback_called, "could not recv packet.");
ck_assert_msg(tcp_connection_to_online_tcp_relays(tc_1, 0) == 1, "Wrong number of connected relays");
@ -638,8 +642,8 @@ START_TEST(test_tcp_connection)
c_sleep(50);
do_TCP_server(tcp_s);
c_sleep(50);
do_tcp_connections(tc_1, NULL);
do_tcp_connections(tc_2, NULL);
do_tcp_connections(tc_1, nullptr);
do_tcp_connections(tc_2, nullptr);
ck_assert_msg(send_packet_tcp_connection(tc_1, 0, (const uint8_t *)"Gentoo", 6) == -1, "could send packet.");
ck_assert_msg(kill_tcp_connection_to(tc_2, 0) == 0, "could not kill connection to\n");
@ -680,7 +684,7 @@ START_TEST(test_tcp_connection2)
uint8_t self_public_key[CRYPTO_PUBLIC_KEY_SIZE];
uint8_t self_secret_key[CRYPTO_SECRET_KEY_SIZE];
crypto_new_keypair(self_public_key, self_secret_key);
TCP_Server *tcp_s = new_TCP_server(USE_IPV6, NUM_PORTS, ports, self_secret_key, NULL);
TCP_Server *tcp_s = new_TCP_server(USE_IPV6, NUM_PORTS, ports, self_secret_key, nullptr);
ck_assert_msg(public_key_cmp(tcp_server_public_key(tcp_s), self_public_key) == 0, "Wrong public key");
TCP_Proxy_Info proxy_info;
@ -709,18 +713,18 @@ START_TEST(test_tcp_connection2)
c_sleep(50);
do_TCP_server(tcp_s);
c_sleep(50);
do_tcp_connections(tc_1, NULL);
do_tcp_connections(tc_2, NULL);
do_tcp_connections(tc_1, nullptr);
do_tcp_connections(tc_2, nullptr);
c_sleep(50);
do_TCP_server(tcp_s);
c_sleep(50);
do_tcp_connections(tc_1, NULL);
do_tcp_connections(tc_2, NULL);
do_tcp_connections(tc_1, nullptr);
do_tcp_connections(tc_2, nullptr);
c_sleep(50);
do_TCP_server(tcp_s);
c_sleep(50);
do_tcp_connections(tc_1, NULL);
do_tcp_connections(tc_2, NULL);
do_tcp_connections(tc_1, nullptr);
do_tcp_connections(tc_2, nullptr);
int ret = send_packet_tcp_connection(tc_1, 0, (const uint8_t *)"Gentoo", 6);
ck_assert_msg(ret == 0, "could not send packet.");
@ -731,8 +735,8 @@ START_TEST(test_tcp_connection2)
do_TCP_server(tcp_s);
c_sleep(50);
do_tcp_connections(tc_1, NULL);
do_tcp_connections(tc_2, NULL);
do_tcp_connections(tc_1, nullptr);
do_tcp_connections(tc_2, nullptr);
ck_assert_msg(tcp_oobdata_callback_called, "could not recv packet.");
@ -740,8 +744,8 @@ START_TEST(test_tcp_connection2)
do_TCP_server(tcp_s);
c_sleep(50);
do_tcp_connections(tc_1, NULL);
do_tcp_connections(tc_2, NULL);
do_tcp_connections(tc_1, nullptr);
do_tcp_connections(tc_2, nullptr);
ck_assert_msg(tcp_data_callback_called, "could not recv packet.");
ck_assert_msg(kill_tcp_connection_to(tc_1, 0) == 0, "could not kill connection to\n");
@ -767,7 +771,7 @@ static Suite *TCP_suite(void)
int main(int argc, char *argv[])
{
srand((unsigned int) time(NULL));
srand((unsigned int) time(nullptr));
Suite *TCP = TCP_suite();
SRunner *test_runner = srunner_create(TCP);

View File

@ -1,7 +1,9 @@
/* Auto Tests: Conferences.
*/
#ifndef _XOPEN_SOURCE
#define _XOPEN_SOURCE 600
#endif
#ifdef HAVE_CONFIG_H
#include "config.h"
@ -28,7 +30,7 @@ static void g_accept_friend_request(Tox *m, const uint8_t *public_key, const uin
}
if (length == 7 && memcmp("Gentoo", data, 7) == 0) {
tox_friend_add_norequest(m, public_key, 0);
tox_friend_add_norequest(m, public_key, nullptr);
}
}
@ -49,12 +51,12 @@ static void print_group_invite_callback(Tox *tox, uint32_t friendnumber, TOX_CON
uint32_t g_num;
if ((g_num = tox_conference_join(tox, friendnumber, data, length, NULL)) == UINT32_MAX) {
if ((g_num = tox_conference_join(tox, friendnumber, data, length, nullptr)) == UINT32_MAX) {
return;
}
ck_assert_msg(g_num == 0, "Group number was not 0");
ck_assert_msg(tox_conference_join(tox, friendnumber, data, length, NULL) == -1,
ck_assert_msg(tox_conference_join(tox, friendnumber, data, length, nullptr) == -1,
"Joining groupchat twice should be impossible.");
invite_tox = tox;
@ -78,7 +80,7 @@ static void print_group_message(Tox *tox, uint32_t groupnumber, uint32_t peernum
START_TEST(test_many_group)
{
long long unsigned int test_start_time = time(NULL);
long long unsigned int test_start_time = time(nullptr);
group_test_restart:
;
@ -88,16 +90,16 @@ group_test_restart:
unsigned int i, j, k;
uint32_t to_comp = 234212;
int test_run = 0;
long long unsigned int cur_time = time(NULL);
struct Tox_Options *opts = tox_options_new(NULL);
long long unsigned int cur_time = time(nullptr);
struct Tox_Options *opts = tox_options_new(nullptr);
/* FIXME: Currently here is problems with IPv6 */
tox_options_set_ipv6_enabled(opts, false);
for (i = 0; i < NUM_GROUP_TOX; ++i) {
tox_index[i] = i + 1;
toxes[i] = tox_new_log(opts, 0, &tox_index[i]);
toxes[i] = tox_new_log(opts, nullptr, &tox_index[i]);
ck_assert_msg(toxes[i] != 0, "Failed to create tox instances %u", i);
ck_assert_msg(toxes[i] != nullptr, "Failed to create tox instances %u", i);
tox_callback_friend_request(toxes[i], &g_accept_friend_request);
tox_callback_conference_invite(toxes[i], &print_group_invite_callback);
}
@ -116,14 +118,14 @@ group_test_restart:
tox_self_get_address(toxes[NUM_GROUP_TOX - 1], address);
for (i = 0; i < NUM_GROUP_TOX; ++i) {
ck_assert_msg(tox_friend_add(toxes[i], address, (const uint8_t *)"Gentoo", 7, 0) == 0, "Failed to add friend");
ck_assert_msg(tox_friend_add(toxes[i], address, (const uint8_t *)"Gentoo", 7, nullptr) == 0, "Failed to add friend");
tox_self_get_address(toxes[i], address);
}
while (1) {
for (i = 0; i < NUM_GROUP_TOX; ++i) {
if (tox_friend_get_connection_status(toxes[i], 0, 0) != TOX_CONNECTION_UDP) {
if (tox_friend_get_connection_status(toxes[i], 0, nullptr) != TOX_CONNECTION_UDP) {
break;
}
}
@ -139,11 +141,11 @@ group_test_restart:
c_sleep(25);
}
printf("friends connected, took %llu seconds\n", time(NULL) - cur_time);
printf("friends connected, took %llu seconds\n", time(nullptr) - cur_time);
ck_assert_msg(tox_conference_new(toxes[0], NULL) != UINT32_MAX, "Failed to create group");
ck_assert_msg(tox_conference_invite(toxes[0], 0, 0, NULL) != 0, "Failed to invite friend");
ck_assert_msg(tox_conference_set_title(toxes[0], 0, (const uint8_t *)"Gentoo", sizeof("Gentoo") - 1, NULL) != 0,
ck_assert_msg(tox_conference_new(toxes[0], nullptr) != UINT32_MAX, "Failed to create group");
ck_assert_msg(tox_conference_invite(toxes[0], 0, 0, nullptr) != 0, "Failed to invite friend");
ck_assert_msg(tox_conference_set_title(toxes[0], 0, (const uint8_t *)"Gentoo", sizeof("Gentoo") - 1, nullptr) != 0,
"Failed to set group title");
invite_counter = ~0;
@ -156,7 +158,7 @@ group_test_restart:
}
if (!invite_counter) {
ck_assert_msg(tox_conference_invite(invite_tox, 0, 0, NULL) != 0, "Failed to invite friend");
ck_assert_msg(tox_conference_invite(invite_tox, 0, 0, nullptr) != 0, "Failed to invite friend");
}
if (done == invite_counter) {
@ -168,7 +170,7 @@ group_test_restart:
}
for (i = 0; i < NUM_GROUP_TOX; ++i) {
uint32_t peer_count = tox_conference_peer_count(toxes[i], 0, NULL);
uint32_t peer_count = tox_conference_peer_count(toxes[i], 0, nullptr);
/**
* Group chats fail unpredictably, currently they'll rerun as many times
@ -199,9 +201,9 @@ group_test_restart:
NUM_GROUP_TOX, i, peer_count);
uint8_t title[2048];
size_t ret = tox_conference_get_title_size(toxes[i], 0, NULL);
size_t ret = tox_conference_get_title_size(toxes[i], 0, nullptr);
ck_assert_msg(ret == sizeof("Gentoo") - 1, "Wrong title length");
tox_conference_get_title(toxes[i], 0, title, NULL);
tox_conference_get_title(toxes[i], 0, title, nullptr);
ck_assert_msg(memcmp("Gentoo", title, ret) == 0, "Wrong title");
}
@ -232,7 +234,7 @@ group_test_restart:
ck_assert_msg(num_recv == NUM_GROUP_TOX, "Failed to recv group messages.");
for (k = NUM_GROUP_TOX; k != 0 ; --k) {
tox_conference_delete(toxes[k - 1], 0, NULL);
tox_conference_delete(toxes[k - 1], 0, nullptr);
for (j = 0; j < 10; ++j) {
for (i = 0; i < NUM_GROUP_TOX; ++i) {
@ -243,7 +245,7 @@ group_test_restart:
}
for (i = 0; i < (k - 1); ++i) {
uint32_t peer_count = tox_conference_peer_count(toxes[i], 0, NULL);
uint32_t peer_count = tox_conference_peer_count(toxes[i], 0, nullptr);
ck_assert_msg(peer_count == (k - 1), "\n\tBad number of group peers (post check)."
"\n\t\t\tExpected: %u but tox_instance(%u) only has: %" PRIu32 "\n\n",
(k - 1), i, peer_count);
@ -254,7 +256,7 @@ group_test_restart:
tox_kill(toxes[i]);
}
printf("test_many_group succeeded, took %llu seconds\n", time(NULL) - test_start_time);
printf("test_many_group succeeded, took %llu seconds\n", time(nullptr) - test_start_time);
}
END_TEST
@ -275,7 +277,7 @@ static Suite *tox_suite(void)
int main(int argc, char *argv[])
{
srand((unsigned int) time(NULL));
srand((unsigned int) time(nullptr));
Suite *tox = tox_suite();
SRunner *test_runner = srunner_create(tox);

View File

@ -434,7 +434,7 @@ static Suite *crypto_suite(void)
int main(int argc, char *argv[])
{
srand((unsigned int) time(NULL));
srand((unsigned int) time(nullptr));
Suite *crypto = crypto_suite();
SRunner *test_runner = srunner_create(crypto);

View File

@ -1,4 +1,6 @@
#ifndef _XOPEN_SOURCE
#define _XOPEN_SOURCE 600
#endif
#ifdef HAVE_CONFIG_H
#include "config.h"
@ -11,7 +13,9 @@
#include "helpers.h"
#ifndef DHT_C_INCLUDED
#include "../toxcore/DHT.c"
#endif // DHT_C_INCLUDED
#include "../toxcore/tox.h"
@ -325,11 +329,11 @@ static void test_addto_lists_good(DHT *dht,
static void test_addto_lists(IP ip)
{
Networking_Core *net = new_networking(NULL, ip, TOX_PORT_DEFAULT);
ck_assert_msg(net != 0, "Failed to create Networking_Core");
Networking_Core *net = new_networking(nullptr, ip, TOX_PORT_DEFAULT);
ck_assert_msg(net != nullptr, "Failed to create Networking_Core");
DHT *dht = new_DHT(NULL, net, true);
ck_assert_msg(dht != 0, "Failed to create DHT");
DHT *dht = new_DHT(nullptr, net, true);
ck_assert_msg(dht != nullptr, "Failed to create DHT");
IP_Port ip_port = { .ip = ip, .port = TOX_PORT_DEFAULT };
uint8_t public_key[CRYPTO_PUBLIC_KEY_SIZE];
@ -466,8 +470,8 @@ static void test_list_main(void)
IP ip;
ip_init(&ip, 1);
dhts[i] = new_DHT(NULL, new_networking(NULL, ip, DHT_DEFAULT_PORT + i), true);
ck_assert_msg(dhts[i] != 0, "Failed to create dht instances %u", i);
dhts[i] = new_DHT(nullptr, new_networking(nullptr, ip, DHT_DEFAULT_PORT + i), true);
ck_assert_msg(dhts[i] != nullptr, "Failed to create dht instances %u", i);
ck_assert_msg(net_port(dhts[i]->net) != DHT_DEFAULT_PORT + i, "Bound to wrong port");
}
@ -602,8 +606,8 @@ START_TEST(test_DHT_test)
IP ip;
ip_init(&ip, 1);
dhts[i] = new_DHT(NULL, new_networking(NULL, ip, DHT_DEFAULT_PORT + i), true);
ck_assert_msg(dhts[i] != 0, "Failed to create dht instances %u", i);
dhts[i] = new_DHT(nullptr, new_networking(nullptr, ip, DHT_DEFAULT_PORT + i), true);
ck_assert_msg(dhts[i] != nullptr, "Failed to create dht instances %u", i);
ck_assert_msg(net_port(dhts[i]->net) != DHT_DEFAULT_PORT + i, "Bound to wrong port");
}
@ -652,7 +656,7 @@ loop_top:
}
for (i = 0; i < NUM_DHT; ++i) {
networking_poll(dhts[i]->net, NULL);
networking_poll(dhts[i]->net, nullptr);
do_DHT(dhts[i]);
}
@ -715,7 +719,7 @@ static void dht_pack_unpack(const Node_format *nodes, size_t size, uint8_t *data
static void random_ip(IP_Port *ipp, int family)
{
uint8_t *ip = NULL;
uint8_t *ip = nullptr;
size_t size;
if (family == TOX_AF_INET || family == TCP_INET) {
@ -797,7 +801,7 @@ static Suite *dht_suite(void)
int main(int argc, char *argv[])
{
srand((unsigned int) time(NULL));
srand((unsigned int) time(nullptr));
Suite *dht = dht_suite();
SRunner *test_runner = srunner_create(dht);

View File

@ -39,7 +39,7 @@ static void accept_friend_request(Tox *m, const uint8_t *public_key, const uint8
}
if (length == 7 && memcmp("Gentoo", data, 7) == 0) {
tox_friend_add_norequest(m, public_key, 0);
tox_friend_add_norequest(m, public_key, nullptr);
}
}
@ -60,13 +60,13 @@ END_TEST
START_TEST(test_save_friend)
{
Tox *tox1 = tox_new_log(0, 0, 0);
Tox *tox2 = tox_new_log(0, 0, 0);
Tox *tox1 = tox_new_log(nullptr, nullptr, nullptr);
Tox *tox2 = tox_new_log(nullptr, nullptr, nullptr);
ck_assert_msg(tox1 || tox2, "Failed to create 2 tox instances");
tox_callback_friend_request(tox2, accept_friend_request);
uint8_t address[TOX_ADDRESS_SIZE];
tox_self_get_address(tox2, address);
uint32_t test = tox_friend_add(tox1, address, (const uint8_t *)"Gentoo", 7, 0);
uint32_t test = tox_friend_add(tox1, address, (const uint8_t *)"Gentoo", 7, nullptr);
ck_assert_msg(test != UINT32_MAX, "Failed to add friend");
size_t size = tox_get_savedata_size(tox1);
@ -79,24 +79,24 @@ START_TEST(test_save_friend)
ck_assert_msg(ret, "failed to encrypted save: %u", error1);
ck_assert_msg(tox_is_data_encrypted(enc_data), "magic number missing");
struct Tox_Options *options = tox_options_new(NULL);
struct Tox_Options *options = tox_options_new(nullptr);
tox_options_set_savedata_type(options, TOX_SAVEDATA_TYPE_TOX_SAVE);
tox_options_set_savedata_data(options, enc_data, size2);
TOX_ERR_NEW err2;
Tox *tox3 = tox_new_log(options, &err2, 0);
Tox *tox3 = tox_new_log(options, &err2, nullptr);
ck_assert_msg(err2 == TOX_ERR_NEW_LOAD_ENCRYPTED, "wrong error! %u. should fail with %u", err2,
TOX_ERR_NEW_LOAD_ENCRYPTED);
ck_assert_msg(tox3 == NULL, "tox_new with error should return NULL");
ck_assert_msg(tox3 == nullptr, "tox_new with error should return NULL");
VLA(uint8_t, dec_data, size);
TOX_ERR_DECRYPTION err3;
ret = tox_pass_decrypt(enc_data, size2, (const uint8_t *)"correcthorsebatterystaple", 25, dec_data, &err3);
ck_assert_msg(ret, "failed to decrypt save: %u", err3);
tox_options_set_savedata_data(options, dec_data, size);
tox3 = tox_new_log(options, &err2, 0);
tox3 = tox_new_log(options, &err2, nullptr);
ck_assert_msg(err2 == TOX_ERR_NEW_OK, "failed to load from decrypted data: %u", err2);
uint8_t address2[TOX_PUBLIC_KEY_SIZE];
ret = tox_friend_get_public_key(tox3, 0, address2, 0);
ret = tox_friend_get_public_key(tox3, 0, address2, nullptr);
ck_assert_msg(ret, "no friends!");
ck_assert_msg(memcmp(address, address2, TOX_PUBLIC_KEY_SIZE) == 0, "addresses don't match!");
@ -105,7 +105,7 @@ START_TEST(test_save_friend)
tox_get_savedata(tox3, data2);
TOX_ERR_KEY_DERIVATION keyerr;
Tox_Pass_Key *key = tox_pass_key_derive((const uint8_t *)"123qweasdzxc", 12, &keyerr);
ck_assert_msg(key != NULL, "pass key allocation failure");
ck_assert_msg(key != nullptr, "pass key allocation failure");
memcpy((uint8_t *)key, test_salt, TOX_PASS_SALT_LENGTH);
memcpy((uint8_t *)key + TOX_PASS_SALT_LENGTH, known_key2, TOX_PASS_KEY_LENGTH);
size2 = size + TOX_PASS_ENCRYPTION_EXTRA_LENGTH;
@ -125,10 +125,10 @@ START_TEST(test_save_friend)
// and now with the code in use (I only bothered with manually to debug this, and it seems a waste
// to remove the manual check now that it's there)
tox_options_set_savedata_data(options, out1, size);
Tox *tox4 = tox_new_log(options, &err2, 0);
Tox *tox4 = tox_new_log(options, &err2, nullptr);
ck_assert_msg(err2 == TOX_ERR_NEW_OK, "failed to new the third");
uint8_t address5[TOX_PUBLIC_KEY_SIZE];
ret = tox_friend_get_public_key(tox4, 0, address5, 0);
ret = tox_friend_get_public_key(tox4, 0, address5, nullptr);
ck_assert_msg(ret, "no friends! the third");
ck_assert_msg(memcmp(address, address2, TOX_PUBLIC_KEY_SIZE) == 0, "addresses don't match! the third");
@ -148,7 +148,7 @@ START_TEST(test_keys)
TOX_ERR_DECRYPTION decerr;
TOX_ERR_KEY_DERIVATION keyerr;
Tox_Pass_Key *key = tox_pass_key_derive((const uint8_t *)"123qweasdzxc", 12, &keyerr);
ck_assert_msg(key != NULL, "generic failure 1: %u", keyerr);
ck_assert_msg(key != nullptr, "generic failure 1: %u", keyerr);
const uint8_t *string = (const uint8_t *)"No Patrick, mayonnaise is not an instrument."; // 44
uint8_t encrypted[44 + TOX_PASS_ENCRYPTION_EXTRA_LENGTH];
@ -171,7 +171,7 @@ START_TEST(test_keys)
ck_assert_msg(ret, "generic failure 5: %u", decerr);
ck_assert_msg(memcmp(out2, string, 44) == 0, "decryption 2 failed");
ret = tox_pass_decrypt(encrypted2, 44 + TOX_PASS_ENCRYPTION_EXTRA_LENGTH, NULL, 0, out2, &decerr);
ret = tox_pass_decrypt(encrypted2, 44 + TOX_PASS_ENCRYPTION_EXTRA_LENGTH, nullptr, 0, out2, &decerr);
ck_assert_msg(!ret, "Decrypt succeeded with wrong pass");
ck_assert_msg(decerr != TOX_ERR_DECRYPTION_FAILED, "Bad error code %u", decerr);
@ -186,7 +186,7 @@ START_TEST(test_keys)
ck_assert_msg(tox_get_salt(encrypted, salt, &salt_err), "couldn't get salt");
ck_assert_msg(salt_err == TOX_ERR_GET_SALT_OK, "get_salt returned an error");
Tox_Pass_Key *key2 = tox_pass_key_derive_with_salt((const uint8_t *)"123qweasdzxc", 12, salt, &keyerr);
ck_assert_msg(key2 != NULL, "generic failure 7: %u", keyerr);
ck_assert_msg(key2 != nullptr, "generic failure 7: %u", keyerr);
ck_assert_msg(0 == memcmp(key, key2, TOX_PASS_KEY_LENGTH + TOX_PASS_SALT_LENGTH), "salt comparison failed");
tox_pass_key_free(key2);
tox_pass_key_free(key);
@ -206,7 +206,7 @@ static Suite *encryptsave_suite(void)
int main(int argc, char *argv[])
{
srand((unsigned int) time(NULL));
srand((unsigned int) time(nullptr));
Suite *encryptsave = encryptsave_suite();
SRunner *test_runner = srunner_create(encryptsave);

View File

@ -30,15 +30,17 @@
#include "../toxcore/tox.h"
#include "../toxencryptsave/toxencryptsave.h"
#include "../toxcore/ccompat.h"
static const char *pphrase = "bar", *name = "foo", *savefile = "./save";
static void save_data_encrypted(void)
{
struct Tox_Options *options = tox_options_new(NULL);
Tox *t = tox_new(options, NULL);
struct Tox_Options *options = tox_options_new(nullptr);
Tox *t = tox_new(options, nullptr);
tox_options_free(options);
tox_self_set_name(t, (const uint8_t *)name, strlen(name), NULL);
tox_self_set_name(t, (const uint8_t *)name, strlen(name), nullptr);
FILE *f = fopen(savefile, "w");
@ -87,7 +89,7 @@ static void load_data_decrypted(void)
exit(3);
}
struct Tox_Options *options = tox_options_new(NULL);
struct Tox_Options *options = tox_options_new(nullptr);
tox_options_set_savedata_type(options, TOX_SAVEDATA_TYPE_TOX_SAVE);
@ -99,7 +101,7 @@ static void load_data_decrypted(void)
tox_options_free(options);
if (t == NULL) {
if (t == nullptr) {
fprintf(stderr, "error: tox_new returned the error value %d\n", err);
return;
}

View File

@ -3,6 +3,8 @@
#include "../toxcore/tox.h"
#include "../toxcore/ccompat.h"
#include <assert.h>
#include <stdio.h>
#include <string.h>
@ -67,17 +69,17 @@ Tox *tox_new_log(struct Tox_Options *options, TOX_ERR_NEW *err, void *log_user_d
{
struct Tox_Options *log_options = options;
if (log_options == NULL) {
log_options = tox_options_new(NULL);
if (log_options == nullptr) {
log_options = tox_options_new(nullptr);
}
assert(log_options != NULL);
assert(log_options != nullptr);
tox_options_set_log_callback(log_options, &print_debug_log);
tox_options_set_log_user_data(log_options, log_user_data);
Tox *tox = tox_new(log_options, err);
if (options == NULL) {
if (options == nullptr) {
tox_options_free(log_options);
}

View File

@ -44,10 +44,10 @@ static const char *good_id_b_str = "d3f14b6d384d8f5f2a66cff637e69f28f539c5de61bc
static const char *bad_id_str = "9B569D14ff637e69f2";
static unsigned char *friend_id = NULL;
static unsigned char *good_id_a = NULL;
static unsigned char *good_id_b = NULL;
static unsigned char *bad_id = NULL;
static unsigned char *friend_id = nullptr;
static unsigned char *good_id_a = nullptr;
static unsigned char *good_id_b = nullptr;
static unsigned char *bad_id = nullptr;
static int friend_id_num = 0;
@ -60,10 +60,14 @@ START_TEST(test_m_sendmesage)
int bad_len = MAX_CRYPTO_PACKET_SIZE;
ck_assert(m_send_message_generic(m, -1, MESSAGE_NORMAL, (const uint8_t *)message, good_len, 0) == -1);
ck_assert(m_send_message_generic(m, REALLY_BIG_NUMBER, MESSAGE_NORMAL, (const uint8_t *)message, good_len, 0) == -1);
ck_assert(m_send_message_generic(m, 17, MESSAGE_NORMAL, (const uint8_t *)message, good_len, 0) == -1);
ck_assert(m_send_message_generic(m, friend_id_num, MESSAGE_NORMAL, (const uint8_t *)message, bad_len, 0) == -2);
ck_assert(m_send_message_generic(
m, -1, MESSAGE_NORMAL, (const uint8_t *)message, good_len, nullptr) == -1);
ck_assert(m_send_message_generic(
m, REALLY_BIG_NUMBER, MESSAGE_NORMAL, (const uint8_t *)message, good_len, nullptr) == -1);
ck_assert(m_send_message_generic(
m, 17, MESSAGE_NORMAL, (const uint8_t *)message, good_len, nullptr) == -1);
ck_assert(m_send_message_generic(
m, friend_id_num, MESSAGE_NORMAL, (const uint8_t *)message, bad_len, nullptr) == -2);
}
END_TEST
@ -355,7 +359,7 @@ int main(int argc, char *argv[])
Messenger_Options options = {0};
options.ipv6enabled = TOX_ENABLE_IPV6_DEFAULT;
options.log_callback = (logger_cb *)print_debug_log;
m = new_messenger(&options, 0);
m = new_messenger(&options, nullptr);
/* setup a default friend and friendnum */
if (m_addfriend_norequest(m, (uint8_t *)friend_id) < 0) {

View File

@ -9,6 +9,83 @@
#endif
#include "../other/monolith.h"
#define DHT_C_INCLUDED
#include "check_compat.h"
#include "helpers.h"
#include "../testing/misc_tools.c"
#include <ctype.h>
namespace TCP_test {
#include "TCP_test.c"
}
namespace conference_test {
#include "conference_test.c"
}
namespace crypto_test {
#include "crypto_test.c"
}
namespace dht_test {
#include "dht_test.c"
}
namespace encryptsave_test {
#include "encryptsave_test.c"
}
namespace file_saving_test {
#include "file_saving_test.c"
}
namespace messenger_test {
#include "messenger_test.c"
}
namespace network_test {
#include "network_test.c"
}
namespace onion_test {
#include "onion_test.c"
}
namespace resource_leak_test {
#include "resource_leak_test.c"
}
namespace save_friend_test {
#include "save_friend_test.c"
}
namespace selfname_change_conference_test {
#include "selfname_change_conference_test.c"
}
namespace self_conference_title_change_test {
#include "self_conference_title_change_test.c"
}
namespace simple_conference_test {
#include "simple_conference_test.c"
}
namespace skeleton_test {
#include "skeleton_test.c"
}
namespace toxav_basic_test {
#include "toxav_basic_test.c"
}
namespace toxav_many_test {
#include "toxav_many_test.c"
}
namespace tox_many_tcp_test {
#include "tox_many_tcp_test.c"
}
namespace tox_many_test {
#include "tox_many_test.c"
}
namespace tox_one_test {
#include "tox_one_test.c"
}
namespace tox_strncasecmp_test {
#include "tox_strncasecmp_test.c"
}
namespace tox_test {
#include "tox_test.c"
}
namespace version_test {
#include "version_test.c"
}
int main(int argc, char *argv[])
{

View File

@ -36,7 +36,7 @@ START_TEST(test_addr_resolv_localhost)
IP ip;
ip_init(&ip, 0); // ipv6enabled = 0
int res = addr_resolve(localhost, &ip, NULL);
int res = addr_resolve(localhost, &ip, nullptr);
ck_assert_msg(res > 0, "Resolver failed: %u, %s (%x, %x)", errno, strerror(errno));
@ -47,10 +47,10 @@ START_TEST(test_addr_resolv_localhost)
ip_ntoa(&ip, ip_str, sizeof(ip_str)));
ip_init(&ip, 1); // ipv6enabled = 1
res = addr_resolve(localhost, &ip, NULL);
res = addr_resolve(localhost, &ip, nullptr);
if (!(res & TOX_ADDR_RESOLVE_INET6)) {
res = addr_resolve("ip6-localhost", &ip, NULL);
res = addr_resolve("ip6-localhost", &ip, nullptr);
localhost_split = 1;
}
@ -96,13 +96,13 @@ START_TEST(test_ip_equal)
ip_reset(&ip1);
ip_reset(&ip2);
res = ip_equal(NULL, NULL);
res = ip_equal(nullptr, nullptr);
ck_assert_msg(res == 0, "ip_equal(NULL, NULL): expected result 0, got %u.", res);
res = ip_equal(&ip1, NULL);
res = ip_equal(&ip1, nullptr);
ck_assert_msg(res == 0, "ip_equal(PTR, NULL): expected result 0, got %u.", res);
res = ip_equal(NULL, &ip1);
res = ip_equal(nullptr, &ip1);
ck_assert_msg(res == 0, "ip_equal(NULL, PTR): expected result 0, got %u.", res);
ip1.family = TOX_AF_INET;
@ -165,7 +165,7 @@ static Suite *network_suite(void)
int main(void)
{
srand((unsigned int) time(NULL));
srand((unsigned int) time(nullptr));
Suite *network = network_suite();
SRunner *test_runner = srunner_create(network);

View File

@ -1,4 +1,6 @@
#ifndef _XOPEN_SOURCE
#define _XOPEN_SOURCE 600
#endif
#ifdef HAVE_CONFIG_H
#include "config.h"
@ -37,7 +39,7 @@ static inline IP get_loopback()
}
static void do_onion(Onion *onion)
{
networking_poll(onion->net, NULL);
networking_poll(onion->net, nullptr);
do_DHT(onion->dht);
}
@ -159,9 +161,9 @@ static int handle_test_4(void *object, IP_Port source, const uint8_t *packet, ui
START_TEST(test_basic)
{
IP ip = get_loopback();
Onion *onion1 = new_onion(new_DHT(NULL, new_networking(NULL, ip, 34567), true));
Onion *onion2 = new_onion(new_DHT(NULL, new_networking(NULL, ip, 34568), true));
ck_assert_msg((onion1 != NULL) && (onion2 != NULL), "Onion failed initializing.");
Onion *onion1 = new_onion(new_DHT(nullptr, new_networking(nullptr, ip, 34567), true));
Onion *onion2 = new_onion(new_DHT(nullptr, new_networking(nullptr, ip, 34568), true));
ck_assert_msg((onion1 != nullptr) && (onion2 != nullptr), "Onion failed initializing.");
networking_registerhandler(onion2->net, 'I', &handle_test_1, onion2);
IP_Port on1 = {ip, net_port(onion1->net)};
@ -203,7 +205,7 @@ START_TEST(test_basic)
Onion_Announce *onion1_a = new_onion_announce(onion1->dht);
Onion_Announce *onion2_a = new_onion_announce(onion2->dht);
networking_registerhandler(onion1->net, NET_PACKET_ANNOUNCE_RESPONSE, &handle_test_3, onion1);
ck_assert_msg((onion1_a != NULL) && (onion2_a != NULL), "Onion_Announce failed initializing.");
ck_assert_msg((onion1_a != nullptr) && (onion2_a != nullptr), "Onion_Announce failed initializing.");
uint8_t zeroes[64] = {0};
random_bytes(sb_data, sizeof(sb_data));
uint64_t s;
@ -245,8 +247,8 @@ START_TEST(test_basic)
}
c_sleep(1000);
Onion *onion3 = new_onion(new_DHT(NULL, new_networking(NULL, ip, 34569), true));
ck_assert_msg((onion3 != NULL), "Onion failed initializing.");
Onion *onion3 = new_onion(new_DHT(nullptr, new_networking(nullptr, ip, 34569), true));
ck_assert_msg((onion3 != nullptr), "Onion failed initializing.");
random_nonce(nonce);
ret = send_data_request(onion3->net, &path, nodes[3].ip_port,
@ -310,22 +312,22 @@ static Onions *new_onions(uint16_t port)
Onions *on = (Onions *)malloc(sizeof(Onions));
if (!on) {
return NULL;
return nullptr;
}
Networking_Core *net = new_networking(NULL, ip, port);
Networking_Core *net = new_networking(nullptr, ip, port);
if (!net) {
free(on);
return NULL;
return nullptr;
}
DHT *dht = new_DHT(NULL, net, true);
DHT *dht = new_DHT(nullptr, net, true);
if (!dht) {
kill_networking(net);
free(on);
return NULL;
return nullptr;
}
on->onion = new_onion(dht);
@ -334,7 +336,7 @@ static Onions *new_onions(uint16_t port)
kill_DHT(dht);
kill_networking(net);
free(on);
return NULL;
return nullptr;
}
on->onion_a = new_onion_announce(dht);
@ -344,11 +346,11 @@ static Onions *new_onions(uint16_t port)
kill_DHT(dht);
kill_networking(net);
free(on);
return NULL;
return nullptr;
}
TCP_Proxy_Info inf = {{{0}}};
on->onion_c = new_onion_client(new_net_crypto(NULL, dht, &inf));
on->onion_c = new_onion_client(new_net_crypto(nullptr, dht, &inf));
if (!on->onion_c) {
kill_onion_announce(on->onion_a);
@ -356,7 +358,7 @@ static Onions *new_onions(uint16_t port)
kill_DHT(dht);
kill_networking(net);
free(on);
return NULL;
return nullptr;
}
return on;
@ -364,7 +366,7 @@ static Onions *new_onions(uint16_t port)
static void do_onions(Onions *on)
{
networking_poll(on->onion->net, NULL);
networking_poll(on->onion->net, nullptr);
do_DHT(on->onion->dht);
do_onion_client(on->onion_c);
}
@ -447,7 +449,7 @@ START_TEST(test_announce)
for (i = 0; i < NUM_ONIONS; ++i) {
onions[i] = new_onions(i + 34655);
ck_assert_msg(onions[i] != 0, "Failed to create onions. %u");
ck_assert_msg(onions[i] != nullptr, "Failed to create onions. %u");
}
IP ip = get_loopback();
@ -536,7 +538,7 @@ static Suite *onion_suite(void)
int main(int argc, char *argv[])
{
srand((unsigned int) time(NULL));
srand((unsigned int) time(nullptr));
Suite *onion = onion_suite();
SRunner *test_runner = srunner_create(onion);

View File

@ -27,8 +27,8 @@ int main(void)
// Warm-up.
for (i = 0; i < 10; i++) {
Tox *tox = tox_new(0, 0);
tox_iterate(tox, NULL);
Tox *tox = tox_new(nullptr, nullptr);
tox_iterate(tox, nullptr);
tox_kill(tox);
}
@ -39,8 +39,8 @@ int main(void)
printf("Creating/deleting %d tox instances\n", ITERATIONS);
for (i = 0; i < ITERATIONS; i++) {
Tox *tox = tox_new(0, 0);
tox_iterate(tox, NULL);
Tox *tox = tox_new(nullptr, nullptr);
tox_iterate(tox, nullptr);
tox_kill(tox);
#if HAVE_SBRK
char *next_hwm = (char *)sbrk(0);

View File

@ -1,7 +1,9 @@
/* Auto Tests: Save and load friends.
*/
#ifndef _XOPEN_SOURCE
#define _XOPEN_SOURCE 600
#endif
#include "helpers.h"
#include "../toxcore/ccompat.h"
@ -28,7 +30,7 @@ static void set_random(Tox *m, bool (*setter)(Tox *, const uint8_t *, size_t, TO
text[i] = rand();
}
setter(m, text, SIZEOF_VLA(text), 0);
setter(m, text, SIZEOF_VLA(text), nullptr);
}
void namechange_callback(Tox *tox, uint32_t friend_number, const uint8_t *name, size_t length, void *user_data)
@ -47,16 +49,16 @@ void statuschange_callback(Tox *tox, uint32_t friend_number, const uint8_t *mess
int main(int argc, char *argv[])
{
Tox *tox1 = tox_new_log(0, 0, 0);
Tox *tox2 = tox_new_log(0, 0, 0);
Tox *tox1 = tox_new_log(nullptr, nullptr, nullptr);
Tox *tox2 = tox_new_log(nullptr, nullptr, nullptr);
struct test_data to_compare = { { 0 } };
uint8_t public_key[TOX_PUBLIC_KEY_SIZE];
tox_self_get_public_key(tox1, public_key);
tox_friend_add_norequest(tox2, public_key, NULL);
tox_friend_add_norequest(tox2, public_key, nullptr);
tox_self_get_public_key(tox2, public_key);
tox_friend_add_norequest(tox1, public_key, NULL);
tox_friend_add_norequest(tox1, public_key, nullptr);
uint8_t reference_name[TOX_MAX_NAME_LENGTH] = { 0 };
uint8_t reference_status[TOX_MAX_STATUS_MESSAGE_LENGTH] = { 0 };
@ -75,13 +77,13 @@ int main(int argc, char *argv[])
while (true) {
if (tox_self_get_connection_status(tox1) &&
tox_self_get_connection_status(tox2) &&
tox_friend_get_connection_status(tox1, 0, 0) == TOX_CONNECTION_UDP) {
tox_friend_get_connection_status(tox1, 0, nullptr) == TOX_CONNECTION_UDP) {
printf("Connected.\n");
break;
}
tox_iterate(tox1, &to_compare);
tox_iterate(tox2, NULL);
tox_iterate(tox2, nullptr);
c_sleep(tox_iteration_interval(tox1));
}
@ -93,7 +95,7 @@ int main(int argc, char *argv[])
}
tox_iterate(tox1, &to_compare);
tox_iterate(tox2, NULL);
tox_iterate(tox2, nullptr);
c_sleep(tox_iteration_interval(tox1));
}
@ -102,14 +104,14 @@ int main(int argc, char *argv[])
VLA(uint8_t, savedata, save_size);
tox_get_savedata(tox1, savedata);
struct Tox_Options *options = tox_options_new(NULL);
struct Tox_Options *options = tox_options_new(nullptr);
tox_options_set_savedata_type(options, TOX_SAVEDATA_TYPE_TOX_SAVE);
tox_options_set_savedata_data(options, savedata, save_size);
Tox *tox_to_compare = tox_new(options, 0);
Tox *tox_to_compare = tox_new(options, nullptr);
tox_friend_get_name(tox_to_compare, 0, to_compare.name, 0);
tox_friend_get_status_message(tox_to_compare, 0, to_compare.status_message, 0);
tox_friend_get_name(tox_to_compare, 0, to_compare.name, nullptr);
tox_friend_get_status_message(tox_to_compare, 0, to_compare.status_message, nullptr);
assert(memcmp(reference_name, to_compare.name, TOX_MAX_NAME_LENGTH) == 0);
assert(memcmp(reference_status, to_compare.status_message, TOX_MAX_STATUS_MESSAGE_LENGTH) == 0);

View File

@ -21,7 +21,9 @@
* along with Tox. If not, see <http://www.gnu.org/licenses/>.
*
*/
#define _XOPEN_SOURCE 500
#ifndef _XOPEN_SOURCE
#define _XOPEN_SOURCE 600
#endif
#include <stdio.h>
#include <stdlib.h>
@ -38,7 +40,7 @@ static const char *newtitle = "kitten over darknet";
static void cbtitlechange(Tox *tox, uint32_t conference_number, uint32_t peer_number, const uint8_t *title,
size_t length, void *user_data)
{
if (!memcmp(title, newtitle, tox_conference_get_title_size(tox, conference_number, NULL))) {
if (!memcmp(title, newtitle, tox_conference_get_title_size(tox, conference_number, nullptr))) {
printf("success: title was changed and updated in the conference");
exit(0);
}
@ -47,12 +49,12 @@ static void cbtitlechange(Tox *tox, uint32_t conference_number, uint32_t peer_nu
int main(void)
{
uint32_t conference_number;
struct Tox_Options *to = tox_options_new(NULL);
struct Tox_Options *to = tox_options_new(nullptr);
Tox *t;
TOX_ERR_CONFERENCE_NEW conference_err;
TOX_ERR_CONFERENCE_TITLE title_err;
t = tox_new(to, NULL);
t = tox_new(to, nullptr);
tox_options_free(to);
tox_callback_conference_title(t, &cbtitlechange);
@ -63,7 +65,7 @@ int main(void)
return 2;
}
tox_iterate(t, NULL);
tox_iterate(t, nullptr);
c_sleep(tox_iteration_interval(t));
if (!tox_conference_set_title(t, conference_number, (const uint8_t *)newtitle, strlen(newtitle), &title_err)) {
@ -72,9 +74,9 @@ int main(void)
return 3;
}
tox_iterate(t, NULL);
tox_iterate(t, nullptr);
c_sleep(tox_iteration_interval(t));
tox_iterate(t, NULL);
tox_iterate(t, nullptr);
fprintf(stderr, "error: title was not changed in callback. exiting.\n");

View File

@ -21,7 +21,9 @@
* along with Tox. If not, see <http://www.gnu.org/licenses/>.
*
*/
#define _XOPEN_SOURCE 500
#ifndef _XOPEN_SOURCE
#define _XOPEN_SOURCE 600
#endif
#include <stdio.h>
#include <stdlib.h>
@ -45,11 +47,11 @@ static void cbconfmembers(Tox *tox, uint32_t conference_number, uint32_t peer_nu
return;
}
if (!tox_conference_peer_get_name(tox, conference_number, peer_number, new_peer_name, NULL)) {
if (!tox_conference_peer_get_name(tox, conference_number, peer_number, new_peer_name, nullptr)) {
return;
}
if (!memcmp(newname, new_peer_name, tox_conference_peer_get_name_size(tox, conference_number, peer_number, NULL))) {
if (!memcmp(newname, new_peer_name, tox_conference_peer_get_name_size(tox, conference_number, peer_number, nullptr))) {
printf("success: own name was changed and updated in the conference");
exit(0);
}
@ -57,12 +59,12 @@ static void cbconfmembers(Tox *tox, uint32_t conference_number, uint32_t peer_nu
int main(void)
{
struct Tox_Options *to = tox_options_new(NULL);
struct Tox_Options *to = tox_options_new(nullptr);
Tox *t;
TOX_ERR_CONFERENCE_NEW conference_err;
TOX_ERR_SET_INFO name_err;
t = tox_new(to, NULL);
t = tox_new(to, nullptr);
tox_options_free(to);
tox_callback_conference_namelist_change(t, cbconfmembers);
@ -73,7 +75,7 @@ int main(void)
return 2;
}
tox_iterate(t, NULL);
tox_iterate(t, nullptr);
c_sleep(tox_iteration_interval(t));
if (!tox_self_set_name(t, (const uint8_t *)newname, strlen(newname), &name_err)) {
@ -82,9 +84,9 @@ int main(void)
return 3;
}
tox_iterate(t, NULL);
tox_iterate(t, nullptr);
c_sleep(tox_iteration_interval(t));
tox_iterate(t, NULL);
tox_iterate(t, nullptr);
fprintf(stderr, "error: name was not changed in callback. exiting.\n");

View File

@ -1,4 +1,6 @@
#ifndef _XOPEN_SOURCE
#define _XOPEN_SOURCE 600
#endif
#include "../toxcore/tox.h"
@ -106,20 +108,20 @@ int main()
State state3 = {3};
// Create toxes.
Tox *tox1 = tox_new_log(NULL, NULL, &state1.id);
Tox *tox2 = tox_new_log(NULL, NULL, &state2.id);
Tox *tox3 = tox_new_log(NULL, NULL, &state3.id);
Tox *tox1 = tox_new_log(nullptr, nullptr, &state1.id);
Tox *tox2 = tox_new_log(nullptr, nullptr, &state2.id);
Tox *tox3 = tox_new_log(nullptr, nullptr, &state3.id);
// tox1 <-> tox2, tox2 <-> tox3
uint8_t key[TOX_PUBLIC_KEY_SIZE];
tox_self_get_public_key(tox2, key);
tox_friend_add_norequest(tox1, key, NULL); // tox1 -> tox2
tox_friend_add_norequest(tox1, key, nullptr); // tox1 -> tox2
tox_self_get_public_key(tox1, key);
tox_friend_add_norequest(tox2, key, NULL); // tox2 -> tox1
tox_friend_add_norequest(tox2, key, nullptr); // tox2 -> tox1
tox_self_get_public_key(tox3, key);
tox_friend_add_norequest(tox2, key, NULL); // tox2 -> tox3
tox_friend_add_norequest(tox2, key, nullptr); // tox2 -> tox3
tox_self_get_public_key(tox2, key);
tox_friend_add_norequest(tox3, key, NULL); // tox3 -> tox2
tox_friend_add_norequest(tox3, key, nullptr); // tox3 -> tox2
// Connection callbacks.
tox_callback_self_connection_status(tox1, handle_self_connection_status);

View File

@ -31,7 +31,7 @@ static Suite *creativesuitenamegoeshere_suite(void)
int main(int argc, char *argv[])
{
srand((unsigned int) time(NULL));
srand((unsigned int) time(nullptr));
Suite *creativesuitenamegoeshere = creativesuitenamegoeshere_suite();
SRunner *test_runner = srunner_create(creativesuitenamegoeshere);

View File

@ -1,7 +1,9 @@
/* Auto Tests: Many TCP.
*/
#ifndef _XOPEN_SOURCE
#define _XOPEN_SOURCE 600
#endif
#ifdef HAVE_CONFIG_H
#include "config.h"
@ -33,7 +35,7 @@ static void accept_friend_request(Tox *m, const uint8_t *public_key, const uint8
}
if (length == 7 && memcmp("Gentoo", data, 7) == 0) {
tox_friend_add_norequest(m, public_key, 0);
tox_friend_add_norequest(m, public_key, nullptr);
}
}
@ -43,32 +45,32 @@ static void accept_friend_request(Tox *m, const uint8_t *public_key, const uint8
START_TEST(test_many_clients_tcp)
{
long long unsigned int cur_time = time(NULL);
long long unsigned int cur_time = time(nullptr);
Tox *toxes[NUM_TOXES_TCP];
uint32_t index[NUM_TOXES_TCP];
uint32_t i, j;
uint32_t to_comp = 974536;
for (i = 0; i < NUM_TOXES_TCP; ++i) {
struct Tox_Options *opts = tox_options_new(NULL);
struct Tox_Options *opts = tox_options_new(nullptr);
if (i == 0) {
tox_options_set_tcp_port(opts, TCP_RELAY_PORT);
} else {
tox_options_set_udp_enabled(opts, 0);
tox_options_set_udp_enabled(opts, false);
}
index[i] = i + 1;
toxes[i] = tox_new_log(opts, 0, &index[i]);
ck_assert_msg(toxes[i] != 0, "Failed to create tox instances %u", i);
toxes[i] = tox_new_log(opts, nullptr, &index[i]);
ck_assert_msg(toxes[i] != nullptr, "Failed to create tox instances %u", i);
tox_callback_friend_request(toxes[i], accept_friend_request);
uint8_t dpk[TOX_PUBLIC_KEY_SIZE];
tox_self_get_dht_id(toxes[0], dpk);
TOX_ERR_BOOTSTRAP error = TOX_ERR_BOOTSTRAP_OK;
ck_assert_msg(tox_add_tcp_relay(toxes[i], TOX_LOCALHOST, TCP_RELAY_PORT, dpk, &error), "add relay error, %i, %i", i,
error);
uint16_t first_port = tox_self_get_udp_port(toxes[0], NULL);
ck_assert_msg(tox_bootstrap(toxes[i], TOX_LOCALHOST, first_port, dpk, 0), "Bootstrap error");
uint16_t first_port = tox_self_get_udp_port(toxes[0], nullptr);
ck_assert_msg(tox_bootstrap(toxes[i], TOX_LOCALHOST, first_port, dpk, nullptr), "Bootstrap error");
tox_options_free(opts);
}
@ -119,7 +121,7 @@ loop_top:
for (i = 0; i < NUM_TOXES_TCP; ++i) {
for (j = 0; j < tox_self_get_friend_list_size(toxes[i]); ++j) {
if (tox_friend_get_connection_status(toxes[i], j, 0) == TOX_CONNECTION_TCP) {
if (tox_friend_get_connection_status(toxes[i], j, nullptr) == TOX_CONNECTION_TCP) {
++counter;
}
}
@ -140,7 +142,7 @@ loop_top:
tox_kill(toxes[i]);
}
printf("test_many_clients_tcp succeeded, took %llu seconds\n", time(NULL) - cur_time);
printf("test_many_clients_tcp succeeded, took %llu seconds\n", time(nullptr) - cur_time);
}
END_TEST
@ -148,14 +150,14 @@ END_TEST
START_TEST(test_many_clients_tcp_b)
{
long long unsigned int cur_time = time(NULL);
long long unsigned int cur_time = time(nullptr);
Tox *toxes[NUM_TOXES_TCP];
uint32_t index[NUM_TOXES_TCP];
uint32_t i, j;
uint32_t to_comp = 974536;
for (i = 0; i < NUM_TOXES_TCP; ++i) {
struct Tox_Options *opts = tox_options_new(NULL);
struct Tox_Options *opts = tox_options_new(nullptr);
if (i < NUM_TCP_RELAYS) {
tox_options_set_tcp_port(opts, TCP_RELAY_PORT + i);
@ -164,16 +166,16 @@ START_TEST(test_many_clients_tcp_b)
}
index[i] = i + 1;
toxes[i] = tox_new_log(opts, 0, &index[i]);
ck_assert_msg(toxes[i] != 0, "Failed to create tox instances %u", i);
toxes[i] = tox_new_log(opts, nullptr, &index[i]);
ck_assert_msg(toxes[i] != nullptr, "Failed to create tox instances %u", i);
tox_callback_friend_request(toxes[i], accept_friend_request);
uint8_t dpk[TOX_PUBLIC_KEY_SIZE];
tox_self_get_dht_id(toxes[(i % NUM_TCP_RELAYS)], dpk);
ck_assert_msg(tox_add_tcp_relay(toxes[i], TOX_LOCALHOST, TCP_RELAY_PORT + (i % NUM_TCP_RELAYS), dpk, 0),
ck_assert_msg(tox_add_tcp_relay(toxes[i], TOX_LOCALHOST, TCP_RELAY_PORT + (i % NUM_TCP_RELAYS), dpk, nullptr),
"add relay error");
tox_self_get_dht_id(toxes[0], dpk);
uint16_t first_port = tox_self_get_udp_port(toxes[0], NULL);
ck_assert_msg(tox_bootstrap(toxes[i], TOX_LOCALHOST, first_port, dpk, 0), "Bootstrap error");
uint16_t first_port = tox_self_get_udp_port(toxes[0], nullptr);
ck_assert_msg(tox_bootstrap(toxes[i], TOX_LOCALHOST, first_port, dpk, nullptr), "Bootstrap error");
tox_options_free(opts);
}
@ -226,7 +228,7 @@ loop_top:
for (i = 0; i < NUM_TOXES_TCP; ++i) {
for (j = 0; j < tox_self_get_friend_list_size(toxes[i]); ++j) {
if (tox_friend_get_connection_status(toxes[i], j, 0) == TOX_CONNECTION_TCP) {
if (tox_friend_get_connection_status(toxes[i], j, nullptr) == TOX_CONNECTION_TCP) {
++counter;
}
}
@ -252,7 +254,7 @@ loop_top:
tox_kill(toxes[i]);
}
printf("test_many_clients_tcp_b succeeded, took %llu seconds\n", time(NULL) - cur_time);
printf("test_many_clients_tcp_b succeeded, took %llu seconds\n", time(nullptr) - cur_time);
}
END_TEST
@ -278,7 +280,7 @@ static Suite *tox_suite(void)
int main(int argc, char *argv[])
{
srand((unsigned int) time(NULL));
srand((unsigned int) time(nullptr));
Suite *tox = tox_suite();
SRunner *test_runner = srunner_create(tox);

View File

@ -1,7 +1,9 @@
/* Auto Tests: Many clients.
*/
#ifndef _XOPEN_SOURCE
#define _XOPEN_SOURCE 600
#endif
#ifdef HAVE_CONFIG_H
#include "config.h"
@ -25,7 +27,7 @@ static void accept_friend_request(Tox *m, const uint8_t *public_key, const uint8
}
if (length == 7 && memcmp("Gentoo", data, 7) == 0) {
tox_friend_add_norequest(m, public_key, 0);
tox_friend_add_norequest(m, public_key, nullptr);
}
}
@ -35,7 +37,7 @@ static void accept_friend_request(Tox *m, const uint8_t *public_key, const uint8
START_TEST(test_many_clients)
{
long long unsigned int cur_time = time(NULL);
long long unsigned int cur_time = time(nullptr);
Tox *toxes[NUM_TOXES];
uint32_t index[NUM_TOXES];
uint32_t i, j;
@ -43,8 +45,8 @@ START_TEST(test_many_clients)
for (i = 0; i < NUM_TOXES; ++i) {
index[i] = i + 1;
toxes[i] = tox_new_log(0, 0, &index[i]);
ck_assert_msg(toxes[i] != 0, "Failed to create tox instances %u", i);
toxes[i] = tox_new_log(nullptr, nullptr, &index[i]);
ck_assert_msg(toxes[i] != nullptr, "Failed to create tox instances %u", i);
tox_callback_friend_request(toxes[i], accept_friend_request);
}
@ -107,7 +109,7 @@ loop_top:
for (i = 0; i < NUM_TOXES; ++i) {
for (j = 0; j < tox_self_get_friend_list_size(toxes[i]); ++j) {
if (tox_friend_get_connection_status(toxes[i], j, 0) == TOX_CONNECTION_UDP) {
if (tox_friend_get_connection_status(toxes[i], j, nullptr) == TOX_CONNECTION_UDP) {
++counter;
}
}
@ -133,7 +135,7 @@ loop_top:
tox_kill(toxes[i]);
}
printf("test_many_clients succeeded, took %llu seconds\n", time(NULL) - cur_time);
printf("test_many_clients succeeded, took %llu seconds\n", time(nullptr) - cur_time);
}
END_TEST
@ -154,7 +156,7 @@ static Suite *tox_suite(void)
int main(int argc, char *argv[])
{
srand((unsigned int) time(NULL));
srand((unsigned int) time(nullptr));
Suite *tox = tox_suite();
SRunner *test_runner = srunner_create(tox);

View File

@ -38,9 +38,9 @@ START_TEST(test_one)
uint8_t status_message2[TOX_MAX_STATUS_MESSAGE_LENGTH];
uint32_t index[] = { 1, 2 };
Tox *tox1 = tox_new_log(0, 0, &index[0]);
Tox *tox1 = tox_new_log(nullptr, nullptr, &index[0]);
set_random_name_and_status_message(tox1, name, status_message);
Tox *tox2 = tox_new_log(0, 0, &index[1]);
Tox *tox2 = tox_new_log(nullptr, nullptr, &index[1]);
set_random_name_and_status_message(tox2, name2, status_message2);
uint8_t address[TOX_ADDRESS_SIZE];
@ -51,7 +51,7 @@ START_TEST(test_one)
tox_self_get_address(tox2, address);
uint8_t message[TOX_MAX_FRIEND_REQUEST_LENGTH + 1];
ret = tox_friend_add(tox1, address, NULL, 0, &error);
ret = tox_friend_add(tox1, address, nullptr, 0, &error);
ck_assert_msg(ret == UINT32_MAX && error == TOX_ERR_FRIEND_ADD_NULL, "Sending request with no message worked.");
ret = tox_friend_add(tox1, address, message, 0, &error);
ck_assert_msg(ret == UINT32_MAX && error == TOX_ERR_FRIEND_ADD_NO_MESSAGE, "Sending request with no message worked.");
@ -70,10 +70,10 @@ START_TEST(test_one)
ret = tox_friend_add(tox1, address, message, TOX_MAX_FRIEND_REQUEST_LENGTH, &error);
ck_assert_msg(ret == UINT32_MAX && error == TOX_ERR_FRIEND_ADD_ALREADY_SENT, "Adding friend twice worked.");
tox_self_set_name(tox1, name, sizeof(name), 0);
tox_self_set_name(tox1, name, sizeof(name), nullptr);
ck_assert_msg(tox_self_get_name_size(tox1) == sizeof(name), "Can't set name of TOX_MAX_NAME_LENGTH");
tox_self_set_status_message(tox1, status_message, sizeof(status_message), 0);
tox_self_set_status_message(tox1, status_message, sizeof(status_message), nullptr);
ck_assert_msg(tox_self_get_status_message_size(tox1) == sizeof(status_message),
"Can't set status message of TOX_MAX_STATUS_MESSAGE_LENGTH");
@ -85,7 +85,7 @@ START_TEST(test_one)
tox_kill(tox2);
TOX_ERR_NEW err_n;
struct Tox_Options *options = tox_options_new(NULL);
struct Tox_Options *options = tox_options_new(nullptr);
tox_options_set_savedata_type(options, TOX_SAVEDATA_TYPE_TOX_SAVE);
tox_options_set_savedata_data(options, data, save_size);
tox2 = tox_new_log(options, &err_n, &index[1]);
@ -151,7 +151,7 @@ static Suite *tox_suite(void)
int main(int argc, char *argv[])
{
srand((unsigned int) time(NULL));
srand((unsigned int) time(nullptr));
Suite *tox = tox_suite();
SRunner *test_runner = srunner_create(tox);

View File

@ -179,7 +179,7 @@ static Suite *tox_strncasecmp_suite(void)
int main(int argc, char *argv[])
{
srand((unsigned int) time(NULL));
srand((unsigned int) time(nullptr));
Suite *s = tox_strncasecmp_suite();
SRunner *test_runner = srunner_create(s);

View File

@ -10,7 +10,9 @@
*
*/
#ifndef _XOPEN_SOURCE
#define _XOPEN_SOURCE 600
#endif
#ifdef HAVE_CONFIG_H
#include "config.h"
@ -43,7 +45,7 @@ static void accept_friend_request(Tox *m, const uint8_t *public_key, const uint8
}
if (length == 7 && memcmp("Gentoo", data, 7) == 0) {
tox_friend_add_norequest(m, public_key, 0);
tox_friend_add_norequest(m, public_key, nullptr);
}
}
static uint32_t messages_received;
@ -154,7 +156,7 @@ static void tox_file_receive(Tox *tox, uint32_t friend_number, uint32_t file_num
uint8_t file_id[TOX_FILE_ID_LENGTH];
if (!tox_file_get_file_id(tox, friend_number, file_number, file_id, 0)) {
if (!tox_file_get_file_id(tox, friend_number, file_number, file_id, nullptr)) {
ck_abort_msg("tox_file_get_file_id error");
}
@ -318,13 +320,13 @@ static void tox_connection_status(Tox *tox, TOX_CONNECTION connection_status, vo
START_TEST(test_few_clients)
{
uint32_t index[] = { 1, 2, 3 };
long long unsigned int con_time = 0, cur_time = time(NULL);
long long unsigned int con_time = 0, cur_time = time(nullptr);
TOX_ERR_NEW t_n_error;
Tox *tox1 = tox_new_log(0, &t_n_error, &index[0]);
Tox *tox1 = tox_new_log(nullptr, &t_n_error, &index[0]);
ck_assert_msg(t_n_error == TOX_ERR_NEW_OK, "wrong error");
Tox *tox2 = tox_new_log(0, &t_n_error, &index[1]);
Tox *tox2 = tox_new_log(nullptr, &t_n_error, &index[1]);
ck_assert_msg(t_n_error == TOX_ERR_NEW_OK, "wrong error");
Tox *tox3 = tox_new_log(0, &t_n_error, &index[2]);
Tox *tox3 = tox_new_log(nullptr, &t_n_error, &index[2]);
ck_assert_msg(t_n_error == TOX_ERR_NEW_OK, "wrong error");
ck_assert_msg(tox1 && tox2 && tox3, "Failed to create 3 tox instances");
@ -351,7 +353,7 @@ START_TEST(test_few_clients)
tox_callback_friend_request(tox2, accept_friend_request);
uint8_t address[TOX_ADDRESS_SIZE];
tox_self_get_address(tox2, address);
uint32_t test = tox_friend_add(tox3, address, (const uint8_t *)"Gentoo", 7, 0);
uint32_t test = tox_friend_add(tox3, address, (const uint8_t *)"Gentoo", 7, nullptr);
ck_assert_msg(test == 0, "Failed to add friend error code: %i", test);
uint8_t off = 1;
@ -364,13 +366,13 @@ START_TEST(test_few_clients)
if (tox_self_get_connection_status(tox1) && tox_self_get_connection_status(tox2)
&& tox_self_get_connection_status(tox3)) {
if (off) {
printf("Toxes are online, took %llu seconds\n", time(NULL) - cur_time);
con_time = time(NULL);
printf("Toxes are online, took %llu seconds\n", time(nullptr) - cur_time);
con_time = time(nullptr);
off = 0;
}
if (tox_friend_get_connection_status(tox2, 0, 0) == TOX_CONNECTION_UDP
&& tox_friend_get_connection_status(tox3, 0, 0) == TOX_CONNECTION_UDP) {
if (tox_friend_get_connection_status(tox2, 0, nullptr) == TOX_CONNECTION_UDP
&& tox_friend_get_connection_status(tox3, 0, nullptr) == TOX_CONNECTION_UDP) {
break;
}
}
@ -379,7 +381,7 @@ START_TEST(test_few_clients)
}
ck_assert_msg(connected_t1, "Tox1 isn't connected. %u", connected_t1);
printf("tox clients connected took %llu seconds\n", time(NULL) - con_time);
printf("tox clients connected took %llu seconds\n", time(nullptr) - con_time);
to_compare = 974536;
tox_callback_friend_message(tox3, print_message);
uint8_t msgs[TOX_MAX_MESSAGE_LENGTH + 1];
@ -412,11 +414,11 @@ START_TEST(test_few_clients)
tox_get_savedata(tox2, save1);
tox_kill(tox2);
struct Tox_Options *options = tox_options_new(NULL);
struct Tox_Options *options = tox_options_new(nullptr);
tox_options_set_savedata_type(options, TOX_SAVEDATA_TYPE_TOX_SAVE);
tox_options_set_savedata_data(options, save1, save_size1);
tox2 = tox_new_log(options, NULL, &index[1]);
cur_time = time(NULL);
tox2 = tox_new_log(options, nullptr, &index[1]);
cur_time = time(nullptr);
off = 1;
while (1) {
@ -427,13 +429,13 @@ START_TEST(test_few_clients)
if (tox_self_get_connection_status(tox1) && tox_self_get_connection_status(tox2)
&& tox_self_get_connection_status(tox3)) {
if (off) {
printf("Toxes are online again after reloading, took %llu seconds\n", time(NULL) - cur_time);
con_time = time(NULL);
printf("Toxes are online again after reloading, took %llu seconds\n", time(nullptr) - cur_time);
con_time = time(nullptr);
off = 0;
}
if (tox_friend_get_connection_status(tox2, 0, 0) == TOX_CONNECTION_UDP
&& tox_friend_get_connection_status(tox3, 0, 0) == TOX_CONNECTION_UDP) {
if (tox_friend_get_connection_status(tox2, 0, nullptr) == TOX_CONNECTION_UDP
&& tox_friend_get_connection_status(tox3, 0, nullptr) == TOX_CONNECTION_UDP) {
break;
}
}
@ -441,7 +443,7 @@ START_TEST(test_few_clients)
c_sleep(50);
}
printf("tox clients connected took %llu seconds\n", time(NULL) - con_time);
printf("tox clients connected took %llu seconds\n", time(nullptr) - con_time);
tox_callback_friend_name(tox3, print_nickchange);
TOX_ERR_SET_INFO err_n;
bool succ = tox_self_set_name(tox2, (const uint8_t *)"Gentoo", sizeof("Gentoo"), &err_n);
@ -460,9 +462,9 @@ START_TEST(test_few_clients)
c_sleep(50);
}
ck_assert_msg(tox_friend_get_name_size(tox3, 0, 0) == sizeof("Gentoo"), "Name length not correct");
ck_assert_msg(tox_friend_get_name_size(tox3, 0, nullptr) == sizeof("Gentoo"), "Name length not correct");
uint8_t temp_name[sizeof("Gentoo")];
tox_friend_get_name(tox3, 0, temp_name, 0);
tox_friend_get_name(tox3, 0, temp_name, nullptr);
ck_assert_msg(memcmp(temp_name, "Gentoo", sizeof("Gentoo")) == 0, "Name not correct");
tox_callback_friend_status_message(tox3, print_status_m_change);
@ -482,15 +484,15 @@ START_TEST(test_few_clients)
c_sleep(50);
}
ck_assert_msg(tox_friend_get_status_message_size(tox3, 0, 0) == sizeof("Installing Gentoo"),
ck_assert_msg(tox_friend_get_status_message_size(tox3, 0, nullptr) == sizeof("Installing Gentoo"),
"status message length not correct");
uint8_t temp_status_m[sizeof("Installing Gentoo")];
tox_friend_get_status_message(tox3, 0, temp_status_m, 0);
tox_friend_get_status_message(tox3, 0, temp_status_m, nullptr);
ck_assert_msg(memcmp(temp_status_m, "Installing Gentoo", sizeof("Installing Gentoo")) == 0,
"status message not correct");
tox_callback_friend_typing(tox2, &print_typingchange);
tox_self_set_typing(tox3, 0, 1, 0);
tox_self_set_typing(tox3, 0, 1, nullptr);
while (1) {
typing_changes = 0;
@ -507,8 +509,8 @@ START_TEST(test_few_clients)
c_sleep(50);
}
ck_assert_msg(tox_friend_get_typing(tox2, 0, 0) == 1, "Typing fail");
tox_self_set_typing(tox3, 0, 0, 0);
ck_assert_msg(tox_friend_get_typing(tox2, 0, nullptr) == 1, "Typing fail");
tox_self_set_typing(tox3, 0, 0, nullptr);
while (1) {
typing_changes = 0;
@ -533,9 +535,9 @@ START_TEST(test_few_clients)
tox_callback_friend_lossless_packet(tox3, &handle_custom_packet);
uint8_t data_c[TOX_MAX_CUSTOM_PACKET_SIZE + 1];
memset(data_c, ((uint8_t)packet_number), sizeof(data_c));
int ret = tox_friend_send_lossless_packet(tox2, 0, data_c, sizeof(data_c), 0);
int ret = tox_friend_send_lossless_packet(tox2, 0, data_c, sizeof(data_c), nullptr);
ck_assert_msg(ret == 0, "tox_friend_send_lossless_packet bigger fail %i", ret);
ret = tox_friend_send_lossless_packet(tox2, 0, data_c, TOX_MAX_CUSTOM_PACKET_SIZE, 0);
ret = tox_friend_send_lossless_packet(tox2, 0, data_c, TOX_MAX_CUSTOM_PACKET_SIZE, nullptr);
ck_assert_msg(ret == 1, "tox_friend_send_lossless_packet fail %i", ret);
while (1) {
@ -556,9 +558,9 @@ START_TEST(test_few_clients)
packet_number = 200;
tox_callback_friend_lossy_packet(tox3, &handle_custom_packet);
memset(data_c, ((uint8_t)packet_number), sizeof(data_c));
ret = tox_friend_send_lossy_packet(tox2, 0, data_c, sizeof(data_c), 0);
ret = tox_friend_send_lossy_packet(tox2, 0, data_c, sizeof(data_c), nullptr);
ck_assert_msg(ret == 0, "tox_friend_send_lossy_packet bigger fail %i", ret);
ret = tox_friend_send_lossy_packet(tox2, 0, data_c, TOX_MAX_CUSTOM_PACKET_SIZE, 0);
ret = tox_friend_send_lossy_packet(tox2, 0, data_c, TOX_MAX_CUSTOM_PACKET_SIZE, nullptr);
ck_assert_msg(ret == 1, "tox_friend_send_lossy_packet fail %i", ret);
while (1) {
@ -581,15 +583,15 @@ START_TEST(test_few_clients)
file_accepted = file_size = sendf_ok = size_recv = 0;
file_recv = 0;
max_sending = UINT64_MAX;
long long unsigned int f_time = time(NULL);
long long unsigned int f_time = time(nullptr);
tox_callback_file_recv_chunk(tox3, write_file);
tox_callback_file_recv_control(tox2, file_print_control);
tox_callback_file_chunk_request(tox2, tox_file_chunk_request);
tox_callback_file_recv_control(tox3, file_print_control);
tox_callback_file_recv(tox3, tox_file_receive);
uint64_t totalf_size = 100 * 1024 * 1024;
uint32_t fnum = tox_file_send(tox2, 0, TOX_FILE_KIND_DATA, totalf_size, 0, (const uint8_t *)"Gentoo.exe",
sizeof("Gentoo.exe"), 0);
uint32_t fnum = tox_file_send(tox2, 0, TOX_FILE_KIND_DATA, totalf_size, nullptr, (const uint8_t *)"Gentoo.exe",
sizeof("Gentoo.exe"), nullptr);
ck_assert_msg(fnum != UINT32_MAX, "tox_new_file_sender fail");
TOX_ERR_FILE_GET gfierr;
@ -623,7 +625,7 @@ START_TEST(test_few_clients)
c_sleep(MIN(tox1_interval, MIN(tox2_interval, tox3_interval)));
}
printf("100MB file sent in %llu seconds\n", time(NULL) - f_time);
printf("100MB file sent in %llu seconds\n", time(nullptr) - f_time);
printf("Starting file streaming transfer test.\n");
@ -635,8 +637,8 @@ START_TEST(test_few_clients)
tox_callback_file_recv_control(tox3, file_print_control);
tox_callback_file_recv(tox3, tox_file_receive);
totalf_size = UINT64_MAX;
fnum = tox_file_send(tox2, 0, TOX_FILE_KIND_DATA, totalf_size, 0, (const uint8_t *)"Gentoo.exe", sizeof("Gentoo.exe"),
0);
fnum = tox_file_send(tox2, 0, TOX_FILE_KIND_DATA, totalf_size, nullptr,
(const uint8_t *)"Gentoo.exe", sizeof("Gentoo.exe"), nullptr);
ck_assert_msg(fnum != UINT32_MAX, "tox_new_file_sender fail");
ck_assert_msg(!tox_file_get_file_id(tox2, 1, fnum, file_cmp_id, &gfierr), "tox_file_get_file_id didn't fail");
@ -683,8 +685,8 @@ START_TEST(test_few_clients)
tox_callback_file_recv_control(tox3, file_print_control);
tox_callback_file_recv(tox3, tox_file_receive);
totalf_size = 0;
fnum = tox_file_send(tox2, 0, TOX_FILE_KIND_DATA, totalf_size, 0, (const uint8_t *)"Gentoo.exe", sizeof("Gentoo.exe"),
0);
fnum = tox_file_send(tox2, 0, TOX_FILE_KIND_DATA, totalf_size, nullptr,
(const uint8_t *)"Gentoo.exe", sizeof("Gentoo.exe"), nullptr);
ck_assert_msg(fnum != UINT32_MAX, "tox_new_file_sender fail");
ck_assert_msg(!tox_file_get_file_id(tox2, 1, fnum, file_cmp_id, &gfierr), "tox_file_get_file_id didn't fail");
@ -717,7 +719,7 @@ START_TEST(test_few_clients)
c_sleep(MIN(tox1_interval, MIN(tox2_interval, tox3_interval)));
}
printf("test_few_clients succeeded, took %llu seconds\n", time(NULL) - cur_time);
printf("test_few_clients succeeded, took %llu seconds\n", time(nullptr) - cur_time);
tox_options_free(options);
tox_kill(tox1);
@ -743,7 +745,7 @@ static Suite *tox_suite(void)
int main(int argc, char *argv[])
{
srand((unsigned int) time(NULL));
srand((unsigned int) time(nullptr));
Suite *tox = tox_suite();
SRunner *test_runner = srunner_create(tox);

View File

@ -1,4 +1,6 @@
#ifndef _XOPEN_SOURCE
#define _XOPEN_SOURCE 600
#endif
#ifdef HAVE_CONFIG_H
#include "config.h"
@ -112,7 +114,7 @@ static void t_accept_friend_request_cb(Tox *m, const uint8_t *public_key, const
(void) userdata;
if (length == 7 && memcmp("gentoo", data, 7) == 0) {
ck_assert(tox_friend_add_norequest(m, public_key, NULL) != (uint32_t) ~0);
ck_assert(tox_friend_add_norequest(m, public_key, nullptr) != (uint32_t) ~0);
}
}
@ -123,9 +125,9 @@ static void t_accept_friend_request_cb(Tox *m, const uint8_t *public_key, const
static int iterate_tox(Tox *bootstrap, Tox *Alice, Tox *Bob)
{
c_sleep(100);
tox_iterate(bootstrap, NULL);
tox_iterate(Alice, NULL);
tox_iterate(Bob, NULL);
tox_iterate(bootstrap, nullptr);
tox_iterate(Alice, nullptr);
tox_iterate(Bob, nullptr);
return MIN(tox_iteration_interval(Alice), tox_iteration_interval(Bob));
}
@ -143,19 +145,19 @@ START_TEST(test_AV_flows)
{
TOX_ERR_NEW error;
bootstrap = tox_new_log(NULL, &error, &index[0]);
bootstrap = tox_new_log(nullptr, &error, &index[0]);
ck_assert(error == TOX_ERR_NEW_OK);
Alice = tox_new_log(NULL, &error, &index[1]);
Alice = tox_new_log(nullptr, &error, &index[1]);
ck_assert(error == TOX_ERR_NEW_OK);
Bob = tox_new_log(NULL, &error, &index[2]);
Bob = tox_new_log(nullptr, &error, &index[2]);
ck_assert(error == TOX_ERR_NEW_OK);
}
printf("Created 3 instances of Tox\n");
printf("Preparing network...\n");
long long unsigned int cur_time = time(NULL);
long long unsigned int cur_time = time(nullptr);
uint8_t address[TOX_ADDRESS_SIZE];
@ -163,7 +165,7 @@ START_TEST(test_AV_flows)
tox_self_get_address(Alice, address);
ck_assert(tox_friend_add(Bob, address, (const uint8_t *)"gentoo", 7, NULL) != (uint32_t) ~0);
ck_assert(tox_friend_add(Bob, address, (const uint8_t *)"gentoo", 7, nullptr) != (uint32_t) ~0);
uint8_t off = 1;
@ -173,12 +175,12 @@ START_TEST(test_AV_flows)
if (tox_self_get_connection_status(bootstrap) &&
tox_self_get_connection_status(Alice) &&
tox_self_get_connection_status(Bob) && off) {
printf("Toxes are online, took %llu seconds\n", time(NULL) - cur_time);
printf("Toxes are online, took %llu seconds\n", time(nullptr) - cur_time);
off = 0;
}
if (tox_friend_get_connection_status(Alice, 0, NULL) == TOX_CONNECTION_UDP &&
tox_friend_get_connection_status(Bob, 0, NULL) == TOX_CONNECTION_UDP) {
if (tox_friend_get_connection_status(Alice, 0, nullptr) == TOX_CONNECTION_UDP &&
tox_friend_get_connection_status(Bob, 0, nullptr) == TOX_CONNECTION_UDP) {
break;
}
@ -206,7 +208,7 @@ START_TEST(test_AV_flows)
toxav_callback_audio_receive_frame(BobAV, t_toxav_receive_audio_frame_cb, &BobCC);
printf("Created 2 instances of ToxAV\n");
printf("All set after %llu seconds!\n", time(NULL) - cur_time);
printf("All set after %llu seconds!\n", time(nullptr) - cur_time);
#define REGULAR_CALL_FLOW(A_BR, V_BR) \
@ -223,7 +225,7 @@ START_TEST(test_AV_flows)
} \
\
\
long long unsigned int start_time = time(NULL); \
long long unsigned int start_time = time(nullptr); \
\
\
while (BobCC.state != TOXAV_FRIEND_CALL_STATE_FINISHED) { \
@ -240,7 +242,7 @@ START_TEST(test_AV_flows)
} else { \
/* TODO(mannol): rtp */ \
\
if (time(NULL) - start_time >= 1) { \
if (time(nullptr) - start_time >= 1) { \
\
TOXAV_ERR_CALL_CONTROL cc_err; \
toxav_call_control(AliceAV, 0, TOXAV_CALL_CONTROL_CANCEL, &cc_err); \
@ -373,12 +375,12 @@ START_TEST(test_AV_flows)
}
/* At first try all stuff while in invalid state */
ck_assert(!toxav_call_control(AliceAV, 0, TOXAV_CALL_CONTROL_PAUSE, NULL));
ck_assert(!toxav_call_control(AliceAV, 0, TOXAV_CALL_CONTROL_RESUME, NULL));
ck_assert(!toxav_call_control(AliceAV, 0, TOXAV_CALL_CONTROL_MUTE_AUDIO, NULL));
ck_assert(!toxav_call_control(AliceAV, 0, TOXAV_CALL_CONTROL_UNMUTE_AUDIO, NULL));
ck_assert(!toxav_call_control(AliceAV, 0, TOXAV_CALL_CONTROL_HIDE_VIDEO, NULL));
ck_assert(!toxav_call_control(AliceAV, 0, TOXAV_CALL_CONTROL_SHOW_VIDEO, NULL));
ck_assert(!toxav_call_control(AliceAV, 0, TOXAV_CALL_CONTROL_PAUSE, nullptr));
ck_assert(!toxav_call_control(AliceAV, 0, TOXAV_CALL_CONTROL_RESUME, nullptr));
ck_assert(!toxav_call_control(AliceAV, 0, TOXAV_CALL_CONTROL_MUTE_AUDIO, nullptr));
ck_assert(!toxav_call_control(AliceAV, 0, TOXAV_CALL_CONTROL_UNMUTE_AUDIO, nullptr));
ck_assert(!toxav_call_control(AliceAV, 0, TOXAV_CALL_CONTROL_HIDE_VIDEO, nullptr));
ck_assert(!toxav_call_control(AliceAV, 0, TOXAV_CALL_CONTROL_SHOW_VIDEO, nullptr));
{
TOXAV_ERR_ANSWER rc;
@ -476,19 +478,19 @@ START_TEST(test_AV_flows)
printf("Call started as audio only\n");
printf("Turning on video for Alice...\n");
ck_assert(toxav_video_set_bit_rate(AliceAV, 0, 1000, NULL));
ck_assert(toxav_video_set_bit_rate(AliceAV, 0, 1000, nullptr));
iterate_tox(bootstrap, Alice, Bob);
ck_assert(BobCC.state & TOXAV_FRIEND_CALL_STATE_SENDING_V);
printf("Turning off video for Alice...\n");
ck_assert(toxav_video_set_bit_rate(AliceAV, 0, 0, NULL));
ck_assert(toxav_video_set_bit_rate(AliceAV, 0, 0, nullptr));
iterate_tox(bootstrap, Alice, Bob);
ck_assert(!(BobCC.state & TOXAV_FRIEND_CALL_STATE_SENDING_V));
printf("Turning off audio for Alice...\n");
ck_assert(toxav_audio_set_bit_rate(AliceAV, 0, 0, NULL));
ck_assert(toxav_audio_set_bit_rate(AliceAV, 0, 0, nullptr));
iterate_tox(bootstrap, Alice, Bob);
ck_assert(!(BobCC.state & TOXAV_FRIEND_CALL_STATE_SENDING_A));
@ -545,12 +547,12 @@ START_TEST(test_AV_flows)
iterate_tox(bootstrap, Alice, Bob);
ck_assert_call_control(AliceAV, 0, TOXAV_CALL_CONTROL_PAUSE);
iterate_tox(bootstrap, Alice, Bob);
ck_assert(!toxav_audio_send_frame(AliceAV, 0, PCM, 960, 1, 48000, NULL));
ck_assert(!toxav_audio_send_frame(BobAV, 0, PCM, 960, 1, 48000, NULL));
ck_assert(!toxav_audio_send_frame(AliceAV, 0, PCM, 960, 1, 48000, nullptr));
ck_assert(!toxav_audio_send_frame(BobAV, 0, PCM, 960, 1, 48000, nullptr));
ck_assert_call_control(AliceAV, 0, TOXAV_CALL_CONTROL_RESUME);
iterate_tox(bootstrap, Alice, Bob);
ck_assert(toxav_audio_send_frame(AliceAV, 0, PCM, 960, 1, 48000, NULL));
ck_assert(toxav_audio_send_frame(BobAV, 0, PCM, 960, 1, 48000, NULL));
ck_assert(toxav_audio_send_frame(AliceAV, 0, PCM, 960, 1, 48000, nullptr));
ck_assert(toxav_audio_send_frame(BobAV, 0, PCM, 960, 1, 48000, nullptr));
iterate_tox(bootstrap, Alice, Bob);
{
@ -594,7 +596,7 @@ int main(int argc, char *argv[])
Suite *tox = tox_suite();
SRunner *test_runner = srunner_create(tox);
setbuf(stdout, NULL);
setbuf(stdout, nullptr);
srunner_run_all(test_runner, CK_NORMAL);
int number_failed = srunner_ntests_failed(test_runner);

View File

@ -1,4 +1,6 @@
#ifndef _XOPEN_SOURCE
#define _XOPEN_SOURCE 600
#endif
#ifdef HAVE_CONFIG_H
#include "config.h"
@ -96,7 +98,7 @@ static void t_accept_friend_request_cb(Tox *m, const uint8_t *public_key, const
(void) userdata;
if (length == 7 && memcmp("gentoo", data, 7) == 0) {
ck_assert(tox_friend_add_norequest(m, public_key, NULL) != (uint32_t) ~0);
ck_assert(tox_friend_add_norequest(m, public_key, nullptr) != (uint32_t) ~0);
}
}
@ -160,17 +162,17 @@ static void *call_thread(void *pd)
uint8_t *video_u = (uint8_t *)calloc(800 * 600 / 4, sizeof(uint8_t));
uint8_t *video_v = (uint8_t *)calloc(800 * 600 / 4, sizeof(uint8_t));
time_t start_time = time(NULL);
time_t start_time = time(nullptr);
while (time(NULL) - start_time < 4) {
while (time(nullptr) - start_time < 4) {
toxav_iterate(AliceAV);
toxav_iterate(BobAV);
toxav_audio_send_frame(AliceAV, friend_number, PCM, 960, 1, 48000, NULL);
toxav_audio_send_frame(BobAV, 0, PCM, 960, 1, 48000, NULL);
toxav_audio_send_frame(AliceAV, friend_number, PCM, 960, 1, 48000, nullptr);
toxav_audio_send_frame(BobAV, 0, PCM, 960, 1, 48000, nullptr);
toxav_video_send_frame(AliceAV, friend_number, 800, 600, video_y, video_u, video_v, NULL);
toxav_video_send_frame(BobAV, 0, 800, 600, video_y, video_u, video_v, NULL);
toxav_video_send_frame(AliceAV, friend_number, 800, 600, video_y, video_u, video_v, nullptr);
toxav_video_send_frame(BobAV, 0, 800, 600, video_y, video_u, video_v, nullptr);
c_sleep(10);
}
@ -192,7 +194,7 @@ static void *call_thread(void *pd)
free(video_v);
printf("Closing thread\n");
pthread_exit(NULL);
pthread_exit(nullptr);
}
@ -208,25 +210,25 @@ START_TEST(test_AV_three_calls)
{
TOX_ERR_NEW error;
bootstrap = tox_new_log(NULL, &error, &index[0]);
bootstrap = tox_new_log(nullptr, &error, &index[0]);
ck_assert(error == TOX_ERR_NEW_OK);
Alice = tox_new_log(NULL, &error, &index[1]);
Alice = tox_new_log(nullptr, &error, &index[1]);
ck_assert(error == TOX_ERR_NEW_OK);
Bobs[0] = tox_new_log(NULL, &error, &index[2]);
Bobs[0] = tox_new_log(nullptr, &error, &index[2]);
ck_assert(error == TOX_ERR_NEW_OK);
Bobs[1] = tox_new_log(NULL, &error, &index[3]);
Bobs[1] = tox_new_log(nullptr, &error, &index[3]);
ck_assert(error == TOX_ERR_NEW_OK);
Bobs[2] = tox_new_log(NULL, &error, &index[4]);
Bobs[2] = tox_new_log(nullptr, &error, &index[4]);
ck_assert(error == TOX_ERR_NEW_OK);
}
printf("Created 5 instances of Tox\n");
printf("Preparing network...\n");
long long unsigned int cur_time = time(NULL);
long long unsigned int cur_time = time(nullptr);
uint8_t address[TOX_ADDRESS_SIZE];
@ -234,34 +236,34 @@ START_TEST(test_AV_three_calls)
tox_self_get_address(Alice, address);
ck_assert(tox_friend_add(Bobs[0], address, (const uint8_t *)"gentoo", 7, NULL) != (uint32_t) ~0);
ck_assert(tox_friend_add(Bobs[1], address, (const uint8_t *)"gentoo", 7, NULL) != (uint32_t) ~0);
ck_assert(tox_friend_add(Bobs[2], address, (const uint8_t *)"gentoo", 7, NULL) != (uint32_t) ~0);
ck_assert(tox_friend_add(Bobs[0], address, (const uint8_t *)"gentoo", 7, nullptr) != (uint32_t) ~0);
ck_assert(tox_friend_add(Bobs[1], address, (const uint8_t *)"gentoo", 7, nullptr) != (uint32_t) ~0);
ck_assert(tox_friend_add(Bobs[2], address, (const uint8_t *)"gentoo", 7, nullptr) != (uint32_t) ~0);
uint8_t off = 1;
while (1) {
tox_iterate(bootstrap, NULL);
tox_iterate(Alice, NULL);
tox_iterate(Bobs[0], NULL);
tox_iterate(Bobs[1], NULL);
tox_iterate(Bobs[2], NULL);
tox_iterate(bootstrap, nullptr);
tox_iterate(Alice, nullptr);
tox_iterate(Bobs[0], nullptr);
tox_iterate(Bobs[1], nullptr);
tox_iterate(Bobs[2], nullptr);
if (tox_self_get_connection_status(bootstrap) &&
tox_self_get_connection_status(Alice) &&
tox_self_get_connection_status(Bobs[0]) &&
tox_self_get_connection_status(Bobs[1]) &&
tox_self_get_connection_status(Bobs[2]) && off) {
printf("Toxes are online, took %llu seconds\n", time(NULL) - cur_time);
printf("Toxes are online, took %llu seconds\n", time(nullptr) - cur_time);
off = 0;
}
if (tox_friend_get_connection_status(Alice, 0, NULL) == TOX_CONNECTION_UDP &&
tox_friend_get_connection_status(Alice, 1, NULL) == TOX_CONNECTION_UDP &&
tox_friend_get_connection_status(Alice, 2, NULL) == TOX_CONNECTION_UDP &&
tox_friend_get_connection_status(Bobs[0], 0, NULL) == TOX_CONNECTION_UDP &&
tox_friend_get_connection_status(Bobs[1], 0, NULL) == TOX_CONNECTION_UDP &&
tox_friend_get_connection_status(Bobs[2], 0, NULL) == TOX_CONNECTION_UDP) {
if (tox_friend_get_connection_status(Alice, 0, nullptr) == TOX_CONNECTION_UDP &&
tox_friend_get_connection_status(Alice, 1, nullptr) == TOX_CONNECTION_UDP &&
tox_friend_get_connection_status(Alice, 2, nullptr) == TOX_CONNECTION_UDP &&
tox_friend_get_connection_status(Bobs[0], 0, nullptr) == TOX_CONNECTION_UDP &&
tox_friend_get_connection_status(Bobs[1], 0, nullptr) == TOX_CONNECTION_UDP &&
tox_friend_get_connection_status(Bobs[2], 0, nullptr) == TOX_CONNECTION_UDP) {
break;
}
@ -274,7 +276,7 @@ START_TEST(test_AV_three_calls)
BobsAV[2] = setup_av_instance(Bobs[2], BobsCC + 2);
printf("Created 4 instances of ToxAV\n");
printf("All set after %llu seconds!\n", time(NULL) - cur_time);
printf("All set after %llu seconds!\n", time(nullptr) - cur_time);
thread_data tds[3];
tds[0].AliceAV = AliceAV;
@ -296,28 +298,28 @@ START_TEST(test_AV_three_calls)
tds[2].friend_number = 2;
pthread_t tids[3];
(void) pthread_create(tids + 0, NULL, call_thread, tds + 0);
(void) pthread_create(tids + 1, NULL, call_thread, tds + 1);
(void) pthread_create(tids + 2, NULL, call_thread, tds + 2);
(void) pthread_create(tids + 0, nullptr, call_thread, tds + 0);
(void) pthread_create(tids + 1, nullptr, call_thread, tds + 1);
(void) pthread_create(tids + 2, nullptr, call_thread, tds + 2);
time_t start_time = time(NULL);
time_t start_time = time(nullptr);
while (time(NULL) - start_time < 5) {
tox_iterate(Alice, NULL);
tox_iterate(Bobs[0], NULL);
tox_iterate(Bobs[1], NULL);
tox_iterate(Bobs[2], NULL);
while (time(nullptr) - start_time < 5) {
tox_iterate(Alice, nullptr);
tox_iterate(Bobs[0], nullptr);
tox_iterate(Bobs[1], nullptr);
tox_iterate(Bobs[2], nullptr);
c_sleep(20);
}
ck_assert(pthread_join(tids[0], &retval) == 0);
ck_assert(retval == NULL);
ck_assert(retval == nullptr);
ck_assert(pthread_join(tids[1], &retval) == 0);
ck_assert(retval == NULL);
ck_assert(retval == nullptr);
ck_assert(pthread_join(tids[2], &retval) == 0);
ck_assert(retval == NULL);
ck_assert(retval == nullptr);
printf("Killing all instances\n");
toxav_kill(BobsAV[0]);
@ -355,7 +357,7 @@ int main(int argc, char *argv[])
Suite *tox = tox_suite();
SRunner *test_runner = srunner_create(tox);
setbuf(stdout, NULL);
setbuf(stdout, nullptr);
srunner_run_all(test_runner, CK_NORMAL);
int number_failed = srunner_ntests_failed(test_runner);

View File

@ -60,7 +60,7 @@ static void manage_keys(DHT *dht)
FILE *keys_file = fopen("key", "r");
if (keys_file != NULL) {
if (keys_file != nullptr) {
/* If file was opened successfully -- load keys,
otherwise save new keys */
size_t read_size = fread(keys, sizeof(uint8_t), KEYS_SIZE, keys_file);
@ -78,7 +78,7 @@ static void manage_keys(DHT *dht)
memcpy(keys + CRYPTO_PUBLIC_KEY_SIZE, dht_get_self_secret_key(dht), CRYPTO_SECRET_KEY_SIZE);
keys_file = fopen("key", "w");
if (keys_file == NULL) {
if (keys_file == nullptr) {
printf("Error opening key file in write mode.\nKeys will not be saved.\n");
return;
}
@ -115,7 +115,7 @@ int main(int argc, char *argv[])
IP ip;
ip_init(&ip, ipv6enabled);
DHT *dht = new_DHT(NULL, new_networking(NULL, ip, PORT), true);
DHT *dht = new_DHT(nullptr, new_networking(nullptr, ip, PORT), true);
Onion *onion = new_onion(dht);
Onion_Announce *onion_a = new_onion_announce(dht);
@ -139,7 +139,7 @@ int main(int argc, char *argv[])
uint16_t ports[NUM_PORTS] = {443, 3389, PORT};
TCP_Server *tcp_s = new_TCP_server(ipv6enabled, NUM_PORTS, ports, dht_get_self_secret_key(dht), onion);
if (tcp_s == NULL) {
if (tcp_s == nullptr) {
printf("TCP server failed to initialize.\n");
exit(1);
}
@ -149,7 +149,7 @@ int main(int argc, char *argv[])
const char *const public_id_filename = "PUBLIC_ID.txt";
FILE *file = fopen(public_id_filename, "w");
if (file == NULL) {
if (file == nullptr) {
printf("Could not open file \"%s\" for writing. Exiting...\n", public_id_filename);
exit(1);
}
@ -200,7 +200,7 @@ int main(int argc, char *argv[])
#ifdef TCP_RELAY_ENABLED
do_TCP_server(tcp_s);
#endif
networking_poll(dht_get_net(dht), NULL);
networking_poll(dht_get_net(dht), nullptr);
c_sleep(1);
}

View File

@ -26,6 +26,8 @@
#include "global.h"
#include "../../../toxcore/ccompat.h"
#include <getopt.h>
#include <stdlib.h>
@ -87,7 +89,7 @@ void handle_command_line_arguments(int argc, char *argv[], char **cfg_file_path,
int opt;
while ((opt = getopt_long(argc, argv, ":", long_options, NULL)) != -1) {
while ((opt = getopt_long(argc, argv, ":", long_options, nullptr)) != -1) {
switch (opt) {

View File

@ -49,7 +49,7 @@ static void parse_tcp_relay_ports_config(config_t *cfg, uint16_t **tcp_relay_por
config_setting_t *ports_array = config_lookup(cfg, NAME_TCP_RELAY_PORTS);
if (ports_array == NULL) {
if (ports_array == nullptr) {
log_write(LOG_LEVEL_WARNING, "No '%s' setting in the configuration file.\n", NAME_TCP_RELAY_PORTS);
log_write(LOG_LEVEL_WARNING, "Using default '%s':\n", NAME_TCP_RELAY_PORTS);
@ -83,7 +83,7 @@ static void parse_tcp_relay_ports_config(config_t *cfg, uint16_t **tcp_relay_por
*tcp_relay_ports = (uint16_t *)realloc(*tcp_relay_ports, (*tcp_relay_port_count) * sizeof(uint16_t));
} else {
free(*tcp_relay_ports);
*tcp_relay_ports = NULL;
*tcp_relay_ports = nullptr;
}
return;
@ -109,7 +109,7 @@ static void parse_tcp_relay_ports_config(config_t *cfg, uint16_t **tcp_relay_por
for (i = 0; i < config_port_count; i ++) {
config_setting_t *elem = config_setting_get_elem(ports_array, i);
if (elem == NULL) {
if (elem == nullptr) {
// it's NULL if `ports_array` is not an array (we have that check earlier) or if `i` is out of range, which should not be
log_write(LOG_LEVEL_WARNING, "Port #%d: Something went wrong while parsing the port. Stopping reading ports.\n", i);
break;
@ -137,7 +137,7 @@ static void parse_tcp_relay_ports_config(config_t *cfg, uint16_t **tcp_relay_por
*tcp_relay_ports = (uint16_t *)realloc(*tcp_relay_ports, (*tcp_relay_port_count) * sizeof(uint16_t));
} else {
free(*tcp_relay_ports);
*tcp_relay_ports = NULL;
*tcp_relay_ports = nullptr;
}
}
@ -306,7 +306,7 @@ int get_general_config(const char *cfg_file_path, char **pid_file_path, char **k
static uint8_t *hex_string_to_bin(const char *hex_string)
{
if (strlen(hex_string) % 2 != 0) {
return NULL;
return nullptr;
}
size_t len = strlen(hex_string) / 2;
@ -342,7 +342,7 @@ int bootstrap_from_config(const char *cfg_file_path, DHT *dht, int enable_ipv6)
config_setting_t *node_list = config_lookup(&cfg, NAME_BOOTSTRAP_NODES);
if (node_list == NULL) {
if (node_list == nullptr) {
log_write(LOG_LEVEL_WARNING, "No '%s' setting in the configuration file. Skipping bootstrapping.\n",
NAME_BOOTSTRAP_NODES);
config_destroy(&cfg);
@ -369,7 +369,7 @@ int bootstrap_from_config(const char *cfg_file_path, DHT *dht, int enable_ipv6)
node = config_setting_get_elem(node_list, 0);
if (node == NULL) {
if (node == nullptr) {
config_destroy(&cfg);
return 0;
}

View File

@ -63,7 +63,7 @@ void log_backend_syslog_write(LOG_LEVEL level, const char *format, va_list args)
va_list args2;
va_copy(args2, args);
int size = vsnprintf(NULL, 0, format, args2);
int size = vsnprintf(nullptr, 0, format, args2);
va_end(args2);
assert(size >= 0);

View File

@ -65,7 +65,7 @@ static int manage_keys(DHT *dht, char *keys_file_path)
// Check if file exits, proceed to open and load keys
keys_file = fopen(keys_file_path, "r");
if (keys_file != NULL) {
if (keys_file != nullptr) {
const size_t read_size = fread(keys, sizeof(uint8_t), KEYS_SIZE, keys_file);
if (read_size != KEYS_SIZE) {
@ -131,7 +131,7 @@ static void daemonize(LOG_BACKEND log_backend, char *pid_file_path)
// Open the PID file for writing
pid_file = fopen(pid_file_path, "a+");
if (pid_file == NULL) {
if (pid_file == nullptr) {
log_write(LOG_LEVEL_ERROR, "Couldn't open the PID file for writing: %s. Exiting.\n", pid_file_path);
exit(1);
}
@ -226,16 +226,16 @@ int main(int argc, char *argv[])
IP ip;
ip_init(&ip, enable_ipv6);
Networking_Core *net = new_networking(NULL, ip, port);
Networking_Core *net = new_networking(nullptr, ip, port);
if (net == NULL) {
if (net == nullptr) {
if (enable_ipv6 && enable_ipv4_fallback) {
log_write(LOG_LEVEL_WARNING, "Couldn't initialize IPv6 networking. Falling back to using IPv4.\n");
enable_ipv6 = 0;
ip_init(&ip, enable_ipv6);
net = new_networking(NULL, ip, port);
net = new_networking(nullptr, ip, port);
if (net == NULL) {
if (net == nullptr) {
log_write(LOG_LEVEL_ERROR, "Couldn't fallback to IPv4. Exiting.\n");
return 1;
}
@ -245,9 +245,9 @@ int main(int argc, char *argv[])
}
}
DHT *dht = new_DHT(NULL, net, true);
DHT *dht = new_DHT(nullptr, net, true);
if (dht == NULL) {
if (dht == nullptr) {
log_write(LOG_LEVEL_ERROR, "Couldn't initialize Tox DHT instance. Exiting.\n");
return 1;
}
@ -280,7 +280,7 @@ int main(int argc, char *argv[])
free(keys_file_path);
TCP_Server *tcp_server = NULL;
TCP_Server *tcp_server = nullptr;
if (enable_tcp_relay) {
if (tcp_relay_port_count == 0) {
@ -293,7 +293,7 @@ int main(int argc, char *argv[])
// tcp_relay_port_count != 0 at this point
free(tcp_relay_ports);
if (tcp_server != NULL) {
if (tcp_server != nullptr) {
log_write(LOG_LEVEL_INFO, "Initialized Tox TCP server successfully.\n");
} else {
log_write(LOG_LEVEL_ERROR, "Couldn't initialize Tox TCP server. Exiting.\n");
@ -332,7 +332,7 @@ int main(int argc, char *argv[])
do_TCP_server(tcp_server);
}
networking_poll(dht_get_net(dht), NULL);
networking_poll(dht_get_net(dht), nullptr);
if (waiting_for_dht_connection && DHT_isconnected(dht)) {
log_write(LOG_LEVEL_INFO, "Connected to another bootstrap node successfully.\n");

View File

@ -24,8 +24,8 @@ int load_file(char *filename, char **result)
int size = 0;
FILE *f = fopen(filename, "rb");
if (f == NULL) {
*result = NULL;
if (f == nullptr) {
*result = nullptr;
return -1; // -1 means file opening fail
}
@ -88,7 +88,7 @@ int main(int argc, char *argv[])
FILE *f = fopen(argv[4], "wb");
if (f == NULL) {
if (f == nullptr) {
goto fail;
}

View File

@ -6,6 +6,7 @@ cc_library(
"misc_tools.c",
],
visibility = ["//c-toxcore:__subpackages__"],
deps = ["//c-toxcore/toxcore:ccompat"],
)
cc_binary(

View File

@ -190,7 +190,7 @@ int main(int argc, char *argv[])
IP ip;
ip_init(&ip, ipv6enabled);
DHT *dht = new_DHT(NULL, new_networking(NULL, ip, PORT), true);
DHT *dht = new_DHT(nullptr, new_networking(nullptr, ip, PORT), true);
printf("OUR ID: ");
uint32_t i;
@ -252,7 +252,7 @@ int main(int argc, char *argv[])
}
#endif
networking_poll(dht_get_net(dht), NULL);
networking_poll(dht_get_net(dht), nullptr);
print_clientlist(dht);
print_friendlist(dht);

View File

@ -132,7 +132,7 @@ int main(int argc, char *argv[])
} else {
FILE *file = fopen(argv[argvoffset + 1], "rb");
if (file == NULL) {
if (file == nullptr) {
printf("Failed to open \"%s\" - does it exist?\n", argv[argvoffset + 1]);
return 1;
}
@ -185,11 +185,11 @@ int main(int argc, char *argv[])
printf("%s\n", name);
m_send_message_generic(m, num, MESSAGE_NORMAL, (const uint8_t *)"Test", 5, 0);
do_messenger(m, NULL);
do_messenger(m, nullptr);
c_sleep(30);
FILE *file = fopen("Save.bak", "wb");
if (file == NULL) {
if (file == nullptr) {
return 1;
}

View File

@ -111,7 +111,7 @@ struct toxav_thread_data {
};
static const char *vdout = "AV Test"; /* Video output */
static PaStream *adout = NULL; /* Audio output */
static PaStream *adout = nullptr; /* Audio output */
typedef struct {
uint16_t size;
@ -139,7 +139,7 @@ static void *pa_write_thread(void *d)
}
}
return NULL;
return nullptr;
}
/**
@ -224,7 +224,7 @@ static void t_accept_friend_request_cb(Tox *m, const uint8_t *public_key, const
void *userdata)
{
if (length == 7 && memcmp("gentoo", data, 7) == 0) {
assert(tox_friend_add_norequest(m, public_key, NULL) != (uint32_t) ~0);
assert(tox_friend_add_norequest(m, public_key, nullptr) != (uint32_t) ~0);
}
}
@ -235,8 +235,8 @@ static void initialize_tox(Tox **bootstrap, ToxAV **AliceAV, CallControl *AliceC
Tox *Alice;
Tox *Bob;
struct Tox_Options *opts = tox_options_new(NULL);
assert(opts != NULL);
struct Tox_Options *opts = tox_options_new(nullptr);
assert(opts != nullptr);
tox_options_set_end_port(opts, 0);
tox_options_set_ipv6_enabled(opts, false);
@ -261,7 +261,7 @@ static void initialize_tox(Tox **bootstrap, ToxAV **AliceAV, CallControl *AliceC
printf("Created 3 instances of Tox\n");
printf("Preparing network...\n");
long long unsigned int cur_time = time(NULL);
long long unsigned int cur_time = time(nullptr);
uint32_t to_compare = 974536;
uint8_t address[TOX_ADDRESS_SIZE];
@ -270,7 +270,7 @@ static void initialize_tox(Tox **bootstrap, ToxAV **AliceAV, CallControl *AliceC
tox_self_get_address(Alice, address);
assert(tox_friend_add(Bob, address, (const uint8_t *)"gentoo", 7, NULL) != (uint32_t) ~0);
assert(tox_friend_add(Bob, address, (const uint8_t *)"gentoo", 7, nullptr) != (uint32_t) ~0);
uint8_t off = 1;
@ -282,12 +282,12 @@ static void initialize_tox(Tox **bootstrap, ToxAV **AliceAV, CallControl *AliceC
if (tox_self_get_connection_status(*bootstrap) &&
tox_self_get_connection_status(Alice) &&
tox_self_get_connection_status(Bob) && off) {
printf("Toxes are online, took %llu seconds\n", time(NULL) - cur_time);
printf("Toxes are online, took %llu seconds\n", time(nullptr) - cur_time);
off = 0;
}
if (tox_friend_get_connection_status(Alice, 0, NULL) == TOX_CONNECTION_UDP &&
tox_friend_get_connection_status(Bob, 0, NULL) == TOX_CONNECTION_UDP) {
if (tox_friend_get_connection_status(Alice, 0, nullptr) == TOX_CONNECTION_UDP &&
tox_friend_get_connection_status(Bob, 0, nullptr) == TOX_CONNECTION_UDP) {
break;
}
@ -321,7 +321,7 @@ static void initialize_tox(Tox **bootstrap, ToxAV **AliceAV, CallControl *AliceC
printf("Created 2 instances of ToxAV\n");
printf("All set after %llu seconds!\n", time(NULL) - cur_time);
printf("All set after %llu seconds!\n", time(nullptr) - cur_time);
}
static int iterate_tox(Tox *bootstrap, ToxAV *AliceAV, ToxAV *BobAV, void *userdata)
{
@ -364,7 +364,7 @@ static void *iterate_toxav(void *data)
cvDestroyWindow(vdout);
#endif
pthread_exit(NULL);
pthread_exit(nullptr);
}
static int send_opencv_img(ToxAV *av, uint32_t friend_number, const IplImage *img)
@ -399,7 +399,7 @@ static int send_opencv_img(ToxAV *av, uint32_t friend_number, const IplImage *im
}
int rc = toxav_video_send_frame(av, friend_number, img->width, img->height,
planes[0], planes[1], planes[2], NULL);
planes[0], planes[1], planes[2], nullptr);
free(planes[0]);
free(planes[1]);
free(planes[2]);
@ -441,8 +441,8 @@ int main(int argc, char **argv)
struct stat st;
/* AV files for testing */
const char *af_name = NULL;
const char *vf_name = NULL;
const char *af_name = nullptr;
const char *vf_name = nullptr;
long audio_out_dev_idx = -1;
int32_t audio_frame_duration = 20;
@ -574,8 +574,8 @@ CHECK_ARG:
memset(&AliceCC, 0, sizeof(CallControl));
memset(&BobCC, 0, sizeof(CallControl));
pthread_mutex_init(AliceCC.arb_mutex, NULL);
pthread_mutex_init(BobCC.arb_mutex, NULL);
pthread_mutex_init(AliceCC.arb_mutex, nullptr);
pthread_mutex_init(BobCC.arb_mutex, nullptr);
AliceCC.arb = rb_new(16);
BobCC.arb = rb_new(16);
@ -591,7 +591,7 @@ CHECK_ARG:
}
while (!BobCC.incoming) {
iterate_tox(bootstrap, AliceAV, BobAV, NULL);
iterate_tox(bootstrap, AliceAV, BobAV, nullptr);
}
{ /* Answer */
@ -605,20 +605,20 @@ CHECK_ARG:
}
while (AliceCC.state == 0) {
iterate_tox(bootstrap, AliceAV, BobAV, NULL);
iterate_tox(bootstrap, AliceAV, BobAV, nullptr);
}
/* Open audio file */
af_handle = sf_open(af_name, SFM_READ, &af_info);
if (af_handle == NULL) {
if (af_handle == nullptr) {
printf("Failed to open the file.\n");
exit(1);
}
int16_t PCM[5760];
time_t start_time = time(NULL);
time_t start_time = time(nullptr);
time_t expected_time = af_info.frames / af_info.samplerate + 2;
@ -630,7 +630,7 @@ CHECK_ARG:
};
pthread_t dect;
pthread_create(&dect, NULL, iterate_toxav, &data);
pthread_create(&dect, nullptr, iterate_toxav, &data);
pthread_detach(dect);
int frame_size = (af_info.samplerate * audio_frame_duration / 1000) * af_info.channels;
@ -640,24 +640,24 @@ CHECK_ARG:
output.channelCount = af_info.channels;
output.sampleFormat = paInt16;
output.suggestedLatency = audio_dev->defaultHighOutputLatency;
output.hostApiSpecificStreamInfo = NULL;
output.hostApiSpecificStreamInfo = nullptr;
PaError err = Pa_OpenStream(&adout, NULL, &output, af_info.samplerate, frame_size, paNoFlag, NULL, NULL);
PaError err = Pa_OpenStream(&adout, nullptr, &output, af_info.samplerate, frame_size, paNoFlag, nullptr, nullptr);
assert(err == paNoError);
err = Pa_StartStream(adout);
assert(err == paNoError);
// toxav_audio_bit_rate_set(AliceAV, 0, 64, false, NULL);
// toxav_audio_bit_rate_set(AliceAV, 0, 64, false, nullptr);
/* Start write thread */
pthread_t t;
pthread_create(&t, NULL, pa_write_thread, &BobCC);
pthread_create(&t, nullptr, pa_write_thread, &BobCC);
pthread_detach(t);
printf("Sample rate %d\n", af_info.samplerate);
while (start_time + expected_time > time(NULL)) {
while (start_time + expected_time > time(nullptr)) {
uint64_t enc_start_time = current_time_monotonic();
int64_t count = sf_read_short(af_handle, PCM, frame_size);
@ -670,11 +670,11 @@ CHECK_ARG:
}
}
iterate_tox(bootstrap, AliceAV, BobAV, NULL);
iterate_tox(bootstrap, AliceAV, BobAV, nullptr);
c_sleep((audio_frame_duration - (current_time_monotonic() - enc_start_time) - 1));
}
printf("Played file in: %lu; stopping stream...\n", time(NULL) - start_time);
printf("Played file in: %lu; stopping stream...\n", time(nullptr) - start_time);
Pa_StopStream(adout);
sf_close(af_handle);
@ -689,7 +689,7 @@ CHECK_ARG:
}
}
iterate_tox(bootstrap, AliceAV, BobAV, NULL);
iterate_tox(bootstrap, AliceAV, BobAV, nullptr);
assert(BobCC.state == TOXAV_FRIEND_CALL_STATE_FINISHED);
/* Stop decode thread */
@ -702,7 +702,7 @@ CHECK_ARG:
pthread_mutex_destroy(AliceCC.arb_mutex);
pthread_mutex_destroy(BobCC.arb_mutex);
void *f = NULL;
void *f = nullptr;
while (rb_read(AliceCC.arb, &f)) {
free(f);
@ -732,7 +732,7 @@ CHECK_ARG:
}
while (!BobCC.incoming) {
iterate_tox(bootstrap, AliceAV, BobAV, NULL);
iterate_tox(bootstrap, AliceAV, BobAV, nullptr);
}
{ /* Answer */
@ -745,7 +745,7 @@ CHECK_ARG:
}
}
iterate_tox(bootstrap, AliceAV, BobAV, NULL);
iterate_tox(bootstrap, AliceAV, BobAV, nullptr);
/* Start decode thread */
struct toxav_thread_data data = {
@ -755,7 +755,7 @@ CHECK_ARG:
};
pthread_t dect;
pthread_create(&dect, NULL, iterate_toxav, &data);
pthread_create(&dect, nullptr, iterate_toxav, &data);
pthread_detach(dect);
CvCapture *capture = cvCreateFileCapture(vf_name);
@ -766,12 +766,12 @@ CHECK_ARG:
}
#if 0
toxav_video_bit_rate_set(AliceAV, 0, 5000, false, NULL);
toxav_video_bit_rate_set(AliceAV, 0, 5000, false, nullptr);
#endif
time_t start_time = time(NULL);
time_t start_time = time(nullptr);
while (start_time + 90 > time(NULL)) {
while (start_time + 90 > time(nullptr)) {
IplImage *frame = cvQueryFrame(capture);
if (!frame) {
@ -779,7 +779,7 @@ CHECK_ARG:
}
send_opencv_img(AliceAV, 0, frame);
iterate_tox(bootstrap, AliceAV, BobAV, NULL);
iterate_tox(bootstrap, AliceAV, BobAV, nullptr);
c_sleep(10);
}
@ -795,7 +795,7 @@ CHECK_ARG:
}
}
iterate_tox(bootstrap, AliceAV, BobAV, NULL);
iterate_tox(bootstrap, AliceAV, BobAV, nullptr);
assert(BobCC.state == TOXAV_FRIEND_CALL_STATE_FINISHED);
/* Stop decode thread */

View File

@ -94,7 +94,7 @@ static void callback_group_invite(Tox *tox, uint32_t fid, TOX_CONFERENCE_TYPE ty
void *userdata)
{
if (current_group == -1) {
current_group = tox_conference_join(tox, fid, data, length, NULL);
current_group = tox_conference_join(tox, fid, data, length, nullptr);
}
}
@ -103,13 +103,13 @@ static void callback_friend_message(Tox *tox, uint32_t fid, TOX_MESSAGE_TYPE typ
void *userdata)
{
if (length == 1 && *message == 'c') {
if (tox_conference_delete(tox, current_group, NULL) == 0) {
if (tox_conference_delete(tox, current_group, nullptr) == 0) {
current_group = -1;
}
}
if (length == 1 && *message == 'i') {
tox_conference_invite(tox, fid, current_group, NULL);
tox_conference_invite(tox, fid, current_group, nullptr);
}
if (length == 1 && *message == 'j' && sock >= 0) {
@ -121,14 +121,14 @@ static void copy_groupmessage(Tox *tox, uint32_t groupnumber, uint32_t friendgro
const uint8_t *message, size_t length,
void *userdata)
{
if (tox_conference_peer_number_is_ours(tox, groupnumber, friendgroupnumber, NULL)) {
if (tox_conference_peer_number_is_ours(tox, groupnumber, friendgroupnumber, nullptr)) {
return;
}
TOX_ERR_CONFERENCE_PEER_QUERY error;
size_t namelen = tox_conference_peer_get_name_size(tox, groupnumber, friendgroupnumber, &error);
uint8_t name[TOX_MAX_NAME_LENGTH];
tox_conference_peer_get_name(tox, groupnumber, friendgroupnumber, name, NULL);
tox_conference_peer_get_name(tox, groupnumber, friendgroupnumber, name, nullptr);
if (namelen == 0 || error != TOX_ERR_CONFERENCE_PEER_QUERY_OK) {
memcpy(name, "<unknown>", 9);
@ -205,7 +205,7 @@ static void send_irc_group(Tox *tox, uint8_t *msg, uint16_t len)
uint8_t *pmsg = (uint8_t *)strstr((char *)req, " PRIVMSG");
if (pmsg == NULL) {
if (pmsg == nullptr) {
return;
}
@ -227,7 +227,7 @@ static void send_irc_group(Tox *tox, uint8_t *msg, uint16_t len)
memcpy(message + length, msg + req_len + 2, len - (req_len + 2));
length += len - (req_len + 2);
tox_conference_send_message(tox, current_group, TOX_MESSAGE_TYPE_NORMAL, message, length, NULL);
tox_conference_send_message(tox, current_group, TOX_MESSAGE_TYPE_NORMAL, message, length, nullptr);
}
static Tox *init_tox(int argc, char *argv[])
@ -377,7 +377,7 @@ int main(int argc, char *argv[])
}
}
tox_iterate(tox, NULL);
tox_iterate(tox, nullptr);
usleep(1000 * 50);
}
}

View File

@ -21,6 +21,9 @@
* You should have received a copy of the GNU General Public License
* along with Tox. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef MISC_TOOLS_C
#define MISC_TOOLS_C
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
@ -42,6 +45,8 @@
#endif
#endif
#include "../toxcore/ccompat.h"
// You are responsible for freeing the return value!
uint8_t *hex_string_to_bin(const char *hex_string)
{
@ -111,3 +116,5 @@ int cmdline_parsefor_ipv46(int argc, char **argv, uint8_t *ipv6enabled)
return argvoffset;
}
#endif // MISC_TOOLS_C

View File

@ -77,7 +77,7 @@ int main(int argc, char *argv[])
}
int *master = (int *)malloc(sizeof(int));
int ret = forkpty(master, NULL, NULL, NULL);
int ret = forkpty(master, nullptr, nullptr, nullptr);
if (ret == -1) {
printf("fork failed\n");
@ -86,7 +86,7 @@ int main(int argc, char *argv[])
}
if (ret == 0) {
execl("/bin/sh", "sh", NULL);
execl("/bin/sh", "sh", nullptr);
return 0;
}

View File

@ -312,7 +312,7 @@ int main(int argc, char *argv[])
d = opendir(path);
if (d) {
while ((dir = readdir(d)) != NULL) {
while ((dir = readdir(d)) != nullptr) {
VLA(char, filepath, strlen(path) + strlen(dir->d_name) + 1);
memcpy(filepath, path, strlen(path));
memcpy(filepath + strlen(path), dir->d_name, strlen(dir->d_name) + 1);
@ -338,7 +338,7 @@ int main(int argc, char *argv[])
}
}
tox_iterate(tox, NULL);
tox_iterate(tox, nullptr);
c_sleep(1);
}
}

View File

@ -15,6 +15,7 @@ cc_library(
name = "ring_buffer",
srcs = ["ring_buffer.c"],
hdrs = ["ring_buffer.h"],
deps = ["//c-toxcore/toxcore:ccompat"],
)
cc_library(

View File

@ -47,13 +47,13 @@ ACSession *ac_new(Logger *log, ToxAV *av, uint32_t friend_number, toxav_audio_re
if (!ac) {
LOGGER_WARNING(log, "Allocation failed! Application might misbehave!");
return NULL;
return nullptr;
}
if (create_recursive_mutex(ac->queue_mutex) != 0) {
LOGGER_WARNING(log, "Failed to create recursive mutex!");
free(ac);
return NULL;
return nullptr;
}
int status;
@ -75,7 +75,7 @@ ACSession *ac_new(Logger *log, ToxAV *av, uint32_t friend_number, toxav_audio_re
/* Initialize encoders with default values */
ac->encoder = create_audio_encoder(log, AUDIO_START_BITRATE, AUDIO_START_SAMPLE_RATE, AUDIO_START_CHANNEL_COUNT);
if (ac->encoder == NULL) {
if (ac->encoder == nullptr) {
goto DECODER_CLEANUP;
}
@ -106,7 +106,7 @@ DECODER_CLEANUP:
BASE_CLEANUP:
pthread_mutex_destroy(ac->queue_mutex);
free(ac);
return NULL;
return nullptr;
}
void ac_kill(ACSession *ac)
@ -147,7 +147,7 @@ void ac_iterate(ACSession *ac)
if (rc == 2) {
LOGGER_DEBUG(ac->log, "OPUS correction");
int fs = (ac->lp_sampling_rate * ac->lp_frame_duration) / 1000;
rc = opus_decode(ac->decoder, NULL, 0, temp_audio_buffer, fs, 1);
rc = opus_decode(ac->decoder, nullptr, 0, temp_audio_buffer, fs, 1);
} else {
/* Get values from packet and decode. */
/* NOTE: This didn't work very well */
@ -275,14 +275,14 @@ static struct JitterBuffer *jbuf_new(uint32_t capacity)
struct JitterBuffer *q = (struct JitterBuffer *)calloc(sizeof(struct JitterBuffer), 1);
if (!q) {
return NULL;
return nullptr;
}
q->queue = (struct RTPMessage **)calloc(sizeof(struct RTPMessage *), size);
if (!q->queue) {
free(q);
return NULL;
return nullptr;
}
q->size = size;
@ -294,7 +294,7 @@ static void jbuf_clear(struct JitterBuffer *q)
for (; q->bottom != q->top; ++q->bottom) {
if (q->queue[q->bottom % q->size]) {
free(q->queue[q->bottom % q->size]);
q->queue[q->bottom % q->size] = NULL;
q->queue[q->bottom % q->size] = nullptr;
}
}
}
@ -340,14 +340,14 @@ static struct RTPMessage *jbuf_read(struct JitterBuffer *q, int32_t *success)
{
if (q->top == q->bottom) {
*success = 0;
return NULL;
return nullptr;
}
unsigned int num = q->bottom % q->size;
if (q->queue[num]) {
struct RTPMessage *ret = q->queue[num];
q->queue[num] = NULL;
q->queue[num] = nullptr;
++q->bottom;
*success = 1;
return ret;
@ -356,11 +356,11 @@ static struct RTPMessage *jbuf_read(struct JitterBuffer *q, int32_t *success)
if ((uint32_t)(q->top - q->bottom) > q->capacity) {
++q->bottom;
*success = 2;
return NULL;
return nullptr;
}
*success = 0;
return NULL;
return nullptr;
}
OpusEncoder *create_audio_encoder(Logger *log, int32_t bit_rate, int32_t sampling_rate, int32_t channel_count)
{
@ -374,7 +374,7 @@ OpusEncoder *create_audio_encoder(Logger *log, int32_t bit_rate, int32_t samplin
if (status != OPUS_OK) {
LOGGER_ERROR(log, "Error while starting audio encoder: %s", opus_strerror(status));
return NULL;
return nullptr;
}
@ -452,7 +452,7 @@ OpusEncoder *create_audio_encoder(Logger *log, int32_t bit_rate, int32_t samplin
FAILURE:
opus_encoder_destroy(rc);
return NULL;
return nullptr;
}
bool reconfigure_audio_encoder(Logger *log, OpusEncoder **e, int32_t new_br, int32_t new_sr, uint8_t new_ch,
@ -462,7 +462,7 @@ bool reconfigure_audio_encoder(Logger *log, OpusEncoder **e, int32_t new_br, int
if (*old_sr != new_sr || *old_ch != new_ch) {
OpusEncoder *new_encoder = create_audio_encoder(log, new_br, new_sr, new_ch);
if (new_encoder == NULL) {
if (new_encoder == nullptr) {
return false;
}

View File

@ -97,7 +97,7 @@ void bwc_kill(BWController *bwc)
return;
}
m_callback_rtp_packet(bwc->m, bwc->friend_number, BWC_PACKET_ID, NULL, NULL);
m_callback_rtp_packet(bwc->m, bwc->friend_number, BWC_PACKET_ID, nullptr, nullptr);
rb_kill(bwc->rcvpkt.rb);
free(bwc);

View File

@ -55,12 +55,12 @@ static Group_JitterBuffer *create_queue(unsigned int capacity)
Group_JitterBuffer *q;
if (!(q = (Group_JitterBuffer *)calloc(sizeof(Group_JitterBuffer), 1))) {
return NULL;
return nullptr;
}
if (!(q->queue = (Group_Audio_Packet **)calloc(sizeof(Group_Audio_Packet *), size))) {
free(q);
return NULL;
return nullptr;
}
q->size = size;
@ -73,7 +73,7 @@ static void clear_queue(Group_JitterBuffer *q)
for (; q->bottom != q->top; ++q->bottom) {
if (q->queue[q->bottom % q->size]) {
free(q->queue[q->bottom % q->size]);
q->queue[q->bottom % q->size] = NULL;
q->queue[q->bottom % q->size] = nullptr;
}
}
}
@ -132,14 +132,14 @@ static Group_Audio_Packet *dequeue(Group_JitterBuffer *q, int *success)
{
if (q->top == q->bottom) {
*success = 0;
return NULL;
return nullptr;
}
unsigned int num = q->bottom % q->size;
if (q->queue[num]) {
Group_Audio_Packet *ret = q->queue[num];
q->queue[num] = NULL;
q->queue[num] = nullptr;
++q->bottom;
*success = 1;
return ret;
@ -148,11 +148,11 @@ static Group_Audio_Packet *dequeue(Group_JitterBuffer *q, int *success)
if ((uint32_t)(q->top - q->bottom) > q->capacity) {
++q->bottom;
*success = 2;
return NULL;
return nullptr;
}
*success = 0;
return NULL;
return nullptr;
}
typedef struct {
@ -190,7 +190,7 @@ static int recreate_encoder(Group_AV *group_av)
{
if (group_av->audio_encoder) {
opus_encoder_destroy(group_av->audio_encoder);
group_av->audio_encoder = NULL;
group_av->audio_encoder = nullptr;
}
int rc = OPUS_OK;
@ -199,7 +199,7 @@ static int recreate_encoder(Group_AV *group_av)
if (rc != OPUS_OK) {
LOGGER_ERROR(group_av->log, "Error while starting audio encoder: %s", opus_strerror(rc));
group_av->audio_encoder = NULL;
group_av->audio_encoder = nullptr;
return -1;
}
@ -208,7 +208,7 @@ static int recreate_encoder(Group_AV *group_av)
if (rc != OPUS_OK) {
LOGGER_ERROR(group_av->log, "Error while setting encoder ctl: %s", opus_strerror(rc));
opus_encoder_destroy(group_av->audio_encoder);
group_av->audio_encoder = NULL;
group_av->audio_encoder = nullptr;
return -1;
}
@ -217,7 +217,7 @@ static int recreate_encoder(Group_AV *group_av)
if (rc != OPUS_OK) {
LOGGER_ERROR(group_av->log, "Error while setting encoder ctl: %s", opus_strerror(rc));
opus_encoder_destroy(group_av->audio_encoder);
group_av->audio_encoder = NULL;
group_av->audio_encoder = nullptr;
return -1;
}
@ -229,13 +229,13 @@ static Group_AV *new_group_av(Logger *log, Group_Chats *g_c, void (*audio_callba
unsigned int, uint8_t, unsigned int, void *), void *userdata)
{
if (!g_c) {
return NULL;
return nullptr;
}
Group_AV *group_av = (Group_AV *)calloc(1, sizeof(Group_AV));
if (!group_av) {
return NULL;
return nullptr;
}
group_av->log = log;
@ -296,7 +296,7 @@ static int decode_audio_packet(Group_AV *group_av, Group_Peer_AV *peer_av, int g
return -1;
}
int16_t *out_audio = NULL;
int16_t *out_audio = nullptr;
int out_audio_samples = 0;
unsigned int sample_rate = 48000;
@ -317,7 +317,7 @@ static int decode_audio_packet(Group_AV *group_av, Group_Peer_AV *peer_av, int g
if (channels != peer_av->decoder_channels) {
if (peer_av->audio_decoder) {
opus_decoder_destroy(peer_av->audio_decoder);
peer_av->audio_decoder = NULL;
peer_av->audio_decoder = nullptr;
}
int rc;
@ -366,7 +366,7 @@ static int decode_audio_packet(Group_AV *group_av, Group_Peer_AV *peer_av, int g
return -1;
}
out_audio_samples = opus_decode(peer_av->audio_decoder, NULL, 0, out_audio, peer_av->last_packet_samples, 1);
out_audio_samples = opus_decode(peer_av->audio_decoder, nullptr, 0, out_audio, peer_av->last_packet_samples, 1);
if (out_audio_samples <= 0) {
free(out_audio);
@ -436,7 +436,7 @@ static int groupchat_enable_av(Logger *log, Group_Chats *g_c, int groupnumber, v
Group_AV *group_av = new_group_av(log, g_c, audio_callback, userdata);
if (group_av == NULL) {
if (group_av == nullptr) {
return -1;
}

View File

@ -104,21 +104,21 @@ void msi_register_callback(MSISession *session, msi_action_cb *callback, MSICall
}
MSISession *msi_new(Messenger *m)
{
if (m == NULL) {
return NULL;
if (m == nullptr) {
return nullptr;
}
MSISession *retu = (MSISession *)calloc(sizeof(MSISession), 1);
if (retu == NULL) {
if (retu == nullptr) {
LOGGER_ERROR(m->log, "Allocation failed! Program might misbehave!");
return NULL;
return nullptr;
}
if (create_recursive_mutex(retu->mutex) != 0) {
LOGGER_ERROR(m->log, "Failed to init mutex! Program might misbehave");
free(retu);
return NULL;
return nullptr;
}
retu->messenger = m;
@ -133,12 +133,12 @@ MSISession *msi_new(Messenger *m)
}
int msi_kill(MSISession *session, Logger *log)
{
if (session == NULL) {
if (session == nullptr) {
LOGGER_ERROR(log, "Tried to terminate non-existing session");
return -1;
}
m_callback_msi_packet((struct Messenger *) session->messenger, NULL, NULL);
m_callback_msi_packet((struct Messenger *) session->messenger, nullptr, nullptr);
if (pthread_mutex_trylock(session->mutex) != 0) {
LOGGER_ERROR(session->messenger->log, "Failed to acquire lock on msi mutex");
@ -179,7 +179,7 @@ int msi_invite(MSISession *session, MSICall **call, uint32_t friend_number, uint
return -1;
}
if (get_call(session, friend_number) != NULL) {
if (get_call(session, friend_number) != nullptr) {
LOGGER_ERROR(session->messenger->log, "Already in a call");
pthread_mutex_unlock(session->mutex);
return -1;
@ -187,7 +187,7 @@ int msi_invite(MSISession *session, MSICall **call, uint32_t friend_number, uint
(*call) = new_call(session, friend_number);
if (*call == NULL) {
if (*call == nullptr) {
pthread_mutex_unlock(session->mutex);
return -1;
}
@ -506,8 +506,8 @@ static MSICall *get_call(MSISession *session, uint32_t friend_number)
{
assert(session);
if (session->calls == NULL || session->calls_tail < friend_number) {
return NULL;
if (session->calls == nullptr || session->calls_tail < friend_number) {
return nullptr;
}
return session->calls[friend_number];
@ -518,28 +518,28 @@ MSICall *new_call(MSISession *session, uint32_t friend_number)
MSICall *rc = (MSICall *)calloc(sizeof(MSICall), 1);
if (rc == NULL) {
return NULL;
if (rc == nullptr) {
return nullptr;
}
rc->session = session;
rc->friend_number = friend_number;
if (session->calls == NULL) { /* Creating */
if (session->calls == nullptr) { /* Creating */
session->calls = (MSICall **)calloc(sizeof(MSICall *), friend_number + 1);
if (session->calls == NULL) {
if (session->calls == nullptr) {
free(rc);
return NULL;
return nullptr;
}
session->calls_tail = session->calls_head = friend_number;
} else if (session->calls_tail < friend_number) { /* Appending */
MSICall **tmp = (MSICall **)realloc(session->calls, sizeof(MSICall *) * (friend_number + 1));
if (tmp == NULL) {
if (tmp == nullptr) {
free(rc);
return NULL;
return nullptr;
}
session->calls = tmp;
@ -548,7 +548,7 @@ MSICall *new_call(MSISession *session, uint32_t friend_number)
uint32_t i = session->calls_tail + 1;
for (; i < friend_number; i ++) {
session->calls[i] = NULL;
session->calls[i] = nullptr;
}
rc->prev = session->calls[session->calls_tail];
@ -567,7 +567,7 @@ MSICall *new_call(MSISession *session, uint32_t friend_number)
void kill_call(MSICall *call)
{
/* Assume that session mutex is locked */
if (call == NULL) {
if (call == nullptr) {
return;
}
@ -594,7 +594,7 @@ void kill_call(MSICall *call)
goto CLEAR_CONTAINER;
}
session->calls[call->friend_number] = NULL;
session->calls[call->friend_number] = nullptr;
free(call);
return;
@ -602,7 +602,7 @@ CLEAR_CONTAINER:
session->calls_head = session->calls_tail = 0;
free(session->calls);
free(call);
session->calls = NULL;
session->calls = nullptr;
}
void on_peer_status(Messenger *m, uint32_t friend_number, uint8_t status, void *data)
{
@ -616,7 +616,7 @@ void on_peer_status(Messenger *m, uint32_t friend_number, uint8_t status, void *
pthread_mutex_lock(session->mutex);
MSICall *call = get_call(session, friend_number);
if (call == NULL) {
if (call == nullptr) {
pthread_mutex_unlock(session->mutex);
return;
}
@ -810,7 +810,7 @@ void handle_msi_packet(Messenger *m, uint32_t friend_number, const uint8_t *data
pthread_mutex_lock(session->mutex);
MSICall *call = get_call(session, friend_number);
if (call == NULL) {
if (call == nullptr) {
if (msg.request.value != requ_init) {
send_error(m, friend_number, msi_EStrayMessage);
pthread_mutex_unlock(session->mutex);
@ -819,7 +819,7 @@ void handle_msi_packet(Messenger *m, uint32_t friend_number, const uint8_t *data
call = new_call(session, friend_number);
if (call == NULL) {
if (call == nullptr) {
send_error(m, friend_number, msi_ESystem);
pthread_mutex_unlock(session->mutex);
return;

View File

@ -21,6 +21,8 @@
*/
#include "ring_buffer.h"
#include "../toxcore/ccompat.h"
#include <stdlib.h>
struct RingBuffer {
@ -46,7 +48,7 @@ bool rb_empty(const RingBuffer *b)
*/
void *rb_write(RingBuffer *b, void *p)
{
void *rc = NULL;
void *rc = nullptr;
if ((b->end + 1) % b->size == b->start) { /* full */
rc = b->data[b->start];
@ -65,7 +67,7 @@ void *rb_write(RingBuffer *b, void *p)
bool rb_read(RingBuffer *b, void **p)
{
if (b->end == b->start) { /* Empty */
*p = NULL;
*p = nullptr;
return false;
}
@ -79,14 +81,14 @@ RingBuffer *rb_new(int size)
RingBuffer *buf = (RingBuffer *)calloc(sizeof(RingBuffer), 1);
if (!buf) {
return NULL;
return nullptr;
}
buf->size = size + 1; /* include empty elem */
if (!(buf->data = (void **)calloc(buf->size, sizeof(void *)))) {
free(buf);
return NULL;
return nullptr;
}
return buf;

View File

@ -49,7 +49,7 @@ RTPSession *rtp_new(int payload_type, Messenger *m, uint32_t friendnumber,
if (!retu) {
LOGGER_WARNING(m->log, "Alloc failed! Program might misbehave!");
return NULL;
return nullptr;
}
retu->ssrc = random_u32();
@ -67,7 +67,7 @@ RTPSession *rtp_new(int payload_type, Messenger *m, uint32_t friendnumber,
if (-1 == rtp_allow_receiving(retu)) {
LOGGER_WARNING(m->log, "Failed to start rtp receiving mode");
free(retu);
return NULL;
return nullptr;
}
return retu;
@ -85,7 +85,7 @@ void rtp_kill(RTPSession *session)
}
int rtp_allow_receiving(RTPSession *session)
{
if (session == NULL) {
if (session == nullptr) {
return -1;
}
@ -100,11 +100,11 @@ int rtp_allow_receiving(RTPSession *session)
}
int rtp_stop_receiving(RTPSession *session)
{
if (session == NULL) {
if (session == nullptr) {
return -1;
}
m_callback_rtp_packet(session->m, session->friend_number, session->payload_type, NULL, NULL);
m_callback_rtp_packet(session->m, session->friend_number, session->payload_type, nullptr, nullptr);
LOGGER_DEBUG(session->m->log, "Stopped receiving on session: %p", session);
return 0;
@ -286,7 +286,7 @@ int handle_rtp_packet(Messenger *m, uint32_t friendnumber, const uint8_t *data,
free(session->mp);
}
session->mp = NULL;
session->mp = nullptr;
}
/* The message came in the allowed time;
@ -341,7 +341,7 @@ int handle_rtp_packet(Messenger *m, uint32_t friendnumber, const uint8_t *data,
free(session->mp);
}
session->mp = NULL;
session->mp = nullptr;
}
} else {
/* Second case */
@ -368,7 +368,7 @@ int handle_rtp_packet(Messenger *m, uint32_t friendnumber, const uint8_t *data,
free(session->mp);
}
session->mp = NULL;
session->mp = nullptr;
goto NEW_MULTIPARTED;
}
} else {

View File

@ -110,10 +110,10 @@ void call_kill_transmission(ToxAVCall *call);
ToxAV *toxav_new(Tox *tox, TOXAV_ERR_NEW *error)
{
TOXAV_ERR_NEW rc = TOXAV_ERR_NEW_OK;
ToxAV *av = NULL;
ToxAV *av = nullptr;
Messenger *m = (Messenger *)tox;
if (tox == NULL) {
if (tox == nullptr) {
rc = TOXAV_ERR_NEW_NULL;
goto END;
}
@ -125,7 +125,7 @@ ToxAV *toxav_new(Tox *tox, TOXAV_ERR_NEW *error)
av = (ToxAV *)calloc(sizeof(ToxAV), 1);
if (av == NULL) {
if (av == nullptr) {
LOGGER_WARNING(m->log, "Allocation failed!");
rc = TOXAV_ERR_NEW_MALLOC;
goto END;
@ -140,7 +140,7 @@ ToxAV *toxav_new(Tox *tox, TOXAV_ERR_NEW *error)
av->m = m;
av->msi = msi_new(av->m);
if (av->msi == NULL) {
if (av->msi == nullptr) {
pthread_mutex_destroy(av->mutex);
rc = TOXAV_ERR_NEW_MALLOC;
goto END;
@ -164,14 +164,14 @@ END:
if (rc != TOXAV_ERR_NEW_OK) {
free(av);
av = NULL;
av = nullptr;
}
return av;
}
void toxav_kill(ToxAV *av)
{
if (av == NULL) {
if (av == nullptr) {
return;
}
@ -189,7 +189,7 @@ void toxav_kill(ToxAV *av)
while (it) {
call_kill_transmission(it);
it->msi_call = NULL; /* msi_kill() frees the call's msi_call handle; which causes #278 */
it->msi_call = nullptr; /* msi_kill() frees the call's msi_call handle; which causes #278 */
it = call_remove(it); /* This will eventually free av->calls */
}
}
@ -212,7 +212,7 @@ void toxav_iterate(ToxAV *av)
{
pthread_mutex_lock(av->mutex);
if (av->calls == NULL) {
if (av->calls == nullptr) {
pthread_mutex_unlock(av->mutex);
return;
}
@ -279,7 +279,7 @@ bool toxav_call(ToxAV *av, uint32_t friend_number, uint32_t audio_bit_rate, uint
call = call_new(av, friend_number, &rc);
if (call == NULL) {
if (call == nullptr) {
goto END;
}
@ -337,7 +337,7 @@ bool toxav_answer(ToxAV *av, uint32_t friend_number, uint32_t audio_bit_rate, ui
call = call_get(av, friend_number);
if (call == NULL) {
if (call == nullptr) {
rc = TOXAV_ERR_ANSWER_FRIEND_NOT_CALLING;
goto END;
}
@ -388,7 +388,7 @@ bool toxav_call_control(ToxAV *av, uint32_t friend_number, TOXAV_CALL_CONTROL co
call = call_get(av, friend_number);
if (call == NULL || (!call->active && control != TOXAV_CALL_CONTROL_CANCEL)) {
if (call == nullptr || (!call->active && control != TOXAV_CALL_CONTROL_CANCEL)) {
rc = TOXAV_ERR_CALL_CONTROL_FRIEND_NOT_IN_CALL;
goto END;
}
@ -443,7 +443,7 @@ bool toxav_call_control(ToxAV *av, uint32_t friend_number, TOXAV_CALL_CONTROL co
goto END;
}
call->msi_call = NULL;
call->msi_call = nullptr;
pthread_mutex_unlock(call->mutex);
/* No mather the case, terminate the call */
@ -545,7 +545,7 @@ bool toxav_audio_set_bit_rate(ToxAV *av, uint32_t friend_number, uint32_t audio_
pthread_mutex_lock(av->mutex);
call = call_get(av, friend_number);
if (call == NULL || !call->active || call->msi_call->state != msi_CallActive) {
if (call == nullptr || !call->active || call->msi_call->state != msi_CallActive) {
pthread_mutex_unlock(av->mutex);
rc = TOXAV_ERR_BIT_RATE_SET_FRIEND_NOT_IN_CALL;
goto END;
@ -617,7 +617,7 @@ bool toxav_video_set_bit_rate(ToxAV *av, uint32_t friend_number, uint32_t video_
pthread_mutex_lock(av->mutex);
call = call_get(av, friend_number);
if (call == NULL || !call->active || call->msi_call->state != msi_CallActive) {
if (call == nullptr || !call->active || call->msi_call->state != msi_CallActive) {
pthread_mutex_unlock(av->mutex);
rc = TOXAV_ERR_BIT_RATE_SET_FRIEND_NOT_IN_CALL;
goto END;
@ -702,7 +702,7 @@ bool toxav_audio_send_frame(ToxAV *av, uint32_t friend_number, const int16_t *pc
call = call_get(av, friend_number);
if (call == NULL || !call->active || call->msi_call->state != msi_CallActive) {
if (call == nullptr || !call->active || call->msi_call->state != msi_CallActive) {
pthread_mutex_unlock(av->mutex);
rc = TOXAV_ERR_SEND_FRAME_FRIEND_NOT_IN_CALL;
goto END;
@ -719,7 +719,7 @@ bool toxav_audio_send_frame(ToxAV *av, uint32_t friend_number, const int16_t *pc
pthread_mutex_lock(call->mutex_audio);
pthread_mutex_unlock(av->mutex);
if (pcm == NULL) {
if (pcm == nullptr) {
pthread_mutex_unlock(call->mutex_audio);
rc = TOXAV_ERR_SEND_FRAME_NULL;
goto END;
@ -787,7 +787,7 @@ bool toxav_video_send_frame(ToxAV *av, uint32_t friend_number, uint16_t width, u
call = call_get(av, friend_number);
if (call == NULL || !call->active || call->msi_call->state != msi_CallActive) {
if (call == nullptr || !call->active || call->msi_call->state != msi_CallActive) {
pthread_mutex_unlock(av->mutex);
rc = TOXAV_ERR_SEND_FRAME_FRIEND_NOT_IN_CALL;
goto END;
@ -804,7 +804,7 @@ bool toxav_video_send_frame(ToxAV *av, uint32_t friend_number, uint16_t width, u
pthread_mutex_lock(call->mutex_video);
pthread_mutex_unlock(av->mutex);
if (y == NULL || u == NULL || v == NULL) {
if (y == nullptr || u == nullptr || v == nullptr) {
pthread_mutex_unlock(call->mutex_video);
rc = TOXAV_ERR_SEND_FRAME_NULL;
goto END;
@ -844,7 +844,7 @@ bool toxav_video_send_frame(ToxAV *av, uint32_t friend_number, uint16_t width, u
++call->video.second->frame_counter;
{ /* Send frames */
vpx_codec_iter_t iter = NULL;
vpx_codec_iter_t iter = nullptr;
const vpx_codec_cx_pkt_t *pkt;
while ((pkt = vpx_codec_get_cx_data(call->video.second->encoder, &iter))) {
@ -948,9 +948,9 @@ int callback_invite(void *toxav_inst, MSICall *call)
ToxAV *toxav = (ToxAV *)toxav_inst;
pthread_mutex_lock(toxav->mutex);
ToxAVCall *av_call = call_new(toxav, call->friend_number, NULL);
ToxAVCall *av_call = call_new(toxav, call->friend_number, nullptr);
if (av_call == NULL) {
if (av_call == nullptr) {
LOGGER_WARNING(toxav->m->log, "Failed to initialize call...");
pthread_mutex_unlock(toxav->mutex);
return -1;
@ -978,7 +978,7 @@ int callback_start(void *toxav_inst, MSICall *call)
ToxAVCall *av_call = call_get(toxav, call->friend_number);
if (av_call == NULL) {
if (av_call == nullptr) {
/* Should this ever happen? */
pthread_mutex_unlock(toxav->mutex);
return -1;
@ -1083,7 +1083,7 @@ ToxAVCall *call_new(ToxAV *av, uint32_t friend_number, TOXAV_ERR_CALL *error)
{
/* Assumes mutex locked */
TOXAV_ERR_CALL rc = TOXAV_ERR_CALL_OK;
ToxAVCall *call = NULL;
ToxAVCall *call = nullptr;
if (m_friend_exists(av->m, friend_number) == 0) {
rc = TOXAV_ERR_CALL_FRIEND_NOT_FOUND;
@ -1095,7 +1095,7 @@ ToxAVCall *call_new(ToxAV *av, uint32_t friend_number, TOXAV_ERR_CALL *error)
goto END;
}
if (call_get(av, friend_number) != NULL) {
if (call_get(av, friend_number) != nullptr) {
rc = TOXAV_ERR_CALL_FRIEND_ALREADY_IN_CALL;
goto END;
}
@ -1103,7 +1103,7 @@ ToxAVCall *call_new(ToxAV *av, uint32_t friend_number, TOXAV_ERR_CALL *error)
call = (ToxAVCall *)calloc(sizeof(ToxAVCall), 1);
if (call == NULL) {
if (call == nullptr) {
rc = TOXAV_ERR_CALL_MALLOC;
goto END;
}
@ -1111,12 +1111,12 @@ ToxAVCall *call_new(ToxAV *av, uint32_t friend_number, TOXAV_ERR_CALL *error)
call->av = av;
call->friend_number = friend_number;
if (av->calls == NULL) { /* Creating */
if (av->calls == nullptr) { /* Creating */
av->calls = (ToxAVCall **)calloc(sizeof(ToxAVCall *), friend_number + 1);
if (av->calls == NULL) {
if (av->calls == nullptr) {
free(call);
call = NULL;
call = nullptr;
rc = TOXAV_ERR_CALL_MALLOC;
goto END;
}
@ -1125,9 +1125,9 @@ ToxAVCall *call_new(ToxAV *av, uint32_t friend_number, TOXAV_ERR_CALL *error)
} else if (av->calls_tail < friend_number) { /* Appending */
ToxAVCall **tmp = (ToxAVCall **)realloc(av->calls, sizeof(ToxAVCall *) * (friend_number + 1));
if (tmp == NULL) {
if (tmp == nullptr) {
free(call);
call = NULL;
call = nullptr;
rc = TOXAV_ERR_CALL_MALLOC;
goto END;
}
@ -1138,7 +1138,7 @@ ToxAVCall *call_new(ToxAV *av, uint32_t friend_number, TOXAV_ERR_CALL *error)
uint32_t i = av->calls_tail + 1;
for (; i < friend_number; i ++) {
av->calls[i] = NULL;
av->calls[i] = nullptr;
}
call->prev = av->calls[av->calls_tail];
@ -1164,16 +1164,16 @@ END:
ToxAVCall *call_get(ToxAV *av, uint32_t friend_number)
{
/* Assumes mutex locked */
if (av->calls == NULL || av->calls_tail < friend_number) {
return NULL;
if (av->calls == nullptr || av->calls_tail < friend_number) {
return nullptr;
}
return av->calls[friend_number];
}
ToxAVCall *call_remove(ToxAVCall *call)
{
if (call == NULL) {
return NULL;
if (call == nullptr) {
return nullptr;
}
uint32_t friend_number = call->friend_number;
@ -1186,7 +1186,7 @@ ToxAVCall *call_remove(ToxAVCall *call)
* removed from the msi call.
*/
if (call->msi_call) {
call->msi_call->av_call = NULL;
call->msi_call->av_call = nullptr;
}
free(call);
@ -1207,21 +1207,21 @@ ToxAVCall *call_remove(ToxAVCall *call)
goto CLEAR;
}
av->calls[friend_number] = NULL;
av->calls[friend_number] = nullptr;
return next;
CLEAR:
av->calls_head = av->calls_tail = 0;
free(av->calls);
av->calls = NULL;
av->calls = nullptr;
return NULL;
return nullptr;
}
bool call_prepare_transmission(ToxAVCall *call)
{
/* Assumes mutex locked */
if (call == NULL) {
if (call == nullptr) {
return false;
}
@ -1292,12 +1292,12 @@ FAILURE:
bwc_kill(call->bwc);
rtp_kill(call->audio.first);
ac_kill(call->audio.second);
call->audio.first = NULL;
call->audio.second = NULL;
call->audio.first = nullptr;
call->audio.second = nullptr;
rtp_kill(call->video.first);
vc_kill(call->video.second);
call->video.first = NULL;
call->video.second = NULL;
call->video.first = nullptr;
call->video.second = nullptr;
pthread_mutex_destroy(call->mutex);
FAILURE_2:
pthread_mutex_destroy(call->mutex_video);
@ -1307,7 +1307,7 @@ FAILURE_3:
}
void call_kill_transmission(ToxAVCall *call)
{
if (call == NULL || call->active == 0) {
if (call == nullptr || call->active == 0) {
return;
}
@ -1324,13 +1324,13 @@ void call_kill_transmission(ToxAVCall *call)
rtp_kill(call->audio.first);
ac_kill(call->audio.second);
call->audio.first = NULL;
call->audio.second = NULL;
call->audio.first = nullptr;
call->audio.second = nullptr;
rtp_kill(call->video.first);
vc_kill(call->video.second);
call->video.first = NULL;
call->video.second = NULL;
call->video.first = nullptr;
call->video.second = nullptr;
pthread_mutex_destroy(call->mutex_audio);
pthread_mutex_destroy(call->mutex_video);

View File

@ -43,20 +43,20 @@ VCSession *vc_new(Logger *log, ToxAV *av, uint32_t friend_number, toxav_video_re
if (!vc) {
LOGGER_WARNING(log, "Allocation failed! Application might misbehave!");
return NULL;
return nullptr;
}
if (create_recursive_mutex(vc->queue_mutex) != 0) {
LOGGER_WARNING(log, "Failed to create recursive mutex!");
free(vc);
return NULL;
return nullptr;
}
if (!(vc->vbuf_raw = rb_new(VIDEO_DECODE_BUFFER_SIZE))) {
goto BASE_CLEANUP;
}
rc = vpx_codec_dec_init(vc->decoder, VIDEO_CODEC_DECODER_INTERFACE, NULL, 0);
rc = vpx_codec_dec_init(vc->decoder, VIDEO_CODEC_DECODER_INTERFACE, nullptr, 0);
if (rc != VPX_CODEC_OK) {
LOGGER_ERROR(log, "Init video_decoder failed: %s", vpx_codec_err_to_string(rc));
@ -118,7 +118,7 @@ BASE_CLEANUP:
pthread_mutex_destroy(vc->queue_mutex);
rb_kill((RingBuffer *)vc->vbuf_raw);
free(vc);
return NULL;
return nullptr;
}
void vc_kill(VCSession *vc)
{
@ -157,13 +157,13 @@ void vc_iterate(VCSession *vc)
if (rb_read((RingBuffer *)vc->vbuf_raw, (void **)&p)) {
pthread_mutex_unlock(vc->queue_mutex);
rc = vpx_codec_decode(vc->decoder, p->data, p->len, NULL, MAX_DECODE_TIME_US);
rc = vpx_codec_decode(vc->decoder, p->data, p->len, nullptr, MAX_DECODE_TIME_US);
free(p);
if (rc != VPX_CODEC_OK) {
LOGGER_ERROR(vc->log, "Error decoding video: %s", vpx_codec_err_to_string(rc));
} else {
vpx_codec_iter_t iter = NULL;
vpx_codec_iter_t iter = nullptr;
vpx_image_t *dest = vpx_codec_get_frame(vc->decoder, &iter);
/* Play decoded images */

View File

@ -9,6 +9,7 @@ filegroup(
cc_library(
name = "ccompat",
hdrs = ["ccompat.h"],
visibility = ["//c-toxcore:__subpackages__"],
)
cc_library(
@ -31,6 +32,7 @@ cc_library(
name = "list",
srcs = ["list.c"],
hdrs = ["list.h"],
deps = [":ccompat"],
)
cc_library(

View File

@ -376,7 +376,7 @@ int packed_node_size(uint8_t ip_family)
*/
int pack_ip_port(uint8_t *data, uint16_t length, const IP_Port *ip_port)
{
if (data == NULL) {
if (data == nullptr) {
return -1;
}
@ -454,7 +454,7 @@ static int DHT_create_packet(const uint8_t public_key[CRYPTO_PUBLIC_KEY_SIZE],
*/
int unpack_ip_port(IP_Port *ip_port, const uint8_t *data, uint16_t length, uint8_t tcp_enabled)
{
if (data == NULL) {
if (data == nullptr) {
return -1;
}
@ -772,7 +772,7 @@ static void get_close_nodes_inner(const uint8_t *public_key, Node_format *nodes_
continue;
}
const IPPTsPng *ipptp = NULL;
const IPPTsPng *ipptp = nullptr;
if (sa_family == TOX_AF_INET) {
ipptp = &client->assoc4;
@ -942,8 +942,8 @@ static void sort_client_list(Client_data *list, unsigned int length, const uint8
static void update_client_with_reset(Client_data *client, const IP_Port *ip_port)
{
IPPTsPng *ipptp_write = NULL;
IPPTsPng *ipptp_clear = NULL;
IPPTsPng *ipptp_write = nullptr;
IPPTsPng *ipptp_clear = nullptr;
if (ip_port->ip.family == TOX_AF_INET) {
ipptp_write = &client->assoc4;
@ -1161,7 +1161,7 @@ uint32_t addto_lists(DHT *dht, IP_Port ip_port, const uint8_t *public_key)
used++;
}
DHT_Friend *friend_foundip = 0;
DHT_Friend *friend_foundip = nullptr;
for (uint32_t i = 0; i < dht->num_friends; ++i) {
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
uint64_t ping_id = 0;
if (sendback_node != NULL) {
if (sendback_node != nullptr) {
memcpy(plain_message + sizeof(receiver), sendback_node, sizeof(Node_format));
ping_id = ping_array_add(dht->dht_harden_ping_array, plain_message, sizeof(plain_message));
} else {
@ -1533,7 +1533,7 @@ int DHT_addfriend(DHT *dht, const uint8_t *public_key, void (*ip_callback)(void
DHT_Friend *temp = (DHT_Friend *)realloc(dht->friends_list, sizeof(DHT_Friend) * (dht->num_friends + 1));
if (temp == NULL) {
if (temp == nullptr) {
return -1;
}
@ -1573,8 +1573,8 @@ int DHT_delfriend(DHT *dht, const uint8_t *public_key, uint16_t lock_count)
if (dht_friend->lock_count && lock_count) { /* DHT friend is still in use.*/
--lock_count;
dht_friend->callbacks[lock_count].ip_callback = NULL;
dht_friend->callbacks[lock_count].data = NULL;
dht_friend->callbacks[lock_count].ip_callback = nullptr;
dht_friend->callbacks[lock_count].data = nullptr;
dht_friend->callbacks[lock_count].number = 0;
return 0;
}
@ -1589,13 +1589,13 @@ int DHT_delfriend(DHT *dht, const uint8_t *public_key, uint16_t lock_count)
if (dht->num_friends == 0) {
free(dht->friends_list);
dht->friends_list = NULL;
dht->friends_list = nullptr;
return 0;
}
DHT_Friend *temp = (DHT_Friend *)realloc(dht->friends_list, sizeof(DHT_Friend) * (dht->num_friends));
if (temp == NULL) {
if (temp == nullptr) {
return -1;
}
@ -1664,7 +1664,7 @@ static uint8_t do_ping_and_sendnode_requests(DHT *dht, uint64_t *lastgetnode, co
not_kill++;
if (is_timeout(assoc->last_pinged, PING_INTERVAL)) {
getnodes(dht, assoc->ip_port, client->public_key, public_key, NULL);
getnodes(dht, assoc->ip_port, client->public_key, public_key, nullptr);
assoc->last_pinged = temp_time;
}
@ -1696,7 +1696,7 @@ static uint8_t do_ping_and_sendnode_requests(DHT *dht, uint64_t *lastgetnode, co
rand_node += rand() % (num_nodes - (rand_node + 1));
}
getnodes(dht, assoc_list[rand_node]->ip_port, client_list[rand_node]->public_key, public_key, NULL);
getnodes(dht, assoc_list[rand_node]->ip_port, client_list[rand_node]->public_key, public_key, nullptr);
*lastgetnode = temp_time;
++*bootstrap_times;
@ -1715,7 +1715,7 @@ static void do_DHT_friends(DHT *dht)
for (size_t j = 0; j < dht_friend->num_to_bootstrap; ++j) {
getnodes(dht, dht_friend->to_bootstrap[j].ip_port, dht_friend->to_bootstrap[j].public_key, dht_friend->public_key,
NULL);
nullptr);
}
dht_friend->num_to_bootstrap = 0;
@ -1732,7 +1732,7 @@ static void do_DHT_friends(DHT *dht)
static void do_Close(DHT *dht)
{
for (size_t i = 0; i < dht->num_to_bootstrap; ++i) {
getnodes(dht, dht->to_bootstrap[i].ip_port, dht->to_bootstrap[i].public_key, dht->self_public_key, NULL);
getnodes(dht, dht->to_bootstrap[i].ip_port, dht->to_bootstrap[i].public_key, dht->self_public_key, nullptr);
}
dht->num_to_bootstrap = 0;
@ -1767,18 +1767,18 @@ static void do_Close(DHT *dht)
void DHT_getnodes(DHT *dht, const IP_Port *from_ipp, const uint8_t *from_id, const uint8_t *which_id)
{
getnodes(dht, *from_ipp, from_id, which_id, NULL);
getnodes(dht, *from_ipp, from_id, which_id, nullptr);
}
void DHT_bootstrap(DHT *dht, IP_Port ip_port, const uint8_t *public_key)
{
getnodes(dht, ip_port, public_key, dht->self_public_key, NULL);
getnodes(dht, ip_port, public_key, dht->self_public_key, nullptr);
}
int DHT_bootstrap_from_address(DHT *dht, const char *address, uint8_t ipv6enabled,
uint16_t port, const uint8_t *public_key)
{
IP_Port ip_port_v64;
IP *ip_extra = NULL;
IP *ip_extra = nullptr;
IP_Port ip_port_v4;
ip_init(&ip_port_v64.ip, ipv6enabled);
@ -1793,7 +1793,7 @@ int DHT_bootstrap_from_address(DHT *dht, const char *address, uint8_t ipv6enable
ip_port_v64.port = port;
DHT_bootstrap(dht, ip_port_v64, public_key);
if ((ip_extra != NULL) && ip_isset(ip_extra)) {
if ((ip_extra != nullptr) && ip_isset(ip_extra)) {
ip_port_v4.port = port;
DHT_bootstrap(dht, ip_port_v4, public_key);
}
@ -2319,7 +2319,7 @@ static IPPTsPng *get_closelist_IPPTsPng(DHT *dht, const uint8_t *public_key, Fam
}
}
return NULL;
return nullptr;
}
/*
@ -2391,7 +2391,7 @@ static int handle_hardening(void *object, IP_Port source, const uint8_t *source_
uint16_t length_nodes = length - 1 - CRYPTO_PUBLIC_KEY_SIZE;
Node_format nodes[MAX_SENT_NODES];
int num_nodes = unpack_nodes(nodes, MAX_SENT_NODES, 0, packet + 1 + CRYPTO_PUBLIC_KEY_SIZE, length_nodes, 0);
int num_nodes = unpack_nodes(nodes, MAX_SENT_NODES, nullptr, packet + 1 + CRYPTO_PUBLIC_KEY_SIZE, length_nodes, 0);
/* TODO(irungentoo): MAX_SENT_NODES nodes should be returned at all times
(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_
IPPTsPng *temp = get_closelist_IPPTsPng(dht, packet + 1, nodes[0].ip_port.ip.family);
if (temp == NULL) {
if (temp == nullptr) {
return 1;
}
@ -2465,21 +2465,21 @@ static uint16_t list_nodes(Client_data *list, size_t length, Node_format *nodes,
uint16_t count = 0;
for (size_t i = length; i != 0; --i) {
IPPTsPng *assoc = NULL;
IPPTsPng *assoc = nullptr;
if (!is_timeout(list[i - 1].assoc4.timestamp, BAD_NODE_TIMEOUT)) {
assoc = &list[i - 1].assoc4;
}
if (!is_timeout(list[i - 1].assoc6.timestamp, BAD_NODE_TIMEOUT)) {
if (assoc == NULL) {
if (assoc == nullptr) {
assoc = &list[i - 1].assoc6;
} else if (rand() % 2) {
assoc = &list[i - 1].assoc6;
}
}
if (assoc != NULL) {
if (assoc != nullptr) {
memcpy(nodes[count].public_key, list[i - 1].public_key, CRYPTO_PUBLIC_KEY_SIZE);
nodes[count].ip_port = assoc->ip_port;
++count;
@ -2635,14 +2635,14 @@ DHT *new_DHT(Logger *log, Networking_Core *net, bool holepunching_enabled)
/* init time */
unix_time_update();
if (net == NULL) {
return NULL;
if (net == nullptr) {
return nullptr;
}
DHT *dht = (DHT *)calloc(1, sizeof(DHT));
if (dht == NULL) {
return NULL;
if (dht == nullptr) {
return nullptr;
}
dht->log = log;
@ -2652,9 +2652,9 @@ DHT *new_DHT(Logger *log, Networking_Core *net, bool holepunching_enabled)
dht->ping = ping_new(dht);
if (dht->ping == NULL) {
if (dht->ping == nullptr) {
kill_DHT(dht);
return NULL;
return nullptr;
}
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)
uint8_t random_key_bytes[CRYPTO_PUBLIC_KEY_SIZE];
random_bytes(random_key_bytes, sizeof(random_key_bytes));
if (DHT_addfriend(dht, random_key_bytes, 0, 0, 0, 0) != 0) {
if (DHT_addfriend(dht, random_key_bytes, nullptr, nullptr, 0, nullptr) != 0) {
kill_DHT(dht);
return NULL;
return nullptr;
}
}
@ -2706,10 +2706,10 @@ void do_DHT(DHT *dht)
}
void kill_DHT(DHT *dht)
{
networking_registerhandler(dht->net, NET_PACKET_GET_NODES, NULL, NULL);
networking_registerhandler(dht->net, NET_PACKET_SEND_NODES_IPV6, NULL, NULL);
cryptopacket_registerhandler(dht, CRYPTO_PACKET_NAT_PING, NULL, NULL);
cryptopacket_registerhandler(dht, CRYPTO_PACKET_HARDENING, NULL, NULL);
networking_registerhandler(dht->net, NET_PACKET_GET_NODES, nullptr, nullptr);
networking_registerhandler(dht->net, NET_PACKET_SEND_NODES_IPV6, nullptr, nullptr);
cryptopacket_registerhandler(dht, CRYPTO_PACKET_NAT_PING, nullptr, nullptr);
cryptopacket_registerhandler(dht, CRYPTO_PACKET_HARDENING, nullptr, nullptr);
ping_array_kill(dht->dht_ping_array);
ping_array_kill(dht->dht_harden_ping_array);
ping_kill(dht->ping);
@ -2817,7 +2817,7 @@ void DHT_save(DHT *dht, uint8_t *data)
/* Start sending packets after DHT loaded_friends_list and loaded_clients_list are set */
int DHT_connect_after_load(DHT *dht)
{
if (dht == NULL) {
if (dht == nullptr) {
return -1;
}
@ -2828,7 +2828,7 @@ int DHT_connect_after_load(DHT *dht)
/* DHT is connected, stop. */
if (DHT_non_lan_connected(dht)) {
free(dht->loaded_nodes_list);
dht->loaded_nodes_list = NULL;
dht->loaded_nodes_list = nullptr;
dht->loaded_num_nodes = 0;
return 0;
}
@ -2857,7 +2857,7 @@ static int dht_load_state_callback(void *outer, const uint8_t *data, uint32_t le
// Copy to loaded_clients_list
dht->loaded_nodes_list = (Node_format *)calloc(MAX_SAVED_DHT_NODES, sizeof(Node_format));
int num = unpack_nodes(dht->loaded_nodes_list, MAX_SAVED_DHT_NODES, NULL, data, length, 0);
int num = unpack_nodes(dht->loaded_nodes_list, MAX_SAVED_DHT_NODES, nullptr, data, length, 0);
if (num > 0) {
dht->loaded_num_nodes = num;

View File

@ -52,7 +52,7 @@ static void fetch_broadcast_info(uint16_t port)
IP_ADAPTER_INFO *pAdapterInfo = (IP_ADAPTER_INFO *)malloc(sizeof(IP_ADAPTER_INFO));
unsigned long ulOutBufLen = sizeof(IP_ADAPTER_INFO);
if (pAdapterInfo == NULL) {
if (pAdapterInfo == nullptr) {
return;
}
@ -60,7 +60,7 @@ static void fetch_broadcast_info(uint16_t port)
free(pAdapterInfo);
pAdapterInfo = (IP_ADAPTER_INFO *)malloc(ulOutBufLen);
if (pAdapterInfo == NULL) {
if (pAdapterInfo == nullptr) {
return;
}
}
@ -405,5 +405,5 @@ void lan_discovery_init(DHT *dht)
void lan_discovery_kill(DHT *dht)
{
networking_registerhandler(dht_get_net(dht), NET_PACKET_LAN_DISCOVERY, NULL, NULL);
networking_registerhandler(dht_get_net(dht), NET_PACKET_LAN_DISCOVERY, nullptr, nullptr);
}

View File

@ -57,13 +57,13 @@ static int realloc_friendlist(Messenger *m, uint32_t num)
{
if (num == 0) {
free(m->friendlist);
m->friendlist = NULL;
m->friendlist = nullptr;
return 0;
}
Friend *newfriendlist = (Friend *)realloc(m->friendlist, num * sizeof(Friend));
if (newfriendlist == NULL) {
if (newfriendlist == nullptr) {
return -1;
}
@ -322,8 +322,8 @@ static int clear_receipts(Messenger *m, int32_t friendnumber)
receipts = temp_r;
}
m->friendlist[friendnumber].receipts_start = NULL;
m->friendlist[friendnumber].receipts_end = NULL;
m->friendlist[friendnumber].receipts_start = nullptr;
m->friendlist[friendnumber].receipts_end = nullptr;
return 0;
}
@ -349,7 +349,7 @@ static int add_receipt(Messenger *m, int32_t friendnumber, uint32_t packet_num,
}
m->friendlist[friendnumber].receipts_end = new_receipts;
new_receipts->next = NULL;
new_receipts->next = nullptr;
return 0;
}
/*
@ -393,7 +393,7 @@ static int do_receipts(Messenger *m, int32_t friendnumber, void *userdata)
}
if (!m->friendlist[friendnumber].receipts_start) {
m->friendlist[friendnumber].receipts_end = NULL;
m->friendlist[friendnumber].receipts_end = nullptr;
}
return 0;
@ -416,7 +416,8 @@ int m_delfriend(Messenger *m, int32_t friendnumber)
clear_receipts(m, friendnumber);
remove_request_received(m->fr, m->friendlist[friendnumber].real_pk);
friend_connection_callbacks(m->fr_c, m->friendlist[friendnumber].friendcon_id, MESSENGER_CALLBACK_INDEX, 0, 0, 0, 0, 0);
friend_connection_callbacks(m->fr_c, m->friendlist[friendnumber].friendcon_id, MESSENGER_CALLBACK_INDEX, nullptr,
nullptr, nullptr, nullptr, 0);
if (friend_con_connected(m->fr_c, m->friendlist[friendnumber].friendcon_id) == FRIENDCONN_STATUS_CONNECTED) {
send_offline_packet(m, m->friendlist[friendnumber].friendcon_id);
@ -601,7 +602,7 @@ int setname(Messenger *m, const uint8_t *name, uint16_t length)
*/
uint16_t getself_name(const Messenger *m, uint8_t *name)
{
if (name == NULL) {
if (name == nullptr) {
return 0;
}
@ -1283,7 +1284,7 @@ int file_control(const Messenger *m, int32_t friendnumber, uint32_t filenumber,
}
}
if (send_file_control_packet(m, friendnumber, send_receive, file_number, control, 0, 0)) {
if (send_file_control_packet(m, friendnumber, send_receive, file_number, control, nullptr, 0)) {
if (control == FILECONTROL_KILL) {
ft->status = FILESTATUS_NONE;
@ -1556,7 +1557,7 @@ static void do_reqchunk_filecb(Messenger *m, int32_t friendnumber, void *userdat
if (ft->size == 0) {
/* Send 0 data to friend if file is 0 length. */
file_data(m, friendnumber, i, 0, 0, 0);
file_data(m, friendnumber, i, 0, nullptr, 0);
break;
}
@ -1619,7 +1620,7 @@ static struct File_Transfers *get_file_transfer(uint8_t receive_send, uint8_t fi
}
if (ft->status == FILESTATUS_NONE) {
return NULL;
return nullptr;
}
return ft;
@ -1639,10 +1640,10 @@ static int handle_filecontrol(Messenger *m, int32_t friendnumber, uint8_t receiv
uint32_t real_filenumber;
struct File_Transfers *ft = get_file_transfer(receive_send, filenumber, &real_filenumber, &m->friendlist[friendnumber]);
if (ft == NULL) {
if (ft == nullptr) {
LOGGER_DEBUG(m->log, "file control (friend %d, file %d): file transfer does not exist; telling the other to kill it",
friendnumber, filenumber);
send_file_control_packet(m, friendnumber, !receive_send, filenumber, FILECONTROL_KILL, 0, 0);
send_file_control_packet(m, friendnumber, !receive_send, filenumber, FILECONTROL_KILL, nullptr, 0);
return -1;
}
@ -1919,7 +1920,7 @@ static int friend_already_added(const uint8_t *real_pk, void *data)
Messenger *new_messenger(Messenger_Options *options, unsigned int *error)
{
if (!options) {
return NULL;
return nullptr;
}
if (error) {
@ -1929,22 +1930,22 @@ Messenger *new_messenger(Messenger_Options *options, unsigned int *error)
Messenger *m = (Messenger *)calloc(1, sizeof(Messenger));
if (!m) {
return NULL;
return nullptr;
}
m->fr = friendreq_new();
if (!m->fr) {
free(m);
return NULL;
return nullptr;
}
Logger *log = NULL;
Logger *log = nullptr;
if (options->log_callback) {
log = logger_new();
if (log != NULL) {
if (log != nullptr) {
logger_callback_log(log, options->log_callback, m, options->log_user_data);
}
}
@ -1961,7 +1962,7 @@ Messenger *new_messenger(Messenger_Options *options, unsigned int *error)
m->net = new_networking_ex(log, ip, options->port_range[0], options->port_range[1], &net_err);
}
if (m->net == NULL) {
if (m->net == nullptr) {
friendreq_kill(m->fr);
free(m);
@ -1969,26 +1970,26 @@ Messenger *new_messenger(Messenger_Options *options, unsigned int *error)
*error = MESSENGER_ERROR_PORT;
}
return NULL;
return nullptr;
}
m->dht = new_DHT(m->log, m->net, options->hole_punching_enabled);
if (m->dht == NULL) {
if (m->dht == nullptr) {
kill_networking(m->net);
friendreq_kill(m->fr);
free(m);
return NULL;
return nullptr;
}
m->net_crypto = new_net_crypto(m->log, m->dht, &options->proxy_info);
if (m->net_crypto == NULL) {
if (m->net_crypto == nullptr) {
kill_networking(m->net);
kill_DHT(m->dht);
friendreq_kill(m->fr);
free(m);
return NULL;
return nullptr;
}
m->onion = new_onion(m->dht);
@ -2006,14 +2007,14 @@ Messenger *new_messenger(Messenger_Options *options, unsigned int *error)
kill_networking(m->net);
friendreq_kill(m->fr);
free(m);
return NULL;
return nullptr;
}
if (options->tcp_server_port) {
m->tcp_server = new_TCP_server(options->ipv6enabled, 1, &options->tcp_server_port, dht_get_self_secret_key(m->dht),
m->onion);
if (m->tcp_server == NULL) {
if (m->tcp_server == nullptr) {
kill_friend_connections(m->fr_c);
kill_onion(m->onion);
kill_onion_announce(m->onion_a);
@ -2028,7 +2029,7 @@ Messenger *new_messenger(Messenger_Options *options, unsigned int *error)
*error = MESSENGER_ERROR_TCP_SERVER;
}
return NULL;
return nullptr;
}
}
@ -2292,7 +2293,7 @@ static int m_handle_packet(void *object, int i, const uint8_t *temp, uint16_t le
memcpy(ft->id, data + 1 + sizeof(uint32_t) + sizeof(uint64_t), FILE_ID_LENGTH);
VLA(uint8_t, filename_terminated, filename_length + 1);
uint8_t *filename = NULL;
uint8_t *filename = nullptr;
if (filename_length) {
/* 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
const uint8_t *file_data;
if (file_data_length == 0) {
file_data = NULL;
file_data = nullptr;
} else {
file_data = data + 1;
}
@ -2386,7 +2387,7 @@ static int m_handle_packet(void *object, int i, const uint8_t *temp, uint16_t le
if (file_data_length && (ft->transferred >= ft->size || file_data_length != MAX_FILE_DATA_SIZE)) {
file_data_length = 0;
file_data = NULL;
file_data = nullptr;
position = ft->transferred;
/* Full file received. */
@ -2480,7 +2481,7 @@ static void do_friends(Messenger *m, void *userdata)
do_receipts(m, i, userdata);
do_reqchunk_filecb(m, i, userdata);
m->friendlist[i].last_seen_time = (uint64_t) time(NULL);
m->friendlist[i].last_seen_time = (uint64_t) time(nullptr);
}
}
}
@ -2585,7 +2586,7 @@ void do_messenger(Messenger *m, void *userdata)
for (client = 0; client < LCLIENT_LIST; client++) {
const Client_data *cptr = dht_get_close_client(m->dht, client);
const IPPTsPng *assoc = NULL;
const IPPTsPng *assoc = nullptr;
uint32_t a;
for (a = 0, assoc = &cptr->assoc4; a < 2; a++, assoc = &cptr->assoc6) {
@ -2647,7 +2648,7 @@ void do_messenger(Messenger *m, void *userdata)
if (dht2m[friend_idx] >= 0) {
msgfptr = &m->friendlist[dht2m[friend_idx]];
} else {
msgfptr = NULL;
msgfptr = nullptr;
}
dhtfptr = dht_get_friend(m->dht, friend_idx);
@ -2665,7 +2666,7 @@ void do_messenger(Messenger *m, void *userdata)
for (client = 0; client < MAX_FRIEND_CLIENTS; client++) {
Client_data *cptr = &dhtfptr->client_list[client];
IPPTsPng *assoc = NULL;
IPPTsPng *assoc = nullptr;
uint32_t a;
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
break;
}
unpack_nodes(m->loaded_relays, NUM_SAVED_TCP_RELAYS, 0, data, length, 1);
unpack_nodes(m->loaded_relays, NUM_SAVED_TCP_RELAYS, nullptr, data, length, 1);
m->has_added_relays = 0;
break;
@ -3087,7 +3088,7 @@ static int messenger_load_state_callback(void *outer, const uint8_t *data, uint3
break;
}
int i, num = unpack_nodes(nodes, NUM_SAVED_PATH_NODES, 0, data, length, 0);
int i, num = unpack_nodes(nodes, NUM_SAVED_PATH_NODES, nullptr, data, length, 0);
for (i = 0; i < num; ++i) {
onion_add_bs_path_node(m->onion_c, nodes[i].ip_port, nodes[i].public_key);

View File

@ -382,7 +382,7 @@ static int client_send_pending_data(TCP_Client_Connection *con)
con->priority_queue_start = p;
if (!p) {
con->priority_queue_end = NULL;
con->priority_queue_end = nullptr;
return 0;
}
@ -401,7 +401,7 @@ static bool client_add_priority(TCP_Client_Connection *con, const uint8_t *packe
return 0;
}
new_list->next = NULL;
new_list->next = nullptr;
new_list->size = size;
new_list->sent = sent;
memcpy(new_list->data, packet, size);
@ -694,16 +694,16 @@ TCP_Client_Connection *new_TCP_connection(IP_Port ip_port, const uint8_t *public
const uint8_t *self_secret_key, TCP_Proxy_Info *proxy_info)
{
if (networking_at_startup() != 0) {
return NULL;
return nullptr;
}
if (ip_port.ip.family != TOX_AF_INET && ip_port.ip.family != TOX_AF_INET6) {
return NULL;
return nullptr;
}
TCP_Proxy_Info default_proxyinfo;
if (proxy_info == NULL) {
if (proxy_info == nullptr) {
default_proxyinfo.proxy_type = TCP_PROXY_NONE;
proxy_info = &default_proxyinfo;
}
@ -717,24 +717,24 @@ TCP_Client_Connection *new_TCP_connection(IP_Port ip_port, const uint8_t *public
Socket sock = net_socket(family, TOX_SOCK_STREAM, TOX_PROTO_TCP);
if (!sock_valid(sock)) {
return NULL;
return nullptr;
}
if (!set_socket_nosigpipe(sock)) {
kill_sock(sock);
return 0;
return nullptr;
}
if (!(set_socket_nonblock(sock) && connect_sock_to(sock, ip_port, proxy_info))) {
kill_sock(sock);
return NULL;
return nullptr;
}
TCP_Client_Connection *temp = (TCP_Client_Connection *)calloc(sizeof(TCP_Client_Connection), 1);
if (temp == NULL) {
if (temp == nullptr) {
kill_sock(sock);
return NULL;
return nullptr;
}
temp->sock = sock;
@ -761,7 +761,7 @@ TCP_Client_Connection *new_TCP_connection(IP_Port ip_port, const uint8_t *public
if (generate_handshake(temp) == -1) {
kill_sock(sock);
free(temp);
return NULL;
return nullptr;
}
break;
@ -1062,7 +1062,7 @@ void do_TCP_connection(TCP_Client_Connection *TCP_connection, void *userdata)
*/
void kill_TCP_connection(TCP_Client_Connection *TCP_connection)
{
if (TCP_connection == NULL) {
if (TCP_connection == nullptr) {
return;
}

View File

@ -78,7 +78,7 @@ const uint8_t *tcp_connections_public_key(const TCP_Connections *tcp_c)
array, \
(num) * sizeof(element_type)), \
temp_pointer ? (array = temp_pointer, 0) : -1) \
: (free(array), array = NULL, 0))
: (free(array), array = nullptr, 0))
/* 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
return 1;
}
if (tcp_c->connections == NULL) {
if (tcp_c->connections == nullptr) {
return 1;
}
@ -110,7 +110,7 @@ static bool tcp_connections_number_not_valid(const TCP_Connections *tcp_c, int t
return 1;
}
if (tcp_c->tcp_connections == NULL) {
if (tcp_c->tcp_connections == nullptr) {
return 1;
}
@ -239,7 +239,7 @@ static int wipe_tcp_connection(TCP_Connections *tcp_c, int tcp_connections_numbe
static TCP_Connection_to *get_connection(const TCP_Connections *tcp_c, int connections_number)
{
if (connections_number_not_valid(tcp_c, connections_number)) {
return 0;
return nullptr;
}
return &tcp_c->connections[connections_number];
@ -248,7 +248,7 @@ static TCP_Connection_to *get_connection(const TCP_Connections *tcp_c, int conne
static TCP_con *get_tcp_connection(const TCP_Connections *tcp_c, int tcp_connections_number)
{
if (tcp_connections_number_not_valid(tcp_c, tcp_connections_number)) {
return 0;
return nullptr;
}
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
memcpy(tcp_con->relay_pk, tcp_con_public_key(tcp_con->connection), CRYPTO_PUBLIC_KEY_SIZE);
kill_TCP_connection(tcp_con->connection);
tcp_con->connection = NULL;
tcp_con->connection = nullptr;
unsigned int i;
@ -922,7 +922,7 @@ static int tcp_response_callback(void *object, uint8_t connection_id, const uint
TCP_Connection_to *con_to = get_connection(tcp_c, connections_number);
if (con_to == NULL) {
if (con_to == nullptr) {
return -1;
}
@ -1368,14 +1368,14 @@ int set_tcp_onion_status(TCP_Connections *tcp_c, bool status)
*/
TCP_Connections *new_tcp_connections(const uint8_t *secret_key, TCP_Proxy_Info *proxy_info)
{
if (secret_key == NULL) {
return NULL;
if (secret_key == nullptr) {
return nullptr;
}
TCP_Connections *temp = (TCP_Connections *)calloc(1, sizeof(TCP_Connections));
if (temp == NULL) {
return NULL;
if (temp == nullptr) {
return nullptr;
}
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)
tcp_con = get_tcp_connection(tcp_c, i);
// Make sure the TCP connection wasn't dropped in any of the callbacks.
assert(tcp_con != NULL);
assert(tcp_con != nullptr);
if (tcp_con_status(tcp_con->connection) == TCP_CLIENT_DISCONNECTED) {
if (tcp_con->status == TCP_CONN_CONNECTED) {

View File

@ -111,7 +111,7 @@ static int realloc_connection(TCP_Server *TCP_server, uint32_t num)
{
if (num == 0) {
free(TCP_server->accepted_connection_array);
TCP_server->accepted_connection_array = NULL;
TCP_server->accepted_connection_array = nullptr;
TCP_server->size_accepted_connections = 0;
return 0;
}
@ -124,7 +124,7 @@ static int realloc_connection(TCP_Server *TCP_server, uint32_t num)
TCP_server->accepted_connection_array,
num * sizeof(TCP_Secure_Connection));
if (new_connections == NULL) {
if (new_connections == nullptr) {
return -1;
}
@ -403,7 +403,7 @@ static int send_pending_data(TCP_Secure_Connection *con)
con->priority_queue_start = p;
if (!p) {
con->priority_queue_end = NULL;
con->priority_queue_end = nullptr;
return 0;
}
@ -422,7 +422,7 @@ static bool add_priority(TCP_Secure_Connection *con, const uint8_t *packet, uint
return 0;
}
new_list->next = NULL;
new_list->next = nullptr;
new_list->size = size;
new_list->sent = sent;
memcpy(new_list->data, packet, size);
@ -1034,25 +1034,25 @@ static Socket new_listening_TCP_socket(int family, uint16_t port)
TCP_Server *new_TCP_server(uint8_t ipv6_enabled, uint16_t num_sockets, const uint16_t *ports, const uint8_t *secret_key,
Onion *onion)
{
if (num_sockets == 0 || ports == NULL) {
return NULL;
if (num_sockets == 0 || ports == nullptr) {
return nullptr;
}
if (networking_at_startup() != 0) {
return NULL;
return nullptr;
}
TCP_Server *temp = (TCP_Server *)calloc(1, sizeof(TCP_Server));
if (temp == NULL) {
return NULL;
if (temp == nullptr) {
return nullptr;
}
temp->socks_listening = (Socket *)calloc(num_sockets, sizeof(Socket));
if (temp->socks_listening == NULL) {
if (temp->socks_listening == nullptr) {
free(temp);
return NULL;
return nullptr;
}
#ifdef TCP_SERVER_USE_EPOLL
@ -1061,7 +1061,7 @@ TCP_Server *new_TCP_server(uint8_t ipv6_enabled, uint16_t num_sockets, const uin
if (temp->efd == -1) {
free(temp->socks_listening);
free(temp);
return NULL;
return nullptr;
}
#endif
@ -1101,7 +1101,7 @@ TCP_Server *new_TCP_server(uint8_t ipv6_enabled, uint16_t num_sockets, const uin
if (temp->num_listening_socks == 0) {
free(temp->socks_listening);
free(temp);
return NULL;
return nullptr;
}
if (onion) {
@ -1429,7 +1429,7 @@ void kill_TCP_server(TCP_Server *TCP_server)
}
if (TCP_server->onion) {
set_callback_handle_recv_1(TCP_server->onion, NULL, NULL);
set_callback_handle_recv_1(TCP_server->onion, nullptr, nullptr);
}
bs_list_free(&TCP_server->accepted_key_list);

View File

@ -45,4 +45,8 @@
#endif
#ifndef __cplusplus
#define nullptr NULL
#endif
#endif /* CCOMPAT_H */

View File

@ -97,7 +97,7 @@ static uint8_t friendconn_id_not_valid(const Friend_Connections *fr_c, int frien
return 1;
}
if (fr_c->conns == NULL) {
if (fr_c->conns == nullptr) {
return 1;
}
@ -118,13 +118,13 @@ static int realloc_friendconns(Friend_Connections *fr_c, uint32_t num)
{
if (num == 0) {
free(fr_c->conns);
fr_c->conns = NULL;
fr_c->conns = nullptr;
return 0;
}
Friend_Conn *newgroup_cons = (Friend_Conn *)realloc(fr_c->conns, num * sizeof(Friend_Conn));
if (newgroup_cons == NULL) {
if (newgroup_cons == nullptr) {
return -1;
}
@ -189,7 +189,7 @@ static int wipe_friend_conn(Friend_Connections *fr_c, int friendcon_id)
static Friend_Conn *get_conn(const Friend_Connections *fr_c, int friendcon_id)
{
if (friendconn_id_not_valid(fr_c, friendcon_id)) {
return 0;
return nullptr;
}
return &fr_c->conns[friendcon_id];
@ -483,7 +483,7 @@ static int handle_packet(void *object, int number, const uint8_t *data, uint16_t
Node_format nodes[MAX_SHARED_RELAYS];
int n;
if ((n = unpack_nodes(nodes, MAX_SHARED_RELAYS, NULL, data + 1, length - 1, 1)) == -1) {
if ((n = unpack_nodes(nodes, MAX_SHARED_RELAYS, nullptr, data + 1, length - 1, 1)) == -1) {
return -1;
}
@ -873,13 +873,13 @@ int send_friend_request_packet(Friend_Connections *fr_c, int friendcon_id, uint3
Friend_Connections *new_friend_connections(Onion_Client *onion_c, bool local_discovery_enabled)
{
if (!onion_c) {
return NULL;
return nullptr;
}
Friend_Connections *temp = (Friend_Connections *)calloc(1, sizeof(Friend_Connections));
if (temp == NULL) {
return NULL;
if (temp == nullptr) {
return nullptr;
}
temp->dht = onion_get_dht(onion_c);

View File

@ -38,7 +38,7 @@ static uint8_t groupnumber_not_valid(const Group_Chats *g_c, int groupnumber)
return 1;
}
if (g_c->chats == NULL) {
if (g_c->chats == nullptr) {
return 1;
}
@ -59,13 +59,13 @@ static int realloc_groupchats(Group_Chats *g_c, uint32_t num)
{
if (num == 0) {
free(g_c->chats);
g_c->chats = NULL;
g_c->chats = nullptr;
return 0;
}
Group_c *newgroup_chats = (Group_c *)realloc(g_c->chats, num * sizeof(Group_c));
if (newgroup_chats == NULL) {
if (newgroup_chats == nullptr) {
return -1;
}
@ -132,7 +132,7 @@ static int wipe_group_chat(Group_Chats *g_c, int groupnumber)
static Group_c *get_group_c(const Group_Chats *g_c, int groupnumber)
{
if (groupnumber_not_valid(g_c, groupnumber)) {
return 0;
return nullptr;
}
return &g_c->chats[groupnumber];
@ -438,7 +438,7 @@ static int addpeer(Group_Chats *g_c, int groupnumber, const uint8_t *real_pk, co
Group_Peer *temp = (Group_Peer *)realloc(g->group, sizeof(Group_Peer) * (g->numpeers + 1));
if (temp == NULL) {
if (temp == nullptr) {
return -1;
}
@ -527,7 +527,7 @@ static int delpeer(Group_Chats *g_c, int groupnumber, int peer_index, void *user
if (g->numpeers == 0) {
free(g->group);
g->group = NULL;
g->group = nullptr;
} else {
if (g->numpeers != (uint32_t)peer_index) {
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
Group_Peer *temp = (Group_Peer *)realloc(g->group, sizeof(Group_Peer) * (g->numpeers));
if (temp == NULL) {
if (temp == nullptr) {
return -1;
}
@ -744,13 +744,13 @@ int add_groupchat(Group_Chats *g_c, uint8_t type)
g->identifier[0] = type;
g->peer_number = 0; /* Founder is peer 0. */
memcpy(g->real_pk, nc_get_self_public_key(g_c->m->net_crypto), CRYPTO_PUBLIC_KEY_SIZE);
int peer_index = addpeer(g_c, groupnumber, g->real_pk, dht_get_self_public_key(g_c->m->dht), 0, NULL, false);
int peer_index = addpeer(g_c, groupnumber, g->real_pk, dht_get_self_public_key(g_c->m->dht), 0, nullptr, false);
if (peer_index == -1) {
return -1;
}
setnick(g_c, groupnumber, peer_index, g_c->m->name, g_c->m->name_length, NULL, false);
setnick(g_c, groupnumber, peer_index, g_c->m->name, g_c->m->name_length, nullptr, false);
return groupnumber;
}
@ -1223,7 +1223,7 @@ static int send_message_group(const Group_Chats *g_c, int groupnumber, uint8_t m
#define GROUP_MESSAGE_PING_ID 0
static int group_ping_send(const Group_Chats *g_c, int groupnumber)
{
if (send_message_group(g_c, groupnumber, GROUP_MESSAGE_PING_ID, 0, 0) > 0) {
if (send_message_group(g_c, groupnumber, GROUP_MESSAGE_PING_ID, nullptr, 0) > 0) {
return 0;
}
@ -2349,7 +2349,7 @@ void *group_get_object(const Group_Chats *g_c, int groupnumber)
Group_c *g = get_group_c(g_c, groupnumber);
if (!g) {
return NULL;
return nullptr;
}
return g->object;
@ -2365,11 +2365,11 @@ void *group_peer_get_object(const Group_Chats *g_c, int groupnumber, int peernum
Group_c *g = get_group_c(g_c, groupnumber);
if (!g) {
return NULL;
return nullptr;
}
if ((uint32_t)peernumber >= g->numpeers) {
return NULL;
return nullptr;
}
return g->group[peernumber].object;
@ -2410,7 +2410,7 @@ static int groupchat_clear_timedout(Group_Chats *g_c, int groupnumber, void *use
delpeer(g_c, groupnumber, i, userdata);
}
if (g->group == NULL || i >= g->numpeers) {
if (g->group == nullptr || i >= g->numpeers) {
break;
}
}
@ -2441,13 +2441,13 @@ void send_name_all_groups(Group_Chats *g_c)
Group_Chats *new_groupchats(Messenger *m)
{
if (!m) {
return NULL;
return nullptr;
}
Group_Chats *temp = (Group_Chats *)calloc(1, sizeof(Group_Chats));
if (temp == NULL) {
return NULL;
if (temp == nullptr) {
return nullptr;
}
temp->m = m;
@ -2489,8 +2489,8 @@ void kill_groupchats(Group_Chats *g_c)
del_groupchat(g_c, i);
}
m_callback_conference_invite(g_c->m, NULL);
g_c->m->conferences_object = NULL;
m_callback_conference_invite(g_c->m, nullptr);
g_c->m->conferences_object = nullptr;
free(g_c);
}

View File

@ -29,6 +29,8 @@
#include "list.h"
#include "ccompat.h"
/* Basically, the elements in the list are placed in order so that they can be searched for easily
* -each element is seen as a big-endian integer when ordering them
* -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
list->n = 0;
list->element_size = element_size;
list->capacity = 0;
list->data = NULL;
list->ids = NULL;
list->data = nullptr;
list->ids = nullptr;
if (initial_capacity != 0) {
if (!resize(list, initial_capacity)) {
@ -166,10 +168,10 @@ void bs_list_free(BS_LIST *list)
{
//free both arrays
free(list->data);
list->data = NULL;
list->data = nullptr;
free(list->ids);
list->ids = NULL;
list->ids = nullptr;
}
int bs_list_find(const BS_LIST *list, const uint8_t *data)

View File

@ -180,7 +180,7 @@ static uint8_t crypt_connection_id_not_valid(const Net_Crypto *c, int crypt_conn
return 1;
}
if (c->crypto_connections == NULL) {
if (c->crypto_connections == nullptr) {
return 1;
}
@ -551,7 +551,7 @@ static int handle_crypto_handshake(const Net_Crypto *c, uint8_t *nonce, uint8_t
static Crypto_Connection *get_crypto_connection(const Net_Crypto *c, int crypt_connection_id)
{
if (crypt_connection_id_not_valid(c, crypt_connection_id)) {
return 0;
return nullptr;
}
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
{
Crypto_Connection *conn = get_crypto_connection(c, crypt_connection_id);
if (conn == 0) {
if (conn == nullptr) {
return -1;
}
@ -607,7 +607,7 @@ static IP_Port return_ip_port_connection(Net_Crypto *c, int crypt_connection_id)
Crypto_Connection *conn = get_crypto_connection(c, crypt_connection_id);
if (conn == 0) {
if (conn == nullptr) {
return empty;
}
@ -647,7 +647,7 @@ static int send_packet_to(Net_Crypto *c, int crypt_connection_id, const uint8_t
// TODO(irungentoo): TCP, etc...
Crypto_Connection *conn = get_crypto_connection(c, crypt_connection_id);
if (conn == 0) {
if (conn == nullptr) {
return -1;
}
@ -659,7 +659,7 @@ static int send_packet_to(Net_Crypto *c, int crypt_connection_id, const uint8_t
// TODO(irungentoo): on bad networks, direct connections might not last indefinitely.
if (ip_port.ip.family != 0) {
bool direct_connected = 0;
crypto_connection_status(c, crypt_connection_id, &direct_connected, NULL);
crypto_connection_status(c, crypt_connection_id, &direct_connected, nullptr);
if (direct_connected) {
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
Packet_Data *new_d = (Packet_Data *)malloc(sizeof(Packet_Data));
if (new_d == NULL) {
if (new_d == nullptr) {
return -1;
}
@ -784,7 +784,7 @@ static int64_t add_data_end_of_buffer(Packets_Array *array, const Packet_Data *d
Packet_Data *new_d = (Packet_Data *)malloc(sizeof(Packet_Data));
if (new_d == NULL) {
if (new_d == nullptr) {
return -1;
}
@ -816,7 +816,7 @@ static int64_t read_data_beg_buffer(Packets_Array *array, Packet_Data *data)
uint32_t id = array->buffer_start;
++array->buffer_start;
free(array->buffer[num]);
array->buffer[num] = NULL;
array->buffer[num] = nullptr;
return id;
}
@ -840,7 +840,7 @@ static int clear_buffer_until(Packets_Array *array, uint32_t number)
if (array->buffer[num]) {
free(array->buffer[num]);
array->buffer[num] = NULL;
array->buffer[num] = nullptr;
}
}
@ -857,7 +857,7 @@ static int clear_buffer(Packets_Array *array)
if (array->buffer[num]) {
free(array->buffer[num]);
array->buffer[num] = NULL;
array->buffer[num] = nullptr;
}
}
@ -996,7 +996,7 @@ static int handle_request_packet(Packets_Array *send_array, const uint8_t *data,
}
free(send_array->buffer[num]);
send_array->buffer[num] = NULL;
send_array->buffer[num] = nullptr;
}
}
@ -1038,7 +1038,7 @@ static int send_data_packet(Net_Crypto *c, int crypt_connection_id, const uint8_
Crypto_Connection *conn = get_crypto_connection(c, crypt_connection_id);
if (conn == 0) {
if (conn == nullptr) {
return -1;
}
@ -1087,14 +1087,14 @@ static int reset_max_speed_reached(Net_Crypto *c, int crypt_connection_id)
{
Crypto_Connection *conn = get_crypto_connection(c, crypt_connection_id);
if (conn == 0) {
if (conn == nullptr) {
return -1;
}
/* If last packet send failed, try to send packet again.
If sending it fails we won't be able to send the new packet. */
if (conn->maximum_speed_reached) {
Packet_Data *dt = NULL;
Packet_Data *dt = nullptr;
uint32_t packet_num = conn->send_array.buffer_end - 1;
int ret = get_data_pointer(&conn->send_array, &dt, packet_num);
@ -1133,7 +1133,7 @@ static int64_t send_lossless_packet(Net_Crypto *c, int crypt_connection_id, cons
Crypto_Connection *conn = get_crypto_connection(c, crypt_connection_id);
if (conn == 0) {
if (conn == nullptr) {
return -1;
}
@ -1162,7 +1162,7 @@ static int64_t send_lossless_packet(Net_Crypto *c, int crypt_connection_id, cons
}
if (send_data_packet_helper(c, crypt_connection_id, conn->recv_array.buffer_start, packet_num, data, length) == 0) {
Packet_Data *dt1 = NULL;
Packet_Data *dt1 = nullptr;
if (get_data_pointer(&conn->send_array, &dt1, packet_num) == 1) {
dt1->sent_time = current_time_monotonic();
@ -1203,7 +1203,7 @@ static int handle_data_packet(const Net_Crypto *c, int crypt_connection_id, uint
Crypto_Connection *conn = get_crypto_connection(c, crypt_connection_id);
if (conn == 0) {
if (conn == nullptr) {
return -1;
}
@ -1238,7 +1238,7 @@ static int send_request_packet(Net_Crypto *c, int crypt_connection_id)
{
Crypto_Connection *conn = get_crypto_connection(c, crypt_connection_id);
if (conn == 0) {
if (conn == nullptr) {
return -1;
}
@ -1266,7 +1266,7 @@ static int send_requested_packets(Net_Crypto *c, int crypt_connection_id, uint32
Crypto_Connection *conn = get_crypto_connection(c, crypt_connection_id);
if (conn == 0) {
if (conn == nullptr) {
return -1;
}
@ -1318,13 +1318,13 @@ static int new_temp_packet(const Net_Crypto *c, int crypt_connection_id, const u
Crypto_Connection *conn = get_crypto_connection(c, crypt_connection_id);
if (conn == 0) {
if (conn == nullptr) {
return -1;
}
uint8_t *temp_packet = (uint8_t *)malloc(length);
if (temp_packet == 0) {
if (temp_packet == nullptr) {
return -1;
}
@ -1349,7 +1349,7 @@ static int clear_temp_packet(const Net_Crypto *c, int crypt_connection_id)
{
Crypto_Connection *conn = get_crypto_connection(c, crypt_connection_id);
if (conn == 0) {
if (conn == nullptr) {
return -1;
}
@ -1357,7 +1357,7 @@ static int clear_temp_packet(const Net_Crypto *c, int crypt_connection_id)
free(conn->temp_packet);
}
conn->temp_packet = 0;
conn->temp_packet = nullptr;
conn->temp_packet_length = 0;
conn->temp_packet_sent_time = 0;
conn->temp_packet_num_sent = 0;
@ -1374,7 +1374,7 @@ static int send_temp_packet(Net_Crypto *c, int crypt_connection_id)
{
Crypto_Connection *conn = get_crypto_connection(c, crypt_connection_id);
if (conn == 0) {
if (conn == nullptr) {
return -1;
}
@ -1402,7 +1402,7 @@ static int create_send_handshake(Net_Crypto *c, int crypt_connection_id, const u
{
Crypto_Connection *conn = get_crypto_connection(c, crypt_connection_id);
if (conn == 0) {
if (conn == nullptr) {
return -1;
}
@ -1430,7 +1430,7 @@ static int send_kill_packet(Net_Crypto *c, int crypt_connection_id)
{
Crypto_Connection *conn = get_crypto_connection(c, crypt_connection_id);
if (conn == 0) {
if (conn == nullptr) {
return -1;
}
@ -1443,7 +1443,7 @@ static void connection_kill(Net_Crypto *c, int crypt_connection_id, void *userda
{
Crypto_Connection *conn = get_crypto_connection(c, crypt_connection_id);
if (conn == 0) {
if (conn == nullptr) {
return;
}
@ -1469,7 +1469,7 @@ static int handle_data_packet_core(Net_Crypto *c, int crypt_connection_id, const
Crypto_Connection *conn = get_crypto_connection(c, crypt_connection_id);
if (conn == 0) {
if (conn == nullptr) {
return -1;
}
@ -1571,7 +1571,7 @@ static int handle_data_packet_core(Net_Crypto *c, int crypt_connection_id, const
/* conn might get killed in callback. */
conn = get_crypto_connection(c, crypt_connection_id);
if (conn == 0) {
if (conn == nullptr) {
return -1;
}
}
@ -1616,7 +1616,7 @@ static int handle_packet_connection(Net_Crypto *c, int crypt_connection_id, cons
Crypto_Connection *conn = get_crypto_connection(c, crypt_connection_id);
if (conn == 0) {
if (conn == nullptr) {
return -1;
}
@ -1702,14 +1702,14 @@ static int realloc_cryptoconnection(Net_Crypto *c, uint32_t num)
{
if (num == 0) {
free(c->crypto_connections);
c->crypto_connections = NULL;
c->crypto_connections = nullptr;
return 0;
}
Crypto_Connection *newcrypto_connections = (Crypto_Connection *)realloc(c->crypto_connections,
num * sizeof(Crypto_Connection));
if (newcrypto_connections == NULL) {
if (newcrypto_connections == nullptr) {
return -1;
}
@ -1756,7 +1756,7 @@ static int create_crypto_connection(Net_Crypto *c)
c->crypto_connections[id].packet_send_rate_requested = 0;
c->crypto_connections[id].last_packets_left_requested_rem = 0;
if (pthread_mutex_init(&c->crypto_connections[id].mutex, NULL) != 0) {
if (pthread_mutex_init(&c->crypto_connections[id].mutex, nullptr) != 0) {
pthread_mutex_unlock(&c->connections_mutex);
return -1;
}
@ -1831,7 +1831,7 @@ static int crypto_connection_add_source(Net_Crypto *c, int crypt_connection_id,
{
Crypto_Connection *conn = get_crypto_connection(c, crypt_connection_id);
if (conn == 0) {
if (conn == nullptr) {
return -1;
}
@ -1884,7 +1884,7 @@ static int handle_new_connection_handshake(Net_Crypto *c, IP_Port source, const
New_Connection n_c;
n_c.cookie = (uint8_t *)malloc(COOKIE_LENGTH);
if (n_c.cookie == NULL) {
if (n_c.cookie == nullptr) {
return -1;
}
@ -1892,7 +1892,7 @@ static int handle_new_connection_handshake(Net_Crypto *c, IP_Port source, const
n_c.cookie_length = COOKIE_LENGTH;
if (handle_crypto_handshake(c, n_c.recv_nonce, n_c.peersessionpublic_key, n_c.public_key, n_c.dht_public_key,
n_c.cookie, data, length, 0) != 0) {
n_c.cookie, data, length, nullptr) != 0) {
free(n_c.cookie);
return -1;
}
@ -2009,7 +2009,7 @@ int new_crypto_connection(Net_Crypto *c, const uint8_t *real_public_key, const u
Crypto_Connection *conn = &c->crypto_connections[crypt_connection_id];
if (conn == 0) {
if (conn == nullptr) {
return -1;
}
@ -2059,7 +2059,7 @@ int set_direct_ip_port(Net_Crypto *c, int crypt_connection_id, IP_Port ip_port,
{
Crypto_Connection *conn = get_crypto_connection(c, crypt_connection_id);
if (conn == 0) {
if (conn == nullptr) {
return -1;
}
@ -2095,7 +2095,7 @@ static int tcp_data_callback(void *object, int id, const uint8_t *data, uint16_t
Crypto_Connection *conn = get_crypto_connection(c, id);
if (conn == 0) {
if (conn == nullptr) {
return -1;
}
@ -2155,7 +2155,7 @@ int add_tcp_relay_peer(Net_Crypto *c, int crypt_connection_id, IP_Port ip_port,
{
Crypto_Connection *conn = get_crypto_connection(c, crypt_connection_id);
if (conn == 0) {
if (conn == nullptr) {
return -1;
}
@ -2239,13 +2239,13 @@ static void do_tcp(Net_Crypto *c, void *userdata)
for (i = 0; i < c->crypto_connections_length; ++i) {
Crypto_Connection *conn = get_crypto_connection(c, i);
if (conn == 0) {
if (conn == nullptr) {
return;
}
if (conn->status == CRYPTO_CONN_ESTABLISHED) {
bool direct_connected = 0;
crypto_connection_status(c, i, &direct_connected, NULL);
crypto_connection_status(c, i, &direct_connected, nullptr);
if (direct_connected) {
pthread_mutex_lock(&c->tcp_mutex);
@ -2275,7 +2275,7 @@ int connection_status_handler(const Net_Crypto *c, int crypt_connection_id,
{
Crypto_Connection *conn = get_crypto_connection(c, crypt_connection_id);
if (conn == 0) {
if (conn == nullptr) {
return -1;
}
@ -2298,7 +2298,7 @@ int connection_data_handler(const Net_Crypto *c, int crypt_connection_id, int (*
{
Crypto_Connection *conn = get_crypto_connection(c, crypt_connection_id);
if (conn == 0) {
if (conn == nullptr) {
return -1;
}
@ -2322,7 +2322,7 @@ int connection_lossy_data_handler(Net_Crypto *c, int crypt_connection_id,
{
Crypto_Connection *conn = get_crypto_connection(c, crypt_connection_id);
if (conn == 0) {
if (conn == nullptr) {
return -1;
}
@ -2348,7 +2348,7 @@ int nc_dht_pk_callback(Net_Crypto *c, int crypt_connection_id, void (*function)(
{
Crypto_Connection *conn = get_crypto_connection(c, crypt_connection_id);
if (conn == 0) {
if (conn == nullptr) {
return -1;
}
@ -2405,7 +2405,7 @@ static int udp_handle_packet(void *object, IP_Port source, const uint8_t *packet
Crypto_Connection *conn = get_crypto_connection(c, crypt_connection_id);
if (conn == 0) {
if (conn == nullptr) {
return -1;
}
@ -2449,7 +2449,7 @@ static void send_crypto_packets(Net_Crypto *c)
for (i = 0; i < c->crypto_connections_length; ++i) {
Crypto_Connection *conn = get_crypto_connection(c, i);
if (conn == 0) {
if (conn == nullptr) {
return;
}
@ -2527,7 +2527,7 @@ static void send_crypto_packets(Net_Crypto *c)
conn->last_num_packets_resent[n_p_pos] = packets_resent;
bool direct_connected = 0;
crypto_connection_status(c, i, &direct_connected, NULL);
crypto_connection_status(c, i, &direct_connected, nullptr);
if (direct_connected && conn->last_tcp_sent + CONGESTION_EVENT_TIMEOUT > temp_time) {
/* 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
{
Crypto_Connection *conn = get_crypto_connection(c, crypt_connection_id);
if (conn == 0) {
if (conn == nullptr) {
return 0;
}
@ -2725,7 +2725,7 @@ int64_t write_cryptpacket(Net_Crypto *c, int crypt_connection_id, const uint8_t
Crypto_Connection *conn = get_crypto_connection(c, crypt_connection_id);
if (conn == 0) {
if (conn == nullptr) {
return -1;
}
@ -2763,7 +2763,7 @@ int cryptpacket_received(Net_Crypto *c, int crypt_connection_id, uint32_t packet
{
Crypto_Connection *conn = get_crypto_connection(c, crypt_connection_id);
if (conn == 0) {
if (conn == nullptr) {
return -1;
}
@ -2872,7 +2872,7 @@ unsigned int crypto_connection_status(const Net_Crypto *c, int crypt_connection_
{
Crypto_Connection *conn = get_crypto_connection(c, crypt_connection_id);
if (conn == 0) {
if (conn == nullptr) {
return CRYPTO_CONN_NO_CONNECTION;
}
@ -2929,33 +2929,33 @@ Net_Crypto *new_net_crypto(Logger *log, DHT *dht, TCP_Proxy_Info *proxy_info)
{
unix_time_update();
if (dht == NULL) {
return NULL;
if (dht == nullptr) {
return nullptr;
}
Net_Crypto *temp = (Net_Crypto *)calloc(1, sizeof(Net_Crypto));
if (temp == NULL) {
return NULL;
if (temp == nullptr) {
return nullptr;
}
temp->log = log;
temp->tcp_c = new_tcp_connections(dht_get_self_secret_key(dht), proxy_info);
if (temp->tcp_c == NULL) {
if (temp->tcp_c == nullptr) {
free(temp);
return NULL;
return nullptr;
}
set_packet_tcp_connection_callback(temp->tcp_c, &tcp_data_callback, temp);
set_oob_packet_tcp_connection_callback(temp->tcp_c, &tcp_oob_callback, temp);
if (create_recursive_mutex(&temp->tcp_mutex) != 0 ||
pthread_mutex_init(&temp->connections_mutex, NULL) != 0) {
pthread_mutex_init(&temp->connections_mutex, nullptr) != 0) {
kill_tcp_connections(temp->tcp_c);
free(temp);
return NULL;
return nullptr;
}
temp->dht = dht;
@ -2983,7 +2983,7 @@ static void kill_timedout(Net_Crypto *c, void *userdata)
for (i = 0; i < c->crypto_connections_length; ++i) {
Crypto_Connection *conn = get_crypto_connection(c, i);
if (conn == 0) {
if (conn == nullptr) {
return;
}
@ -3039,10 +3039,10 @@ void kill_net_crypto(Net_Crypto *c)
kill_tcp_connections(c->tcp_c);
bs_list_free(&c->ip_port_list);
networking_registerhandler(dht_get_net(c->dht), NET_PACKET_COOKIE_REQUEST, NULL, NULL);
networking_registerhandler(dht_get_net(c->dht), NET_PACKET_COOKIE_RESPONSE, NULL, NULL);
networking_registerhandler(dht_get_net(c->dht), NET_PACKET_CRYPTO_HS, NULL, NULL);
networking_registerhandler(dht_get_net(c->dht), NET_PACKET_CRYPTO_DATA, NULL, NULL);
networking_registerhandler(dht_get_net(c->dht), NET_PACKET_COOKIE_REQUEST, nullptr, nullptr);
networking_registerhandler(dht_get_net(c->dht), NET_PACKET_COOKIE_RESPONSE, nullptr, nullptr);
networking_registerhandler(dht_get_net(c->dht), NET_PACKET_CRYPTO_HS, nullptr, nullptr);
networking_registerhandler(dht_get_net(c->dht), NET_PACKET_CRYPTO_DATA, nullptr, nullptr);
crypto_memzero(c, sizeof(Net_Crypto));
free(c);
}

View File

@ -82,8 +82,8 @@ static const char *inet_ntop(Family family, const void *addr, char *buf, size_t
DWORD len = bufsize;
if (WSAAddressToString((LPSOCKADDR)&saddr, sizeof(saddr), NULL, buf, &len)) {
return NULL;
if (WSAAddressToString((LPSOCKADDR)&saddr, sizeof(saddr), nullptr, buf, &len)) {
return nullptr;
}
return buf;
@ -96,14 +96,14 @@ static const char *inet_ntop(Family family, const void *addr, char *buf, size_t
DWORD len = bufsize;
if (WSAAddressToString((LPSOCKADDR)&saddr, sizeof(saddr), NULL, buf, &len)) {
return NULL;
if (WSAAddressToString((LPSOCKADDR)&saddr, sizeof(saddr), nullptr, buf, &len)) {
return nullptr;
}
return buf;
}
return NULL;
return nullptr;
}
static 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)
INT len = sizeof(saddr);
if (WSAStringToAddress((LPTSTR)addrString, AF_INET, NULL, (LPSOCKADDR)&saddr, &len)) {
if (WSAStringToAddress((LPTSTR)addrString, AF_INET, nullptr, (LPSOCKADDR)&saddr, &len)) {
return 0;
}
@ -127,7 +127,7 @@ static int inet_pton(Family family, const char *addrString, void *addrbuf)
INT len = sizeof(saddr);
if (WSAStringToAddress((LPTSTR)addrString, AF_INET6, NULL, (LPSOCKADDR)&saddr, &len)) {
if (WSAStringToAddress((LPTSTR)addrString, AF_INET6, nullptr, (LPSOCKADDR)&saddr, &len)) {
return 0;
}
@ -306,7 +306,7 @@ static uint64_t current_time_actual(void)
return time / 10;
#else
struct timeval a;
gettimeofday(&a, NULL);
gettimeofday(&a, nullptr);
time = 1000000ULL * a.tv_sec + a.tv_usec;
return time;
#endif
@ -624,7 +624,7 @@ static void at_shutdown(void)
*/
Networking_Core *new_networking(Logger *log, IP ip, uint16_t port)
{
return new_networking_ex(log, ip, port, port + (TOX_PORTRANGE_TO - TOX_PORTRANGE_FROM), 0);
return new_networking_ex(log, ip, port, port + (TOX_PORTRANGE_TO - TOX_PORTRANGE_FROM), nullptr);
}
/* Initialize networking.
@ -663,17 +663,17 @@ Networking_Core *new_networking_ex(Logger *log, IP ip, uint16_t port_from, uint1
/* maybe check for invalid IPs like 224+.x.y.z? if there is any IP set ever */
if (ip.family != TOX_AF_INET && ip.family != TOX_AF_INET6) {
LOGGER_ERROR(log, "Invalid address family: %u\n", ip.family);
return NULL;
return nullptr;
}
if (networking_at_startup() != 0) {
return NULL;
return nullptr;
}
Networking_Core *temp = (Networking_Core *)calloc(1, sizeof(Networking_Core));
if (temp == NULL) {
return NULL;
if (temp == nullptr) {
return nullptr;
}
temp->log = log;
@ -693,7 +693,7 @@ Networking_Core *new_networking_ex(Logger *log, IP ip, uint16_t port_from, uint1
*error = 1;
}
return NULL;
return nullptr;
}
/* 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
*error = 1;
}
return NULL;
return nullptr;
}
/* Set socket nonblocking. */
@ -725,11 +725,11 @@ Networking_Core *new_networking_ex(Logger *log, IP ip, uint16_t port_from, uint1
*error = 1;
}
return NULL;
return nullptr;
}
/* Bind our socket to port PORT and the given IP address (usually 0.0.0.0 or ::) */
uint16_t *portptr = NULL;
uint16_t *portptr = nullptr;
struct sockaddr_storage addr;
size_t addrsize;
@ -758,7 +758,7 @@ Networking_Core *new_networking_ex(Logger *log, IP ip, uint16_t port_from, uint1
portptr = &addr6->sin6_port;
} else {
free(temp);
return NULL;
return nullptr;
}
if (ip.family == TOX_AF_INET6) {
@ -841,7 +841,7 @@ Networking_Core *new_networking_ex(Logger *log, IP ip, uint16_t port_from, uint1
*error = 1;
}
return NULL;
return nullptr;
}
Networking_Core *new_networking_no_udp(Logger *log)
@ -849,8 +849,8 @@ Networking_Core *new_networking_no_udp(Logger *log)
/* this is the easiest way to completely disable UDP without changing too much code. */
Networking_Core *net = (Networking_Core *)calloc(1, sizeof(Networking_Core));
if (net == NULL) {
return NULL;
if (net == nullptr) {
return nullptr;
}
net->log = log;
@ -1076,12 +1076,12 @@ int ip_parse_addr(const IP *ip, char *address, size_t length)
if (ip->family == TOX_AF_INET) {
const struct in_addr *addr = (const struct in_addr *)&ip->ip4;
return inet_ntop(ip->family, addr, address, length) != NULL;
return inet_ntop(ip->family, addr, address, length) != nullptr;
}
if (ip->family == TOX_AF_INET6) {
const struct in6_addr *addr = (const struct in6_addr *)&ip->ip6;
return inet_ntop(ip->family, addr, address, length) != NULL;
return inet_ntop(ip->family, addr, address, length) != nullptr;
}
return 0;
@ -1151,8 +1151,8 @@ int addr_resolve(const char *address, IP *to, IP *extra)
Family tox_family = to->family;
Family family = make_family(tox_family);
struct addrinfo *server = NULL;
struct addrinfo *walker = NULL;
struct addrinfo *server = nullptr;
struct addrinfo *walker = nullptr;
struct addrinfo hints;
int rc;
int result = 0;
@ -1166,7 +1166,7 @@ int addr_resolve(const char *address, IP *to, IP *extra)
return 0;
}
rc = getaddrinfo(address, NULL, &hints, &server);
rc = getaddrinfo(address, nullptr, &hints, &server);
// Lookup failed.
if (rc != 0) {
@ -1178,7 +1178,7 @@ int addr_resolve(const char *address, IP *to, IP *extra)
IP ip6;
ip_init(&ip6, 1); // ipv6enabled = 1
for (walker = server; (walker != NULL) && !done; walker = walker->ai_next) {
for (walker = server; (walker != nullptr) && !done; walker = walker->ai_next) {
switch (walker->ai_family) {
case AF_INET:
if (walker->ai_family == family) { /* AF_INET requested, done */
@ -1218,7 +1218,7 @@ int addr_resolve(const char *address, IP *to, IP *extra)
if (result & TOX_ADDR_RESOLVE_INET6) {
ip_copy(to, &ip6);
if ((result & TOX_ADDR_RESOLVE_INET) && (extra != NULL)) {
if ((result & TOX_ADDR_RESOLVE_INET) && (extra != nullptr)) {
ip_copy(extra, &ip4);
}
} else if (result & TOX_ADDR_RESOLVE_INET) {
@ -1287,8 +1287,8 @@ int net_connect(Socket sock, IP_Port ip_port)
int32_t net_getipport(const char *node, IP_Port **res, int tox_type)
{
struct addrinfo *infos;
int ret = getaddrinfo(node, NULL, NULL, &infos);
*res = NULL;
int ret = getaddrinfo(node, nullptr, nullptr, &infos);
*res = nullptr;
if (ret != 0) {
return -1;
@ -1300,7 +1300,7 @@ int32_t net_getipport(const char *node, IP_Port **res, int tox_type)
struct addrinfo *cur;
int32_t count = 0;
for (cur = infos; count < MAX_COUNT && cur != NULL; cur = cur->ai_next) {
for (cur = infos; count < MAX_COUNT && cur != nullptr; cur = cur->ai_next) {
if (cur->ai_socktype && type > 0 && cur->ai_socktype != type) {
continue;
}
@ -1321,14 +1321,14 @@ int32_t net_getipport(const char *node, IP_Port **res, int tox_type)
*res = (IP_Port *)malloc(sizeof(IP_Port) * count);
if (*res == NULL) {
if (*res == nullptr) {
freeaddrinfo(infos);
return -1;
}
IP_Port *ip_port = *res;
for (cur = infos; cur != NULL; cur = cur->ai_next) {
for (cur = infos; cur != nullptr; cur = cur->ai_next) {
if (cur->ai_socktype && type > 0 && cur->ai_socktype != type) {
continue;
}

View File

@ -125,17 +125,16 @@ typedef enum NET_PACKET_TYPE {
#define TCP_INET6 (TOX_AF_INET6 + 3)
#define TCP_FAMILY (TOX_AF_INET6 + 4)
typedef union {
typedef union IP4 {
uint32_t uint32;
uint16_t uint16[2];
uint8_t uint8[4];
}
IP4;
} IP4;
IP4 get_ip4_loopback(void);
extern const IP4 IP4_BROADCAST;
typedef union {
typedef union IP6 {
uint8_t uint8[16];
uint16_t uint16[8];
uint32_t uint32[4];
@ -146,7 +145,7 @@ IP6 get_ip6_loopback(void);
extern const IP6 IP6_BROADCAST;
#define IP_DEFINED
typedef struct {
typedef struct IP {
uint8_t family;
GNU_EXTENSION union {
IP4 ip4;

View File

@ -635,14 +635,14 @@ void set_callback_handle_recv_1(Onion *onion, int (*function)(void *, IP_Port, c
Onion *new_onion(DHT *dht)
{
if (dht == NULL) {
return NULL;
if (dht == nullptr) {
return nullptr;
}
Onion *onion = (Onion *)calloc(1, sizeof(Onion));
if (onion == NULL) {
return NULL;
if (onion == nullptr) {
return nullptr;
}
onion->dht = dht;
@ -663,17 +663,17 @@ Onion *new_onion(DHT *dht)
void kill_onion(Onion *onion)
{
if (onion == NULL) {
if (onion == nullptr) {
return;
}
networking_registerhandler(onion->net, NET_PACKET_ONION_SEND_INITIAL, NULL, NULL);
networking_registerhandler(onion->net, NET_PACKET_ONION_SEND_1, NULL, NULL);
networking_registerhandler(onion->net, NET_PACKET_ONION_SEND_2, NULL, NULL);
networking_registerhandler(onion->net, NET_PACKET_ONION_SEND_INITIAL, nullptr, nullptr);
networking_registerhandler(onion->net, NET_PACKET_ONION_SEND_1, nullptr, nullptr);
networking_registerhandler(onion->net, NET_PACKET_ONION_SEND_2, nullptr, nullptr);
networking_registerhandler(onion->net, NET_PACKET_ONION_RECV_3, NULL, NULL);
networking_registerhandler(onion->net, NET_PACKET_ONION_RECV_2, NULL, NULL);
networking_registerhandler(onion->net, NET_PACKET_ONION_RECV_1, NULL, NULL);
networking_registerhandler(onion->net, NET_PACKET_ONION_RECV_3, nullptr, nullptr);
networking_registerhandler(onion->net, NET_PACKET_ONION_RECV_2, nullptr, nullptr);
networking_registerhandler(onion->net, NET_PACKET_ONION_RECV_1, nullptr, nullptr);
free(onion);
}

View File

@ -493,14 +493,14 @@ static int handle_data_request(void *object, IP_Port source, const uint8_t *pack
Onion_Announce *new_onion_announce(DHT *dht)
{
if (dht == NULL) {
return NULL;
if (dht == nullptr) {
return nullptr;
}
Onion_Announce *onion_a = (Onion_Announce *)calloc(1, sizeof(Onion_Announce));
if (onion_a == NULL) {
return NULL;
if (onion_a == nullptr) {
return nullptr;
}
onion_a->dht = dht;
@ -515,11 +515,11 @@ Onion_Announce *new_onion_announce(DHT *dht)
void kill_onion_announce(Onion_Announce *onion_a)
{
if (onion_a == NULL) {
if (onion_a == nullptr) {
return;
}
networking_registerhandler(onion_a->net, NET_PACKET_ANNOUNCE_REQUEST, NULL, NULL);
networking_registerhandler(onion_a->net, NET_PACKET_ONION_DATA_REQUEST, NULL, NULL);
networking_registerhandler(onion_a->net, NET_PACKET_ANNOUNCE_REQUEST, nullptr, nullptr);
networking_registerhandler(onion_a->net, NET_PACKET_ONION_DATA_REQUEST, nullptr, nullptr);
free(onion_a);
}

View File

@ -579,7 +579,7 @@ static int client_send_announce_request(Onion_Client *onion_c, uint32_t num, IP_
uint8_t zero_ping_id[ONION_PING_ID_SIZE] = {0};
if (ping_id == NULL) {
if (ping_id == nullptr) {
ping_id = zero_ping_id;
}
@ -670,8 +670,8 @@ static int client_add_to_list(Onion_Client *onion_c, uint32_t num, const uint8_t
return -1;
}
Onion_Node *list_nodes = NULL;
const uint8_t *reference_id = NULL;
Onion_Node *list_nodes = nullptr;
const uint8_t *reference_id = nullptr;
unsigned int list_length;
if (num == 0) {
@ -772,12 +772,12 @@ static int client_ping_nodes(Onion_Client *onion_c, uint32_t num, const Node_for
return 0;
}
Onion_Node *list_nodes = NULL;
const uint8_t *reference_id = NULL;
Onion_Node *list_nodes = nullptr;
const uint8_t *reference_id = nullptr;
unsigned int list_length;
Last_Pinged *last_pinged = NULL;
uint8_t *last_pinged_index = NULL;
Last_Pinged *last_pinged = nullptr;
uint8_t *last_pinged_index = nullptr;
if (num == 0) {
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
}
if (j == list_length && good_to_ping(last_pinged, last_pinged_index, nodes[i].public_key)) {
client_send_announce_request(onion_c, num, nodes[i].ip_port, nodes[i].public_key, NULL, ~0);
client_send_announce_request(onion_c, num, nodes[i].ip_port, nodes[i].public_key, nullptr, ~0);
}
}
}
@ -875,7 +875,7 @@ static int handle_announce_response(void *object, IP_Port source, const uint8_t
if (len_nodes != 0) {
Node_format nodes[MAX_SENT_NODES];
int num_nodes = unpack_nodes(nodes, MAX_SENT_NODES, 0, plain + 1 + ONION_PING_ID_SIZE, len_nodes, 0);
int num_nodes = unpack_nodes(nodes, MAX_SENT_NODES, nullptr, plain + 1 + ONION_PING_ID_SIZE, len_nodes, 0);
if (num_nodes <= 0) {
return 1;
@ -974,7 +974,7 @@ static int handle_dhtpk_announce(void *object, const uint8_t *source_pubkey, con
if (len_nodes != 0) {
Node_format nodes[MAX_SENT_NODES];
int num_nodes = unpack_nodes(nodes, MAX_SENT_NODES, 0, data + 1 + sizeof(uint64_t) + CRYPTO_PUBLIC_KEY_SIZE,
int num_nodes = unpack_nodes(nodes, MAX_SENT_NODES, nullptr, data + 1 + sizeof(uint64_t) + CRYPTO_PUBLIC_KEY_SIZE,
len_nodes, 1);
if (num_nodes <= 0) {
@ -1260,13 +1260,13 @@ static int realloc_onion_friends(Onion_Client *onion_c, uint32_t num)
{
if (num == 0) {
free(onion_c->friends_list);
onion_c->friends_list = NULL;
onion_c->friends_list = nullptr;
return 0;
}
Onion_Friend *newonion_friends = (Onion_Friend *)realloc(onion_c->friends_list, num * sizeof(Onion_Friend));
if (newonion_friends == NULL) {
if (newonion_friends == nullptr) {
return -1;
}
@ -1586,7 +1586,8 @@ static void do_friend(Onion_Client *onion_c, uint16_t friendnum)
if (is_timeout(list_nodes[i].last_pinged, interval)
|| (ping_random && rand() % (MAX_ONION_CLIENTS - i) == 0)) {
if (client_send_announce_request(onion_c, friendnum + 1, list_nodes[i].ip_port, list_nodes[i].public_key, 0, ~0) == 0) {
if (client_send_announce_request(onion_c, friendnum + 1, list_nodes[i].ip_port,
list_nodes[i].public_key, nullptr, ~0) == 0) {
list_nodes[i].last_pinged = unix_time();
++list_nodes[i].unsuccessful_pings;
ping_random = false;
@ -1610,7 +1611,7 @@ static void do_friend(Onion_Client *onion_c, uint16_t friendnum)
for (j = 0; j < n; ++j) {
unsigned int num = rand() % num_nodes;
client_send_announce_request(onion_c, friendnum + 1, onion_c->path_nodes[num].ip_port,
onion_c->path_nodes[num].public_key, 0, ~0);
onion_c->path_nodes[num].public_key, nullptr, ~0);
}
++onion_c->friends_list[friendnum].run_count;
@ -1729,7 +1730,7 @@ static void do_announce(Onion_Client *onion_c)
if (num_nodes != 0) {
for (i = 0; i < (MAX_ONION_CLIENTS_ANNOUNCE / 2); ++i) {
unsigned int num = rand() % num_nodes;
client_send_announce_request(onion_c, 0, path_nodes[num].ip_port, path_nodes[num].public_key, 0, ~0);
client_send_announce_request(onion_c, 0, path_nodes[num].ip_port, path_nodes[num].public_key, nullptr, ~0);
}
}
}
@ -1846,21 +1847,21 @@ void do_onion_client(Onion_Client *onion_c)
Onion_Client *new_onion_client(Net_Crypto *c)
{
if (c == NULL) {
return NULL;
if (c == nullptr) {
return nullptr;
}
Onion_Client *onion_c = (Onion_Client *)calloc(1, sizeof(Onion_Client));
if (onion_c == NULL) {
return NULL;
if (onion_c == nullptr) {
return nullptr;
}
onion_c->announce_ping_array = ping_array_new(ANNOUNCE_ARRAY_SIZE, ANNOUNCE_TIMEOUT);
if (onion_c->announce_ping_array == NULL) {
if (onion_c->announce_ping_array == nullptr) {
free(onion_c);
return NULL;
return nullptr;
}
onion_c->dht = nc_get_dht(c);
@ -1879,17 +1880,17 @@ Onion_Client *new_onion_client(Net_Crypto *c)
void kill_onion_client(Onion_Client *onion_c)
{
if (onion_c == NULL) {
if (onion_c == nullptr) {
return;
}
ping_array_kill(onion_c->announce_ping_array);
realloc_onion_friends(onion_c, 0);
networking_registerhandler(onion_c->net, NET_PACKET_ANNOUNCE_RESPONSE, NULL, NULL);
networking_registerhandler(onion_c->net, NET_PACKET_ONION_DATA_RESPONSE, NULL, NULL);
oniondata_registerhandler(onion_c, ONION_DATA_DHTPK, NULL, NULL);
cryptopacket_registerhandler(onion_c->dht, CRYPTO_PACKET_DHTPK, NULL, NULL);
set_onion_packet_tcp_connection_callback(nc_get_tcp_c(onion_c->c), NULL, NULL);
networking_registerhandler(onion_c->net, NET_PACKET_ANNOUNCE_RESPONSE, nullptr, nullptr);
networking_registerhandler(onion_c->net, NET_PACKET_ONION_DATA_RESPONSE, nullptr, nullptr);
oniondata_registerhandler(onion_c, ONION_DATA_DHTPK, nullptr, nullptr);
cryptopacket_registerhandler(onion_c->dht, CRYPTO_PACKET_DHTPK, nullptr, nullptr);
set_onion_packet_tcp_connection_callback(nc_get_tcp_c(onion_c->c), nullptr, nullptr);
crypto_memzero(onion_c, sizeof(Onion_Client));
free(onion_c);
}

View File

@ -355,15 +355,15 @@ Ping *ping_new(DHT *dht)
{
Ping *ping = (Ping *)calloc(1, sizeof(Ping));
if (ping == NULL) {
return NULL;
if (ping == nullptr) {
return nullptr;
}
ping->ping_array = ping_array_new(PING_NUM_MAX, PING_TIMEOUT);
if (ping->ping_array == NULL) {
if (ping->ping_array == nullptr) {
free(ping);
return NULL;
return nullptr;
}
ping->dht = dht;
@ -375,8 +375,8 @@ Ping *ping_new(DHT *dht)
void ping_kill(Ping *ping)
{
networking_registerhandler(dht_get_net(ping->dht), NET_PACKET_PING_REQUEST, NULL, NULL);
networking_registerhandler(dht_get_net(ping->dht), NET_PACKET_PING_RESPONSE, NULL, NULL);
networking_registerhandler(dht_get_net(ping->dht), NET_PACKET_PING_REQUEST, nullptr, nullptr);
networking_registerhandler(dht_get_net(ping->dht), NET_PACKET_PING_RESPONSE, nullptr, nullptr);
ping_array_kill(ping->ping_array);
free(ping);

View File

@ -57,20 +57,20 @@ struct Ping_Array {
Ping_Array *ping_array_new(uint32_t size, uint32_t timeout)
{
if (size == 0 || timeout == 0) {
return NULL;
return nullptr;
}
Ping_Array *empty_array = (Ping_Array *)calloc(1, sizeof(Ping_Array));
if (empty_array == NULL) {
return NULL;
if (empty_array == nullptr) {
return nullptr;
}
empty_array->entries = (Ping_Array_Entry *)calloc(size, sizeof(Ping_Array_Entry));
if (empty_array->entries == NULL) {
if (empty_array->entries == nullptr) {
free(empty_array);
return NULL;
return nullptr;
}
empty_array->last_deleted = empty_array->last_added = 0;
@ -82,7 +82,7 @@ Ping_Array *ping_array_new(uint32_t size, uint32_t timeout)
static void clear_entry(Ping_Array *array, uint32_t index)
{
free(array->entries[index].data);
array->entries[index].data = NULL;
array->entries[index].data = nullptr;
array->entries[index].length =
array->entries[index].time =
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)
ping_array_clear_timedout(array);
uint32_t index = array->last_added % array->total_size;
if (array->entries[index].data != NULL) {
if (array->entries[index].data != nullptr) {
array->last_deleted = array->last_added - array->total_size;
clear_entry(array, index);
}
array->entries[index].data = malloc(length);
if (array->entries[index].data == NULL) {
if (array->entries[index].data == nullptr) {
return 0;
}
@ -184,7 +184,7 @@ int32_t ping_array_check(Ping_Array *array, uint8_t *data, size_t length, uint64
return -1;
}
if (array->entries[index].data == NULL) {
if (array->entries[index].data == nullptr) {
return -1;
}

View File

@ -84,32 +84,32 @@ Tox *tox_new(const struct Tox_Options *options, TOX_ERR_NEW *error)
bool load_savedata_sk = 0, load_savedata_tox = 0;
if (options == NULL) {
if (options == nullptr) {
m_options.ipv6enabled = TOX_ENABLE_IPV6_DEFAULT;
} else {
if (tox_options_get_savedata_type(options) != TOX_SAVEDATA_TYPE_NONE) {
if (tox_options_get_savedata_data(options) == NULL || tox_options_get_savedata_length(options) == 0) {
if (tox_options_get_savedata_data(options) == nullptr || tox_options_get_savedata_length(options) == 0) {
SET_ERROR_PARAMETER(error, TOX_ERR_NEW_LOAD_BAD_FORMAT);
return NULL;
return nullptr;
}
}
if (tox_options_get_savedata_type(options) == TOX_SAVEDATA_TYPE_SECRET_KEY) {
if (tox_options_get_savedata_length(options) != TOX_SECRET_KEY_SIZE) {
SET_ERROR_PARAMETER(error, TOX_ERR_NEW_LOAD_BAD_FORMAT);
return NULL;
return nullptr;
}
load_savedata_sk = 1;
} else if (tox_options_get_savedata_type(options) == TOX_SAVEDATA_TYPE_TOX_SAVE) {
if (tox_options_get_savedata_length(options) < TOX_ENC_SAVE_MAGIC_LENGTH) {
SET_ERROR_PARAMETER(error, TOX_ERR_NEW_LOAD_BAD_FORMAT);
return NULL;
return nullptr;
}
if (crypto_memcmp(tox_options_get_savedata_data(options), TOX_ENC_SAVE_MAGIC_NUMBER, TOX_ENC_SAVE_MAGIC_LENGTH) == 0) {
SET_ERROR_PARAMETER(error, TOX_ERR_NEW_LOAD_ENCRYPTED);
return NULL;
return nullptr;
}
load_savedata_tox = 1;
@ -141,13 +141,13 @@ Tox *tox_new(const struct Tox_Options *options, TOX_ERR_NEW *error)
default:
SET_ERROR_PARAMETER(error, TOX_ERR_NEW_PROXY_BAD_TYPE);
return NULL;
return nullptr;
}
if (m_options.proxy_info.proxy_type != TCP_PROXY_NONE) {
if (tox_options_get_proxy_port(options) == 0) {
SET_ERROR_PARAMETER(error, TOX_ERR_NEW_PROXY_BAD_PORT);
return NULL;
return nullptr;
}
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)
m_options.proxy_info.ip_port.ip.family = TOX_AF_UNSPEC;
}
if (!addr_resolve_or_parse_ip(tox_options_get_proxy_host(options), &m_options.proxy_info.ip_port.ip, NULL)) {
if (!addr_resolve_or_parse_ip(tox_options_get_proxy_host(options), &m_options.proxy_info.ip_port.ip, nullptr)) {
SET_ERROR_PARAMETER(error, TOX_ERR_NEW_PROXY_BAD_HOST);
// TODO(irungentoo): TOX_ERR_NEW_PROXY_NOT_FOUND if domain.
return NULL;
return nullptr;
}
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)
SET_ERROR_PARAMETER(error, TOX_ERR_NEW_MALLOC);
}
return NULL;
return nullptr;
}
if (load_savedata_tox
@ -198,7 +198,7 @@ Tox *tox_new(const struct Tox_Options *options, TOX_ERR_NEW *error)
void tox_kill(Tox *tox)
{
if (tox == NULL) {
if (tox == nullptr) {
return;
}

View File

@ -1,5 +1,7 @@
#include "tox.h"
#include "ccompat.h"
#include <stdlib.h>
#include <string.h>
@ -88,7 +90,7 @@ struct Tox_Options *tox_options_new(TOX_ERR_OPTIONS_NEW *error)
}
SET_ERROR_PARAMETER(error, TOX_ERR_OPTIONS_NEW_MALLOC);
return NULL;
return nullptr;
}
void tox_options_free(struct Tox_Options *options)

View File

@ -48,7 +48,7 @@ static uint64_t unix_base_time_value;
void unix_time_update(void)
{
if (unix_base_time_value == 0) {
unix_base_time_value = ((uint64_t)time(NULL) - (current_time_monotonic() / 1000ULL));
unix_base_time_value = ((uint64_t)time(nullptr) - (current_time_monotonic() / 1000ULL));
}
unix_time_value = (current_time_monotonic() / 1000ULL) + unix_base_time_value;

View File

@ -19,6 +19,7 @@ cc_library(
visibility = ["//c-toxcore:__subpackages__"],
deps = [
":defines",
"//c-toxcore/toxcore:ccompat",
"//c-toxcore/toxcore:crypto_core",
],
)

View File

@ -25,6 +25,7 @@
#include "config.h"
#endif
#include "../toxcore/ccompat.h"
#include "../toxcore/crypto_core.h"
#include "defines.h"
#include "toxencryptsave.h"
@ -134,7 +135,7 @@ Tox_Pass_Key *tox_pass_key_derive_with_salt(const uint8_t *passphrase, size_t pp
{
if (!salt || (!passphrase && pplength != 0)) {
SET_ERROR_PARAMETER(error, TOX_ERR_KEY_DERIVATION_NULL);
return NULL;
return nullptr;
}
uint8_t passkey[crypto_hash_sha256_BYTES];
@ -152,7 +153,7 @@ Tox_Pass_Key *tox_pass_key_derive_with_salt(const uint8_t *passphrase, size_t pp
crypto_pwhash_scryptsalsa208sha256_MEMLIMIT_INTERACTIVE) != 0) {
/* out of memory most likely */
SET_ERROR_PARAMETER(error, TOX_ERR_KEY_DERIVATION_FAILED);
return NULL;
return nullptr;
}
sodium_memzero(passkey, crypto_hash_sha256_BYTES); /* wipe plaintext pw */
@ -161,7 +162,7 @@ Tox_Pass_Key *tox_pass_key_derive_with_salt(const uint8_t *passphrase, size_t pp
if (!out_key) {
SET_ERROR_PARAMETER(error, TOX_ERR_KEY_DERIVATION_FAILED);
return NULL;
return nullptr;
}
memcpy(out_key->salt, salt, crypto_pwhash_scryptsalsa208sha256_SALTBYTES);
@ -320,7 +321,7 @@ bool tox_pass_decrypt(const uint8_t *data, size_t length, const uint8_t *passphr
memcpy(salt, data + TOX_ENC_SAVE_MAGIC_LENGTH, crypto_pwhash_scryptsalsa208sha256_SALTBYTES);
/* derive the key */
Tox_Pass_Key *key = tox_pass_key_derive_with_salt(passphrase, pplength, salt, NULL);
Tox_Pass_Key *key = tox_pass_key_derive_with_salt(passphrase, pplength, salt, nullptr);
if (!key) {
/* out of memory most likely */