diff --git a/.clang-tidy b/.clang-tidy index f808e71f13a..2a396a2cfe3 100644 --- a/.clang-tidy +++ b/.clang-tidy @@ -33,3 +33,6 @@ CheckOptions: value: Camel_Snake_Case - key: readability-identifier-naming.VariableCase value: lower_case + + - key: llvmlibc-restrict-system-libc-headers.Includes + value: "arpa/inet.h,assert.h,ctype.h,errno.h,fcntl.h,getopt.h,libconfig.h,linux/netdevice.h,math.h,netdb.h,netinet/in.h,opus.h,pthread.h,signal.h,sodium/crypto_scalarmult_curve25519.h,sodium.h,sodium/randombytes.h,stdio.h,stdlib.h,string.h,sys/ioctl.h,syslog.h,sys/resource.h,sys/socket.h,sys/stat.h,sys/time.h,sys/types.h,time.h,unistd.h,vpx/vp8cx.h,vpx/vp8dx.h,vpx/vpx_decoder.h,vpx/vpx_encoder.h,vpx/vpx_image.h" diff --git a/auto_tests/conference_av_test.c b/auto_tests/conference_av_test.c index 8e42f359e96..c366be42dc4 100644 --- a/auto_tests/conference_av_test.c +++ b/auto_tests/conference_av_test.c @@ -255,8 +255,12 @@ static void test_eventual_audio(AutoTox *autotoxes, const bool *disabled, uint64 uint64_t start = autotoxes[0].clock; while (autotoxes[0].clock < start + timeout) { - if (test_audio(autotoxes, disabled, true) - && test_audio(autotoxes, disabled, true)) { + if (!test_audio(autotoxes, disabled, true)) { + continue; + } + + // It needs to succeed twice in a row for the test to pass. + if (test_audio(autotoxes, disabled, true)) { printf("audio test successful after %d seconds\n", (int)((autotoxes[0].clock - start) / 1000)); return; } diff --git a/auto_tests/crypto_test.c b/auto_tests/crypto_test.c index f4fdf3e22de..36da0413064 100644 --- a/auto_tests/crypto_test.c +++ b/auto_tests/crypto_test.c @@ -9,9 +9,7 @@ static void rand_bytes(const Random *rng, uint8_t *b, size_t blen) { - size_t i; - - for (i = 0; i < blen; i++) { + for (size_t i = 0; i < blen; i++) { b[i] = random_u08(rng); } } @@ -84,19 +82,18 @@ static void test_known(void) { uint8_t c[147]; uint8_t m[131]; - uint16_t clen, mlen; ck_assert_msg(sizeof(c) == sizeof(m) + CRYPTO_MAC_SIZE * sizeof(uint8_t), "cyphertext should be CRYPTO_MAC_SIZE bytes longer than plaintext"); ck_assert_msg(sizeof(test_c) == sizeof(c), "sanity check failed"); ck_assert_msg(sizeof(test_m) == sizeof(m), "sanity check failed"); - clen = encrypt_data(bobpk, alicesk, test_nonce, test_m, sizeof(test_m) / sizeof(uint8_t), c); + const uint16_t clen = encrypt_data(bobpk, alicesk, test_nonce, test_m, sizeof(test_m) / sizeof(uint8_t), c); ck_assert_msg(memcmp(test_c, c, sizeof(c)) == 0, "cyphertext doesn't match test vector"); ck_assert_msg(clen == sizeof(c) / sizeof(uint8_t), "wrong ciphertext length"); - mlen = decrypt_data(bobpk, alicesk, test_nonce, test_c, sizeof(test_c) / sizeof(uint8_t), m); + const uint16_t mlen = decrypt_data(bobpk, alicesk, test_nonce, test_c, sizeof(test_c) / sizeof(uint8_t), m); ck_assert_msg(memcmp(test_m, m, sizeof(m)) == 0, "decrypted text doesn't match test vector"); ck_assert_msg(mlen == sizeof(m) / sizeof(uint8_t), "wrong plaintext length"); @@ -107,7 +104,6 @@ static void test_fast_known(void) uint8_t k[CRYPTO_SHARED_KEY_SIZE]; uint8_t c[147]; uint8_t m[131]; - uint16_t clen, mlen; encrypt_precompute(bobpk, alicesk, k); @@ -116,12 +112,12 @@ static void test_fast_known(void) ck_assert_msg(sizeof(test_c) == sizeof(c), "sanity check failed"); ck_assert_msg(sizeof(test_m) == sizeof(m), "sanity check failed"); - clen = encrypt_data_symmetric(k, test_nonce, test_m, sizeof(test_m) / sizeof(uint8_t), c); + const uint16_t clen = encrypt_data_symmetric(k, test_nonce, test_m, sizeof(test_m) / sizeof(uint8_t), c); ck_assert_msg(memcmp(test_c, c, sizeof(c)) == 0, "cyphertext doesn't match test vector"); ck_assert_msg(clen == sizeof(c) / sizeof(uint8_t), "wrong ciphertext length"); - mlen = decrypt_data_symmetric(k, test_nonce, test_c, sizeof(test_c) / sizeof(uint8_t), m); + const uint16_t mlen = decrypt_data_symmetric(k, test_nonce, test_c, sizeof(test_c) / sizeof(uint8_t), m); ck_assert_msg(memcmp(test_m, m, sizeof(m)) == 0, "decrypted text doesn't match test vector"); ck_assert_msg(mlen == sizeof(m) / sizeof(uint8_t), "wrong plaintext length"); @@ -275,10 +271,10 @@ static void test_large_data_symmetric(void) static void increment_nonce_number_cmp(uint8_t *nonce, uint32_t num) { - uint32_t num1, num2; + uint32_t num1 = 0; memcpy(&num1, nonce + (CRYPTO_NONCE_SIZE - sizeof(num1)), sizeof(num1)); num1 = net_ntohl(num1); - num2 = num + num1; + uint32_t num2 = num + num1; if (num2 < num1) { for (uint16_t i = CRYPTO_NONCE_SIZE - sizeof(num1); i != 0; --i) { @@ -299,11 +295,9 @@ static void test_increment_nonce(void) const Random *rng = system_random(); ck_assert(rng != nullptr); - uint32_t i; - uint8_t n[CRYPTO_NONCE_SIZE]; - for (i = 0; i < CRYPTO_NONCE_SIZE; ++i) { + for (uint32_t i = 0; i < CRYPTO_NONCE_SIZE; ++i) { n[i] = random_u08(rng); } @@ -311,13 +305,13 @@ static void test_increment_nonce(void) memcpy(n1, n, CRYPTO_NONCE_SIZE); - for (i = 0; i < (1 << 18); ++i) { + for (uint32_t i = 0; i < (1 << 18); ++i) { increment_nonce_number_cmp(n, 1); increment_nonce(n1); ck_assert_msg(memcmp(n, n1, CRYPTO_NONCE_SIZE) == 0, "Bad increment_nonce function"); } - for (i = 0; i < (1 << 18); ++i) { + for (uint32_t i = 0; i < (1 << 18); ++i) { const uint32_t r = random_u32(rng); increment_nonce_number_cmp(n, r); increment_nonce_number(n1, r); @@ -331,9 +325,8 @@ static void test_memzero(void) memcpy(src, test_c, sizeof(test_c)); crypto_memzero(src, sizeof(src)); - size_t i; - for (i = 0; i < sizeof(src); i++) { + for (size_t i = 0; i < sizeof(src); i++) { ck_assert_msg(src[i] == 0, "Memory is not zeroed"); } } diff --git a/auto_tests/onion_test.c b/auto_tests/onion_test.c index 282b99637e6..6975c3ec300 100644 --- a/auto_tests/onion_test.c +++ b/auto_tests/onion_test.c @@ -574,7 +574,6 @@ static void dht_pk_callback(void *object, int32_t number, const uint8_t *dht_pub static void test_announce(void) { - uint32_t i, j; uint32_t index[NUM_ONIONS]; Onions *onions[NUM_ONIONS]; const Random *rng = system_random(); @@ -582,7 +581,7 @@ static void test_announce(void) const Memory *mem = system_memory(); ck_assert(mem != nullptr); - for (i = 0; i < NUM_ONIONS; ++i) { + for (uint32_t i = 0; i < NUM_ONIONS; ++i) { index[i] = i + 1; onions[i] = new_onions(mem, rng, i + 36655, &index[i]); ck_assert_msg(onions[i] != nullptr, "Failed to create onions. %u", i); @@ -590,7 +589,7 @@ static void test_announce(void) IP ip = get_loopback(); - for (i = 3; i < NUM_ONIONS; ++i) { + for (uint32_t i = 3; i < NUM_ONIONS; ++i) { IP_Port ip_port = {ip, net_port(onions[i - 1]->onion->net)}; dht_bootstrap(onions[i]->onion->dht, &ip_port, dht_get_self_public_key(onions[i - 1]->onion->dht)); IP_Port ip_port1 = {ip, net_port(onions[i - 2]->onion->net)}; @@ -604,7 +603,7 @@ static void test_announce(void) do { connected = 0; - for (i = 0; i < NUM_ONIONS; ++i) { + for (uint32_t i = 0; i < NUM_ONIONS; ++i) { do_onions(onions[i]); connected += dht_isconnected(onions[i]->onion->dht); } @@ -614,8 +613,8 @@ static void test_announce(void) printf("connected\n"); - for (i = 0; i < 25 * 2; ++i) { - for (j = 0; j < NUM_ONIONS; ++j) { + for (uint32_t i = 0; i < 25 * 2; ++i) { + for (uint32_t j = 0; j < NUM_ONIONS; ++j) { do_onions(onions[j]); } @@ -637,7 +636,7 @@ static void test_announce(void) IP_Port ip_port; do { - for (i = 0; i < NUM_ONIONS; ++i) { + for (uint32_t i = 0; i < NUM_ONIONS; ++i) { do_onions(onions[i]); } @@ -647,7 +646,7 @@ static void test_announce(void) printf("Waiting for ips\n"); do { - for (i = 0; i < NUM_ONIONS; ++i) { + for (uint32_t i = 0; i < NUM_ONIONS; ++i) { do_onions(onions[i]); } @@ -657,7 +656,7 @@ static void test_announce(void) onion_getfriendip(onions[NUM_LAST]->onion_c, frnum, &ip_port); ck_assert_msg(ip_port.port == net_port(onions[NUM_FIRST]->onion->net), "Port in returned ip not correct."); - for (i = 0; i < NUM_ONIONS; ++i) { + for (uint32_t i = 0; i < NUM_ONIONS; ++i) { kill_onions(mem, onions[i]); } } diff --git a/auto_tests/tox_many_tcp_test.c b/auto_tests/tox_many_tcp_test.c index f466e3e1711..0fda9181fe9 100644 --- a/auto_tests/tox_many_tcp_test.c +++ b/auto_tests/tox_many_tcp_test.c @@ -46,10 +46,9 @@ static void test_many_clients_tcp(void) 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) { + for (uint32_t i = 0; i < NUM_TOXES_TCP; ++i) { struct Tox_Options *opts = tox_options_new(nullptr); if (i == 0) { @@ -72,7 +71,7 @@ static void test_many_clients_tcp(void) 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; + Tox_Err_Bootstrap error; ck_assert_msg(tox_add_tcp_relay(toxes[i], TOX_LOCALHOST, tcp_relay_port, dpk, &error), "add relay error, %u, %d", i, error); uint16_t first_port = tox_self_get_udp_port(toxes[0], nullptr); @@ -88,12 +87,12 @@ static void test_many_clients_tcp(void) uint8_t address[TOX_ADDRESS_SIZE]; - for (i = 0; i < NUM_FRIENDS; ++i) { + for (uint32_t i = 0; i < NUM_FRIENDS; ++i) { loop_top: pairs[i].tox1 = random_u32(rng) % NUM_TOXES_TCP; pairs[i].tox2 = (pairs[i].tox1 + random_u32(rng) % (NUM_TOXES_TCP - 1) + 1) % NUM_TOXES_TCP; - for (j = 0; j < i; ++j) { + for (uint32_t j = 0; j < i; ++j) { if (pairs[j].tox2 == pairs[i].tox1 && pairs[j].tox1 == pairs[i].tox2) { goto loop_top; } @@ -114,8 +113,8 @@ static void test_many_clients_tcp(void) while (true) { uint16_t counter = 0; - for (i = 0; i < NUM_TOXES_TCP; ++i) { - for (j = 0; j < tox_self_get_friend_list_size(toxes[i]); ++j) { + for (uint32_t i = 0; i < NUM_TOXES_TCP; ++i) { + for (uint32_t j = 0; j < tox_self_get_friend_list_size(toxes[i]); ++j) { if (tox_friend_get_connection_status(toxes[i], j, nullptr) == TOX_CONNECTION_TCP) { ++counter; } @@ -126,14 +125,14 @@ static void test_many_clients_tcp(void) break; } - for (i = 0; i < NUM_TOXES_TCP; ++i) { + for (uint32_t i = 0; i < NUM_TOXES_TCP; ++i) { tox_iterate(toxes[i], &to_comp); } c_sleep(50); } - for (i = 0; i < NUM_TOXES_TCP; ++i) { + for (uint32_t i = 0; i < NUM_TOXES_TCP; ++i) { tox_kill(toxes[i]); } @@ -149,10 +148,9 @@ static void test_many_clients_tcp_b(void) 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) { + for (uint32_t i = 0; i < NUM_TOXES_TCP; ++i) { struct Tox_Options *opts = tox_options_new(nullptr); if (i < NUM_TCP_RELAYS) { @@ -183,12 +181,12 @@ static void test_many_clients_tcp_b(void) uint8_t address[TOX_ADDRESS_SIZE]; - for (i = 0; i < NUM_FRIENDS; ++i) { + for (uint32_t i = 0; i < NUM_FRIENDS; ++i) { loop_top: pairs[i].tox1 = random_u32(rng) % NUM_TOXES_TCP; pairs[i].tox2 = (pairs[i].tox1 + random_u32(rng) % (NUM_TOXES_TCP - 1) + 1) % NUM_TOXES_TCP; - for (j = 0; j < i; ++j) { + for (uint32_t j = 0; j < i; ++j) { if (pairs[j].tox2 == pairs[i].tox1 && pairs[j].tox1 == pairs[i].tox2) { goto loop_top; } @@ -211,8 +209,8 @@ static void test_many_clients_tcp_b(void) while (true) { uint16_t counter = 0; - for (i = 0; i < NUM_TOXES_TCP; ++i) { - for (j = 0; j < tox_self_get_friend_list_size(toxes[i]); ++j) { + for (uint32_t i = 0; i < NUM_TOXES_TCP; ++i) { + for (uint32_t j = 0; j < tox_self_get_friend_list_size(toxes[i]); ++j) { if (tox_friend_get_connection_status(toxes[i], j, nullptr) == TOX_CONNECTION_TCP) { ++counter; } @@ -228,14 +226,14 @@ static void test_many_clients_tcp_b(void) break; } - for (i = 0; i < NUM_TOXES_TCP; ++i) { + for (uint32_t i = 0; i < NUM_TOXES_TCP; ++i) { tox_iterate(toxes[i], &to_comp); } c_sleep(30); } - for (i = 0; i < NUM_TOXES_TCP; ++i) { + for (uint32_t i = 0; i < NUM_TOXES_TCP; ++i) { tox_kill(toxes[i]); } diff --git a/other/DHT_bootstrap.c b/other/DHT_bootstrap.c index f48b3025f87..cb469bfdce9 100644 --- a/other/DHT_bootstrap.c +++ b/other/DHT_bootstrap.c @@ -82,38 +82,33 @@ static void manage_keys(DHT *dht) fclose(keys_file); } -static void print_log(void *context, Logger_Level level, const char *file, int line, - const char *func, const char *message, void *userdata) +static const char *strlevel(Logger_Level level) { - const char *strlevel; - switch (level) { case LOGGER_LEVEL_TRACE: - strlevel = "TRACE"; - break; + return "TRACE"; case LOGGER_LEVEL_DEBUG: - strlevel = "DEBUG"; - break; + return "DEBUG"; case LOGGER_LEVEL_INFO: - strlevel = "INFO"; - break; + return "INFO"; case LOGGER_LEVEL_WARNING: - strlevel = "WARNING"; - break; + return "WARNING"; case LOGGER_LEVEL_ERROR: - strlevel = "ERROR"; - break; + return "ERROR"; default: - strlevel = ""; - break; + return ""; } +} - fprintf(stderr, "[%s] %s:%d(%s) %s\n", strlevel, file, line, func, message); +static void print_log(void *context, Logger_Level level, const char *file, int line, + const char *func, const char *message, void *userdata) +{ + fprintf(stderr, "[%s] %s:%d(%s) %s\n", strlevel(level), file, line, func, message); } int main(int argc, char *argv[]) @@ -139,7 +134,7 @@ int main(int argc, char *argv[]) Logger *logger = logger_new(); - if (MIN_LOGGER_LEVEL == LOGGER_LEVEL_TRACE || MIN_LOGGER_LEVEL == LOGGER_LEVEL_DEBUG) { + if (MIN_LOGGER_LEVEL <= LOGGER_LEVEL_DEBUG) { logger_callback_log(logger, print_log, nullptr, nullptr); } diff --git a/other/analysis/run-clang-tidy b/other/analysis/run-clang-tidy index c8d1a86a88c..ac9175e8847 100755 --- a/other/analysis/run-clang-tidy +++ b/other/analysis/run-clang-tidy @@ -6,7 +6,9 @@ CHECKS="*" CHECKS="$CHECKS,-clang-diagnostic-pointer-bool-conversion" CHECKS="$CHECKS,-clang-diagnostic-tautological-pointer-compare" -CHECKS="$CHECKS,-clang-diagnostic-unknown-warning-option" +# Conflicts with "Variable is assigned a value that is never used." +# [unreadVariable] +CHECKS="$CHECKS,-cppcoreguidelines-init-variables" # Short variable names are used quite a lot, and we don't consider them a # readability issue. @@ -29,21 +31,24 @@ CHECKS="$CHECKS,-cert-dcl51-cpp" # the toxencryptsave magic number. CHECKS="$CHECKS,-bugprone-not-null-terminated-result" +# We don't want default labels in enum switches. +CHECKS="$CHECKS,-hicpp-multiway-paths-covered" + +# This can make readability quite a bit worse when the 2 cases look very +# similar. +CHECKS="$CHECKS,-llvm-else-after-return" +CHECKS="$CHECKS,-readability-else-after-return" + +# We need 'return;' in empty functions because cimple won't allow empty +# functions otherwise. +CHECKS="$CHECKS,-readability-redundant-control-flow" + # TODO(iphydf): We might want some of these. For the ones we don't want, add a # comment explaining why not. CHECKS="$CHECKS,-clang-analyzer-optin.performance.Padding" -CHECKS="$CHECKS,-cppcoreguidelines-init-variables" -CHECKS="$CHECKS,-hicpp-multiway-paths-covered" CHECKS="$CHECKS,-hicpp-signed-bitwise" -CHECKS="$CHECKS,-llvm-else-after-return" -CHECKS="$CHECKS,-llvmlibc-restrict-system-libc-headers" -CHECKS="$CHECKS,-misc-redundant-expression" CHECKS="$CHECKS,-misc-unused-parameters" -CHECKS="$CHECKS,-readability-else-after-return" CHECKS="$CHECKS,-readability-function-cognitive-complexity" -CHECKS="$CHECKS,-readability-inconsistent-declaration-parameter-name" -CHECKS="$CHECKS,-readability-magic-numbers" -CHECKS="$CHECKS,-readability-redundant-control-flow" # TODO(iphydf): Maybe fix these? CHECKS="$CHECKS,-altera-id-dependent-backward-branch" @@ -61,13 +66,14 @@ CHECKS="$CHECKS,-clang-analyzer-valist.Uninitialized" CHECKS="$CHECKS,-concurrency-mt-unsafe" CHECKS="$CHECKS,-cppcoreguidelines-avoid-non-const-global-variables" CHECKS="$CHECKS,-cppcoreguidelines-narrowing-conversions" -CHECKS="$CHECKS,-google-readability-casting" CHECKS="$CHECKS,-misc-no-recursion" # TODO(iphydf): Probably fix these. CHECKS="$CHECKS,-cert-err33-c" CHECKS="$CHECKS,-cppcoreguidelines-avoid-magic-numbers" +CHECKS="$CHECKS,-google-readability-casting" CHECKS="$CHECKS,-modernize-macro-to-enum" +CHECKS="$CHECKS,-readability-magic-numbers" ERRORS="*" diff --git a/other/bootstrap_daemon/docker/tox-bootstrapd.sha256 b/other/bootstrap_daemon/docker/tox-bootstrapd.sha256 index 251196a3104..dad4290e4a5 100644 --- a/other/bootstrap_daemon/docker/tox-bootstrapd.sha256 +++ b/other/bootstrap_daemon/docker/tox-bootstrapd.sha256 @@ -1 +1 @@ -a8917dcace422e2a6644f140463da7b9e70e67a7e15f5209c572b72650d87368 /usr/local/bin/tox-bootstrapd +3089925fd022dec8ec335435caf56f6ad5ccd2bf916f92f86a544da0ff654501 /usr/local/bin/tox-bootstrapd diff --git a/other/bootstrap_daemon/src/tox-bootstrapd.c b/other/bootstrap_daemon/src/tox-bootstrapd.c index 2d86e9d26eb..b56eab6b949 100644 --- a/other/bootstrap_daemon/src/tox-bootstrapd.c +++ b/other/bootstrap_daemon/src/tox-bootstrapd.c @@ -61,7 +61,7 @@ static int manage_keys(DHT *dht, char *keys_file_path) { enum { KEYS_SIZE = CRYPTO_PUBLIC_KEY_SIZE + CRYPTO_SECRET_KEY_SIZE }; uint8_t keys[KEYS_SIZE]; - FILE *keys_file; + FILE *keys_file = nullptr; // Check if file exits, proceed to open and load keys keys_file = fopen(keys_file_path, "rb"); @@ -120,7 +120,7 @@ static void print_public_key(const uint8_t *public_key) static void daemonize(LOG_BACKEND log_backend, char *pid_file_path) { // Check if the PID file exists - FILE *pid_file; + FILE *pid_file = nullptr; if ((pid_file = fopen(pid_file_path, "r"))) { log_write(LOG_LEVEL_WARNING, "Another instance of the daemon is already running, PID file %s exists.\n", pid_file_path); @@ -175,38 +175,33 @@ static void daemonize(LOG_BACKEND log_backend, char *pid_file_path) // Logs toxcore logger message using our logger facility -static void toxcore_logger_callback(void *context, Logger_Level level, const char *file, int line, - const char *func, const char *message, void *userdata) +static LOG_LEVEL logger_level_to_log_level(Logger_Level level) { - LOG_LEVEL log_level; - switch (level) { case LOGGER_LEVEL_TRACE: - log_level = LOG_LEVEL_INFO; - break; + return LOG_LEVEL_INFO; case LOGGER_LEVEL_DEBUG: - log_level = LOG_LEVEL_INFO; - break; + return LOG_LEVEL_INFO; case LOGGER_LEVEL_INFO: - log_level = LOG_LEVEL_INFO; - break; + return LOG_LEVEL_INFO; case LOGGER_LEVEL_WARNING: - log_level = LOG_LEVEL_WARNING; - break; + return LOG_LEVEL_WARNING; case LOGGER_LEVEL_ERROR: - log_level = LOG_LEVEL_ERROR; - break; + return LOG_LEVEL_ERROR; default: - log_level = LOG_LEVEL_INFO; - break; + return LOG_LEVEL_INFO; } +} - log_write(log_level, "%s:%d(%s) %s\n", file, line, func, message); +static void toxcore_logger_callback(void *context, Logger_Level level, const char *file, int line, + const char *func, const char *message, void *userdata) +{ + log_write(logger_level_to_log_level(level), "%s:%d(%s) %s\n", file, line, func, message); } static volatile sig_atomic_t caught_signal = 0; @@ -220,11 +215,10 @@ int main(int argc, char *argv[]) { umask(077); char *cfg_file_path = nullptr; - LOG_BACKEND log_backend; - bool run_in_foreground; + bool run_in_foreground = 0; // choose backend for printing command line argument parsing output based on whether the daemon is being run from a terminal - log_backend = isatty(STDOUT_FILENO) ? LOG_BACKEND_STDOUT : LOG_BACKEND_SYSLOG; + LOG_BACKEND log_backend = isatty(STDOUT_FILENO) ? LOG_BACKEND_STDOUT : LOG_BACKEND_SYSLOG; log_open(log_backend); handle_command_line_arguments(argc, argv, &cfg_file_path, &log_backend, &run_in_foreground); @@ -236,14 +230,14 @@ int main(int argc, char *argv[]) char *pid_file_path = nullptr; char *keys_file_path = nullptr; - int start_port; - int enable_ipv6; - int enable_ipv4_fallback; - int enable_lan_discovery; - int enable_tcp_relay; + int start_port = 0; + int enable_ipv6 = 0; + int enable_ipv4_fallback = 0; + int enable_lan_discovery = 0; + int enable_tcp_relay = 0; uint16_t *tcp_relay_ports = nullptr; - int tcp_relay_port_count; - int enable_motd; + int tcp_relay_port_count = 0; + int enable_motd = 0; char *motd = nullptr; if (get_general_config(cfg_file_path, &pid_file_path, &keys_file_path, &start_port, &enable_ipv6, &enable_ipv4_fallback, @@ -275,7 +269,7 @@ int main(int argc, char *argv[]) Logger *logger = logger_new(); - if (MIN_LOGGER_LEVEL == LOGGER_LEVEL_TRACE || MIN_LOGGER_LEVEL == LOGGER_LEVEL_DEBUG) { + if (MIN_LOGGER_LEVEL <= LOGGER_LEVEL_DEBUG) { logger_callback_log(logger, toxcore_logger_callback, nullptr, nullptr); }