From 92ffad1a72bc8c422426d52ac408bd71242dd047 Mon Sep 17 00:00:00 2001 From: iphydf Date: Sun, 28 Jan 2018 21:30:39 +0000 Subject: Use nullptr as NULL pointer constant instead of NULL or 0. This changes only code, no string literals or comments. --- other/DHT_bootstrap.c | 12 ++++++------ .../bootstrap_daemon/src/command_line_arguments.c | 4 +++- other/bootstrap_daemon/src/config.c | 14 +++++++------- other/bootstrap_daemon/src/log_backend_syslog.c | 2 +- other/bootstrap_daemon/src/tox-bootstrapd.c | 22 +++++++++++----------- other/fun/sign.c | 6 +++--- 6 files changed, 31 insertions(+), 29 deletions(-) (limited to 'other') diff --git a/other/DHT_bootstrap.c b/other/DHT_bootstrap.c index 33ca45c2..bbb4844e 100644 --- a/other/DHT_bootstrap.c +++ b/other/DHT_bootstrap.c @@ -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); } diff --git a/other/bootstrap_daemon/src/command_line_arguments.c b/other/bootstrap_daemon/src/command_line_arguments.c index dce828a7..d9747932 100644 --- a/other/bootstrap_daemon/src/command_line_arguments.c +++ b/other/bootstrap_daemon/src/command_line_arguments.c @@ -26,6 +26,8 @@ #include "global.h" +#include "../../../toxcore/ccompat.h" + #include #include @@ -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) { diff --git a/other/bootstrap_daemon/src/config.c b/other/bootstrap_daemon/src/config.c index 64fc4d94..3f1592e6 100644 --- a/other/bootstrap_daemon/src/config.c +++ b/other/bootstrap_daemon/src/config.c @@ -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; } diff --git a/other/bootstrap_daemon/src/log_backend_syslog.c b/other/bootstrap_daemon/src/log_backend_syslog.c index 88911a21..9fc6d18f 100644 --- a/other/bootstrap_daemon/src/log_backend_syslog.c +++ b/other/bootstrap_daemon/src/log_backend_syslog.c @@ -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); diff --git a/other/bootstrap_daemon/src/tox-bootstrapd.c b/other/bootstrap_daemon/src/tox-bootstrapd.c index e0472cba..bdf679c9 100644 --- a/other/bootstrap_daemon/src/tox-bootstrapd.c +++ b/other/bootstrap_daemon/src/tox-bootstrapd.c @@ -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"); diff --git a/other/fun/sign.c b/other/fun/sign.c index 0cd8f38e..b24cdae7 100644 --- a/other/fun/sign.c +++ b/other/fun/sign.c @@ -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; } -- cgit v1.2.3