diff --git a/.clang-tidy b/.clang-tidy index b6423bc9..2f25d8d4 100644 --- a/.clang-tidy +++ b/.clang-tidy @@ -35,8 +35,12 @@ CheckOptions: 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,limits.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,stdarg.h,stdbool.h,stdint.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" + value: "arpa/inet.h,assert.h,ctype.h,errno.h,fcntl.h,getopt.h,libconfig.h,limits.h,linux/if.h,math.h,netdb.h,netinet/in.h,opus.h,pthread.h,signal.h,sodium/crypto_scalarmult_curve25519.h,sodium.h,sodium/randombytes.h,stdarg.h,stdbool.h,stdint.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" - key: hicpp-signed-bitwise.IgnorePositiveIntegerLiterals value: true - key: concurrency-mt-unsafe.FunctionSet value: posix + - key: misc-include-cleaner.IgnoreHeaders + value: "pthread.h;stdbool.h;stddef.h;stdint.;stdint.h;stdint...;cstdint;sodium.*;sys/.*;unistd.h;opus.*;vpx.*;attributes.h;tox_struct.h" + - key: readability-function-cognitive-complexity.Threshold + value: 153 # TODO(iphydf): Decrease. tox_new is the highest at the moment. diff --git a/.github/settings.yml b/.github/settings.yml index 6e118f0d..2dae52a9 100644 --- a/.github/settings.yml +++ b/.github/settings.yml @@ -27,7 +27,6 @@ branches: - "ci/circleci: bazel-msan" - "ci/circleci: bazel-tsan" - "ci/circleci: clang-analyze" - - "ci/circleci: clang-tidy" - "ci/circleci: cpplint" - "ci/circleci: infer" - "ci/circleci: static-analysis" @@ -35,6 +34,8 @@ branches: - "ci/circleci: ubsan" - "cimple" - "cimplefmt" + - "clang-tidy" + - "cppcheck" - "CodeFactor" - "code-review/reviewable" - "common / buildifier" diff --git a/other/BUILD.bazel b/other/BUILD.bazel index 253cfcd0..50693bda 100644 --- a/other/BUILD.bazel +++ b/other/BUILD.bazel @@ -21,13 +21,11 @@ cc_binary( "//c-toxcore/toxcore:Messenger", "//c-toxcore/toxcore:TCP_server", "//c-toxcore/toxcore:ccompat", - "//c-toxcore/toxcore:friend_requests", "//c-toxcore/toxcore:group_onion_announce", "//c-toxcore/toxcore:logger", "//c-toxcore/toxcore:mono_time", "//c-toxcore/toxcore:network", "//c-toxcore/toxcore:onion_announce", "//c-toxcore/toxcore:tox", - "//c-toxcore/toxcore:util", ], ) diff --git a/other/DHT_bootstrap.c b/other/DHT_bootstrap.c index 6c5a27c6..5fd2568d 100644 --- a/other/DHT_bootstrap.c +++ b/other/DHT_bootstrap.c @@ -16,12 +16,17 @@ #include "../toxcore/DHT.h" #include "../toxcore/LAN_discovery.h" #include "../toxcore/ccompat.h" -#include "../toxcore/friend_requests.h" +#include "../toxcore/crypto_core.h" +#include "../toxcore/forwarding.h" +#include "../toxcore/group_announce.h" #include "../toxcore/group_onion_announce.h" #include "../toxcore/logger.h" +#include "../toxcore/mem.h" #include "../toxcore/mono_time.h" +#include "../toxcore/network.h" +#include "../toxcore/onion.h" +#include "../toxcore/onion_announce.h" #include "../toxcore/tox.h" -#include "../toxcore/util.h" #define TCP_RELAY_ENABLED diff --git a/other/analysis/run-clang-tidy b/other/analysis/run-clang-tidy index dc8177f6..d4bcd5f0 100755 --- a/other/analysis/run-clang-tidy +++ b/other/analysis/run-clang-tidy @@ -8,38 +8,47 @@ ERRORS="*" # TODO(iphydf): Fix these. ERRORS="$ERRORS,-cert-err34-c" -ERRORS="$ERRORS,-cert-str34-c" ERRORS="$ERRORS,-readability-suspicious-call-argument" +# TODO(iphydf): Fix once cimple 0.0.19 is released. +CHECKS="$CHECKS,-google-readability-casting" + # TODO(iphydf): Fix these. CHECKS="$CHECKS,-bugprone-switch-missing-default-case" -CHECKS="$CHECKS,-misc-include-cleaner" # 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,-hicpp-signed-bitwise" -CHECKS="$CHECKS,-readability-function-cognitive-complexity" # TODO(iphydf): Maybe fix these? -CHECKS="$CHECKS,-bugprone-easily-swappable-parameters" CHECKS="$CHECKS,-bugprone-implicit-widening-of-multiplication-result" CHECKS="$CHECKS,-bugprone-integer-division" -CHECKS="$CHECKS,-clang-analyzer-core.NullDereference" -CHECKS="$CHECKS,-clang-analyzer-valist.Uninitialized" -CHECKS="$CHECKS,-cppcoreguidelines-avoid-non-const-global-variables" CHECKS="$CHECKS,-misc-no-recursion" +# TODO(iphydf): Only happens in bootstrap_daemon. Fix it. +CHECKS="$CHECKS,-cppcoreguidelines-avoid-non-const-global-variables" + # 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" +# TODO(iphydf): We're using a lot of macros for constants. Should we convert +# all of them to enum? +CHECKS="$CHECKS,-modernize-macro-to-enum" + # Documented disabled checks. We don't want these for sure. # ========================================================= +# https://stackoverflow.com/questions/58672959/why-does-clang-tidy-say-vsnprintf-has-an-uninitialized-va-list-argument +CHECKS="$CHECKS,-clang-analyzer-valist.Uninitialized" + +# We pass a lot of ints around, so many function parameters are some kind of +# int type that can be converted from another int type. We won't be getting +# away from that anytime soon. +CHECKS="$CHECKS,-bugprone-easily-swappable-parameters" + # Callback handlers often don't use all their parameters. There's # IgnoreVirtual, but that doesn't work for C-style callbacks. CHECKS="$CHECKS,-misc-unused-parameters" @@ -132,27 +141,46 @@ CHECKS="$CHECKS,-misc-static-assert" set -eux +# TODO(iphydf): Add toxav. +DIRS=( + other/bootstrap_daemon/src + other + toxcore + toxcore/events + toxencryptsave +) + +copy_files() { + find "${DIRS[@]}" \ + -maxdepth 1 -type d -exec mkdir -p "$1/{}" \; + find "${DIRS[@]}" \ + -maxdepth 1 -name "*.c" -exec cp "{}" "$1/{}" \; +} + run() { echo "Running clang-tidy in variant '$*'" EXTRA_ARGS=("$@") for i in "${!EXTRA_ARGS[@]}"; do EXTRA_ARGS[$i]="--extra-arg=${EXTRA_ARGS[$i]}" done - find \ - other/bootstrap_daemon/src \ - other \ - toxav \ - toxcore \ - toxcore/events \ - toxencryptsave \ + ls .clang-tidy + copy_files a + if ! find "${DIRS[@]}" \ -maxdepth 1 -name "*.c" -print0 \ | xargs -0 -n15 -P"$(nproc)" clang-tidy \ -p=_build \ --extra-arg=-DMIN_LOGGER_LEVEL=LOGGER_LEVEL_TRACE \ "${EXTRA_ARGS[@]}" \ + --fix \ --checks="$CHECKS" \ --warnings-as-errors="$ERRORS" \ - --use-color + --use-color; then + copy_files b + colordiff -ru a b + rm -rf a b + false + fi + rm -rf a } cmake . -B_build -GNinja -DCMAKE_EXPORT_COMPILE_COMMANDS=ON diff --git a/other/bootstrap_daemon/BUILD.bazel b/other/bootstrap_daemon/BUILD.bazel index dce64bbe..6d4b157b 100644 --- a/other/bootstrap_daemon/BUILD.bazel +++ b/other/bootstrap_daemon/BUILD.bazel @@ -18,7 +18,6 @@ cc_binary( "//c-toxcore/toxcore:mono_time", "//c-toxcore/toxcore:onion_announce", "//c-toxcore/toxcore:tox", - "//c-toxcore/toxcore:util", "@libconfig", ], ) diff --git a/other/bootstrap_daemon/docker/tox-bootstrapd.sha256 b/other/bootstrap_daemon/docker/tox-bootstrapd.sha256 index 57cad658..a1ee4683 100644 --- a/other/bootstrap_daemon/docker/tox-bootstrapd.sha256 +++ b/other/bootstrap_daemon/docker/tox-bootstrapd.sha256 @@ -1 +1 @@ -793cce1916b0d406b8e337d1a5243dc71b07727974cc83a3ef39b7af6cbf6cdb /usr/local/bin/tox-bootstrapd +c93d2d972558f578c6893aa12c1dafadf8b3dbb959b68c22efbfe7ad00d20f88 /usr/local/bin/tox-bootstrapd diff --git a/other/bootstrap_daemon/src/command_line_arguments.c b/other/bootstrap_daemon/src/command_line_arguments.c index 60bd5245..16b76ae1 100644 --- a/other/bootstrap_daemon/src/command_line_arguments.c +++ b/other/bootstrap_daemon/src/command_line_arguments.c @@ -10,12 +10,12 @@ #include "command_line_arguments.h" #include "global.h" +#include "log.h" #include "../../../toxcore/ccompat.h" #include -#include #include diff --git a/other/bootstrap_daemon/src/config.c b/other/bootstrap_daemon/src/config.c index 9f579d92..200a94fa 100644 --- a/other/bootstrap_daemon/src/config.c +++ b/other/bootstrap_daemon/src/config.c @@ -10,6 +10,7 @@ #include "config.h" #include "config_defaults.h" +#include "global.h" #include "log.h" #include @@ -18,6 +19,10 @@ #include +#include "../../../toxcore/DHT.h" +#include "../../../toxcore/ccompat.h" +#include "../../../toxcore/crypto_core.h" +#include "../../../toxcore/network.h" #include "../../bootstrap_node_packets.h" /** diff --git a/other/bootstrap_daemon/src/log.c b/other/bootstrap_daemon/src/log.c index bc36b9c8..ed3bf03d 100644 --- a/other/bootstrap_daemon/src/log.c +++ b/other/bootstrap_daemon/src/log.c @@ -3,6 +3,8 @@ * Copyright © 2015-2016 Tox project. */ +#include + /* * Tox DHT bootstrap daemon. * Logging utility with support of multiple logging backends. diff --git a/other/bootstrap_daemon/src/log_backend_stdout.c b/other/bootstrap_daemon/src/log_backend_stdout.c index 3fac48c0..854c7678 100644 --- a/other/bootstrap_daemon/src/log_backend_stdout.c +++ b/other/bootstrap_daemon/src/log_backend_stdout.c @@ -9,8 +9,11 @@ */ #include "log_backend_stdout.h" +#include #include +#include "log.h" + static FILE *log_backend_stdout_level(LOG_LEVEL level) { switch (level) { diff --git a/other/bootstrap_daemon/src/log_backend_syslog.c b/other/bootstrap_daemon/src/log_backend_syslog.c index ad2bf4eb..1f73d9a6 100644 --- a/other/bootstrap_daemon/src/log_backend_syslog.c +++ b/other/bootstrap_daemon/src/log_backend_syslog.c @@ -10,10 +10,12 @@ #include "log_backend_syslog.h" #include "global.h" +#include "log.h" #include "../../../toxcore/ccompat.h" #include +#include #include #include #include diff --git a/other/bootstrap_daemon/src/tox-bootstrapd.c b/other/bootstrap_daemon/src/tox-bootstrapd.c index 57eed234..2f8912c2 100644 --- a/other/bootstrap_daemon/src/tox-bootstrapd.c +++ b/other/bootstrap_daemon/src/tox-bootstrapd.c @@ -23,17 +23,24 @@ #include #include #include +#include // toxcore -#include "../../../toxcore/tox.h" +#include "../../../toxcore/DHT.h" #include "../../../toxcore/LAN_discovery.h" #include "../../../toxcore/TCP_server.h" #include "../../../toxcore/announce.h" +#include "../../../toxcore/ccompat.h" +#include "../../../toxcore/crypto_core.h" +#include "../../../toxcore/forwarding.h" +#include "../../../toxcore/group_announce.h" #include "../../../toxcore/group_onion_announce.h" #include "../../../toxcore/logger.h" +#include "../../../toxcore/mem.h" #include "../../../toxcore/mono_time.h" +#include "../../../toxcore/network.h" +#include "../../../toxcore/onion.h" #include "../../../toxcore/onion_announce.h" -#include "../../../toxcore/util.h" // misc #include "../../bootstrap_node_packets.h" diff --git a/other/bootstrap_node_packets.c b/other/bootstrap_node_packets.c index 7ff0e9e7..fb009218 100644 --- a/other/bootstrap_node_packets.c +++ b/other/bootstrap_node_packets.c @@ -12,6 +12,8 @@ #include +#include "../toxcore/network.h" + #define INFO_REQUEST_PACKET_LENGTH 78 static uint32_t bootstrap_version; diff --git a/other/docker/clang-tidy/Dockerfile b/other/docker/clang-tidy/Dockerfile index a7e58fd9..a7610a6f 100644 --- a/other/docker/clang-tidy/Dockerfile +++ b/other/docker/clang-tidy/Dockerfile @@ -5,6 +5,7 @@ RUN ["apk", "add", "--no-cache", \ "clang", \ "clang-extra-tools", \ "cmake", \ + "colordiff", \ "libconfig-dev", \ "libsodium-dev", \ "libvpx-dev", \ diff --git a/toxcore/DHT.c b/toxcore/DHT.c index 66a16600..ee01d648 100644 --- a/toxcore/DHT.c +++ b/toxcore/DHT.c @@ -16,13 +16,15 @@ #include "LAN_discovery.h" #include "bin_pack.h" #include "ccompat.h" +#include "crypto_core.h" #include "logger.h" +#include "mem.h" #include "mono_time.h" #include "network.h" #include "ping.h" +#include "ping_array.h" #include "shared_key_cache.h" #include "state.h" -#include "util.h" /** The timeout after which a node is discarded completely. */ #define KILL_NODE_TIMEOUT (BAD_NODE_TIMEOUT + PING_INTERVAL) diff --git a/toxcore/LAN_discovery.c b/toxcore/LAN_discovery.c index ef44d3b5..f068814b 100644 --- a/toxcore/LAN_discovery.c +++ b/toxcore/LAN_discovery.c @@ -32,7 +32,7 @@ #endif #ifdef __linux__ -#include +#include #endif #if defined(__FreeBSD__) || defined(__DragonFly__) @@ -41,7 +41,7 @@ #include "ccompat.h" #include "crypto_core.h" -#include "util.h" +#include "network.h" #define MAX_INTERFACES 16 diff --git a/toxcore/Messenger.c b/toxcore/Messenger.c index 03872cc6..22abfb75 100644 --- a/toxcore/Messenger.c +++ b/toxcore/Messenger.c @@ -10,17 +10,33 @@ #include #include -#include #include #include #include "DHT.h" +#include "TCP_client.h" +#include "TCP_connection.h" +#include "TCP_server.h" +#include "announce.h" +#include "bin_pack.h" +#include "bin_unpack.h" #include "ccompat.h" +#include "crypto_core.h" +#include "forwarding.h" +#include "friend_connection.h" +#include "friend_requests.h" +#include "group_announce.h" #include "group_chats.h" +#include "group_common.h" #include "group_onion_announce.h" #include "logger.h" +#include "mem.h" #include "mono_time.h" +#include "net_crypto.h" #include "network.h" +#include "onion.h" +#include "onion_announce.h" +#include "onion_client.h" #include "state.h" #include "util.h" diff --git a/toxcore/TCP_client.c b/toxcore/TCP_client.c index a698eca8..06476ebb 100644 --- a/toxcore/TCP_client.c +++ b/toxcore/TCP_client.c @@ -10,12 +10,17 @@ #include #include -#include #include +#include "DHT.h" #include "TCP_common.h" #include "ccompat.h" +#include "crypto_core.h" +#include "forwarding.h" +#include "logger.h" +#include "mem.h" #include "mono_time.h" +#include "network.h" #include "util.h" typedef struct TCP_Client_Conn { diff --git a/toxcore/TCP_common.c b/toxcore/TCP_common.c index 4d0d009f..157ec144 100644 --- a/toxcore/TCP_common.c +++ b/toxcore/TCP_common.c @@ -5,10 +5,13 @@ #include "TCP_common.h" -#include #include #include "ccompat.h" +#include "crypto_core.h" +#include "logger.h" +#include "mem.h" +#include "network.h" void wipe_priority_list(const Memory *mem, TCP_Priority_List *p) { diff --git a/toxcore/TCP_connection.c b/toxcore/TCP_connection.c index c6118cdd..4ed1ce09 100644 --- a/toxcore/TCP_connection.c +++ b/toxcore/TCP_connection.c @@ -9,12 +9,17 @@ #include "TCP_connection.h" #include -#include #include +#include "DHT.h" #include "TCP_client.h" #include "ccompat.h" +#include "crypto_core.h" +#include "forwarding.h" +#include "logger.h" +#include "mem.h" #include "mono_time.h" +#include "network.h" #include "util.h" struct TCP_Connections { diff --git a/toxcore/TCP_server.c b/toxcore/TCP_server.c index c07b176a..9809da13 100644 --- a/toxcore/TCP_server.c +++ b/toxcore/TCP_server.c @@ -8,7 +8,6 @@ */ #include "TCP_server.h" -#include #include #if !defined(_WIN32) && !defined(__WIN32__) && !defined (WIN32) #include @@ -19,11 +18,17 @@ #include #endif +#include "DHT.h" #include "TCP_common.h" #include "ccompat.h" +#include "crypto_core.h" +#include "forwarding.h" #include "list.h" +#include "logger.h" +#include "mem.h" #include "mono_time.h" -#include "util.h" +#include "network.h" +#include "onion.h" #ifdef TCP_SERVER_USE_EPOLL #define TCP_SOCKET_LISTENING 0 @@ -909,7 +914,7 @@ static Socket new_listening_tcp_socket(const Logger *logger, const Network *ns, if (!sock_valid(sock)) { LOGGER_ERROR(logger, "TCP socket creation failed (family = %d)", family.value); - return net_invalid_socket; + return net_invalid_socket(); } bool ok = set_socket_nonblock(ns, sock); @@ -930,7 +935,7 @@ static Socket new_listening_tcp_socket(const Logger *logger, const Network *ns, port, family.value, error != nullptr ? error : "(null)"); net_kill_strerror(error); kill_sock(ns, sock); - return net_invalid_socket; + return net_invalid_socket(); } LOGGER_DEBUG(logger, "successfully bound to TCP port %d", port); diff --git a/toxcore/announce.c b/toxcore/announce.c index 5ac49867..19f15f41 100644 --- a/toxcore/announce.c +++ b/toxcore/announce.c @@ -12,8 +12,15 @@ #include #include +#include "DHT.h" #include "LAN_discovery.h" #include "ccompat.h" +#include "crypto_core.h" +#include "forwarding.h" +#include "logger.h" +#include "mem.h" +#include "mono_time.h" +#include "network.h" #include "shared_key_cache.h" #include "timed_auth.h" #include "util.h" @@ -427,7 +434,7 @@ static int create_reply_plain_store_announce_request(Announcements *announce, const uint8_t *to_auth, uint16_t to_auth_length) { const int plain_len = (int)length - (CRYPTO_PUBLIC_KEY_SIZE + CRYPTO_NONCE_SIZE + CRYPTO_MAC_SIZE); - const int announcement_len = (int)plain_len - (TIMED_AUTH_SIZE + sizeof(uint32_t) + 1); + const int announcement_len = plain_len - (TIMED_AUTH_SIZE + sizeof(uint32_t) + 1); const uint8_t *const data_public_key = data; diff --git a/toxcore/bin_pack.c b/toxcore/bin_pack.c index 51f2ff5b..774f03a6 100644 --- a/toxcore/bin_pack.c +++ b/toxcore/bin_pack.c @@ -10,6 +10,7 @@ #include "../third_party/cmp/cmp.h" #include "ccompat.h" +#include "logger.h" struct Bin_Pack { uint8_t *bytes; diff --git a/toxcore/ccompat.c b/toxcore/ccompat.c index 30e689d0..bc884af2 100644 --- a/toxcore/ccompat.c +++ b/toxcore/ccompat.c @@ -2,3 +2,5 @@ * Copyright © 2022 The TokTok team. */ #include "ccompat.h" + +static_assert(sizeof(int) >= 4, "toxcore does not support 16-bit platform"); diff --git a/toxcore/events/conference_connected.c b/toxcore/events/conference_connected.c index ce278755..fe51503f 100644 --- a/toxcore/events/conference_connected.c +++ b/toxcore/events/conference_connected.c @@ -6,7 +6,6 @@ #include #include -#include #include "../bin_pack.h" #include "../bin_unpack.h" diff --git a/toxcore/events/conference_peer_list_changed.c b/toxcore/events/conference_peer_list_changed.c index b6aaa3bf..9360f89d 100644 --- a/toxcore/events/conference_peer_list_changed.c +++ b/toxcore/events/conference_peer_list_changed.c @@ -6,7 +6,6 @@ #include #include -#include #include "../bin_pack.h" #include "../bin_unpack.h" diff --git a/toxcore/events/events_alloc.c b/toxcore/events/events_alloc.c index f661c5c0..b768eab5 100644 --- a/toxcore/events/events_alloc.c +++ b/toxcore/events/events_alloc.c @@ -8,6 +8,7 @@ #include #include "../ccompat.h" +#include "../tox_events.h" Tox_Events_State *tox_events_alloc(void *user_data) { diff --git a/toxcore/events/file_chunk_request.c b/toxcore/events/file_chunk_request.c index b7c3042f..4f4deafc 100644 --- a/toxcore/events/file_chunk_request.c +++ b/toxcore/events/file_chunk_request.c @@ -6,7 +6,6 @@ #include #include -#include #include "../bin_pack.h" #include "../bin_unpack.h" diff --git a/toxcore/events/file_recv_control.c b/toxcore/events/file_recv_control.c index a504d4b4..21ef33f5 100644 --- a/toxcore/events/file_recv_control.c +++ b/toxcore/events/file_recv_control.c @@ -6,7 +6,6 @@ #include #include -#include #include "../bin_pack.h" #include "../bin_unpack.h" diff --git a/toxcore/events/friend_connection_status.c b/toxcore/events/friend_connection_status.c index 82daa432..4341f72d 100644 --- a/toxcore/events/friend_connection_status.c +++ b/toxcore/events/friend_connection_status.c @@ -6,7 +6,6 @@ #include #include -#include #include "../bin_pack.h" #include "../bin_unpack.h" diff --git a/toxcore/events/friend_read_receipt.c b/toxcore/events/friend_read_receipt.c index dee1aa47..0a8cddb4 100644 --- a/toxcore/events/friend_read_receipt.c +++ b/toxcore/events/friend_read_receipt.c @@ -6,7 +6,6 @@ #include #include -#include #include "../bin_pack.h" #include "../bin_unpack.h" diff --git a/toxcore/events/friend_status.c b/toxcore/events/friend_status.c index 4208df47..3c2a5573 100644 --- a/toxcore/events/friend_status.c +++ b/toxcore/events/friend_status.c @@ -6,7 +6,6 @@ #include #include -#include #include "../bin_pack.h" #include "../bin_unpack.h" diff --git a/toxcore/events/friend_typing.c b/toxcore/events/friend_typing.c index 4a05abc1..64e494d7 100644 --- a/toxcore/events/friend_typing.c +++ b/toxcore/events/friend_typing.c @@ -6,7 +6,6 @@ #include #include -#include #include "../bin_pack.h" #include "../bin_unpack.h" diff --git a/toxcore/events/self_connection_status.c b/toxcore/events/self_connection_status.c index b390bec3..097319e9 100644 --- a/toxcore/events/self_connection_status.c +++ b/toxcore/events/self_connection_status.c @@ -6,7 +6,6 @@ #include #include -#include #include "../bin_pack.h" #include "../bin_unpack.h" diff --git a/toxcore/forwarding.c b/toxcore/forwarding.c index be96a21d..37a0f841 100644 --- a/toxcore/forwarding.c +++ b/toxcore/forwarding.c @@ -10,6 +10,10 @@ #include "DHT.h" #include "ccompat.h" +#include "crypto_core.h" +#include "logger.h" +#include "mono_time.h" +#include "network.h" #include "timed_auth.h" struct Forwarding { diff --git a/toxcore/friend_connection.c b/toxcore/friend_connection.c index 2326560c..23251bda 100644 --- a/toxcore/friend_connection.c +++ b/toxcore/friend_connection.c @@ -11,9 +11,16 @@ #include #include +#include "DHT.h" +#include "LAN_discovery.h" +#include "TCP_connection.h" #include "ccompat.h" +#include "crypto_core.h" +#include "logger.h" #include "mono_time.h" -#include "util.h" +#include "net_crypto.h" +#include "network.h" +#include "onion_client.h" #define PORTS_PER_DISCOVERY 10 diff --git a/toxcore/friend_requests.c b/toxcore/friend_requests.c index 7f18b1ff..c780f3e3 100644 --- a/toxcore/friend_requests.c +++ b/toxcore/friend_requests.c @@ -12,7 +12,9 @@ #include #include "ccompat.h" -#include "util.h" +#include "crypto_core.h" +#include "friend_connection.h" +#include "onion_client.h" /** * NOTE: The following is just a temporary fix for the multiple friend requests received at the same time problem. diff --git a/toxcore/group.c b/toxcore/group.c index 57a81ef2..0086a17e 100644 --- a/toxcore/group.c +++ b/toxcore/group.c @@ -12,8 +12,16 @@ #include #include +#include "DHT.h" +#include "Messenger.h" #include "ccompat.h" +#include "crypto_core.h" +#include "friend_connection.h" +#include "group_common.h" +#include "logger.h" #include "mono_time.h" +#include "net_crypto.h" +#include "network.h" #include "state.h" #include "util.h" diff --git a/toxcore/group_announce.c b/toxcore/group_announce.c index 896b043d..3308ecbd 100644 --- a/toxcore/group_announce.c +++ b/toxcore/group_announce.c @@ -8,10 +8,11 @@ #include #include -#include "LAN_discovery.h" +#include "DHT.h" #include "ccompat.h" +#include "logger.h" #include "mono_time.h" -#include "util.h" +#include "network.h" /** * Removes `announces` from `gc_announces_list`. diff --git a/toxcore/group_chats.c b/toxcore/group_chats.c index 901c73d5..e8f21371 100644 --- a/toxcore/group_chats.c +++ b/toxcore/group_chats.c @@ -9,23 +9,31 @@ #include "group_chats.h" -#include - #include +#include +#include #include #include "DHT.h" -#include "LAN_discovery.h" #include "Messenger.h" #include "TCP_connection.h" +#include "bin_pack.h" +#include "bin_unpack.h" #include "ccompat.h" +#include "crypto_core.h" #include "friend_connection.h" +#include "group_announce.h" #include "group_common.h" +#include "group_connection.h" #include "group_moderation.h" #include "group_pack.h" +#include "logger.h" #include "mono_time.h" +#include "net_crypto.h" #include "network.h" +#include "onion_announce.h" +#include "onion_client.h" #include "util.h" /* The minimum size of a plaintext group handshake packet */ @@ -1374,7 +1382,7 @@ static int make_gc_shared_state_packet(const GC_Chat *chat, uint8_t *data, uint1 return -1; } - return (int)(header_len + packed_len); + return header_len + packed_len; } /** @brief Creates a signature for the group's shared state in packed form. @@ -3241,7 +3249,7 @@ static int make_gc_sanctions_list_packet(const GC_Chat *chat, uint8_t *data, uin return -1; } - return (int)(length + packed_len); + return length + packed_len; } /** @brief Sends the sanctions list to peer. diff --git a/toxcore/group_connection.c b/toxcore/group_connection.c index 9d919361..2a8045a8 100644 --- a/toxcore/group_connection.c +++ b/toxcore/group_connection.c @@ -15,11 +15,14 @@ #include #include "DHT.h" +#include "TCP_connection.h" #include "ccompat.h" #include "crypto_core.h" #include "group_chats.h" #include "group_common.h" +#include "logger.h" #include "mono_time.h" +#include "network.h" #include "util.h" /** Seconds since last direct UDP packet was received before the connection is considered dead */ diff --git a/toxcore/group_moderation.c b/toxcore/group_moderation.c index eeed26d0..90a95e17 100644 --- a/toxcore/group_moderation.c +++ b/toxcore/group_moderation.c @@ -15,9 +15,10 @@ #include #include +#include "DHT.h" #include "ccompat.h" #include "crypto_core.h" -#include "mono_time.h" +#include "logger.h" #include "network.h" #include "util.h" @@ -305,7 +306,7 @@ int sanctions_list_pack(uint8_t *data, uint16_t length, const Mod_Sanction *sanc return -1; } - return (int)(packed_len + cred_len); + return packed_len + cred_len; } uint16_t sanctions_creds_unpack(Mod_Sanction_Creds *creds, const uint8_t *data) @@ -457,7 +458,7 @@ static bool sanctions_list_validate_entry(const Moderation *moderation, const Mo uint8_t packed_data[MOD_SANCTION_PACKED_SIZE]; const int packed_len = sanctions_list_pack(packed_data, sizeof(packed_data), sanction, 1, nullptr); - if (packed_len <= (int) SIGNATURE_SIZE) { + if (packed_len <= SIGNATURE_SIZE) { return false; } @@ -785,7 +786,7 @@ static bool sanctions_list_sign_entry(const Moderation *moderation, Mod_Sanction uint8_t packed_data[MOD_SANCTION_PACKED_SIZE]; const int packed_len = sanctions_list_pack(packed_data, sizeof(packed_data), sanction, 1, nullptr); - if (packed_len <= (int) SIGNATURE_SIZE) { + if (packed_len <= SIGNATURE_SIZE) { LOGGER_ERROR(moderation->log, "Failed to pack sanctions list: %d", packed_len); return false; } diff --git a/toxcore/group_onion_announce.c b/toxcore/group_onion_announce.c index 7efb4af6..16368e5c 100644 --- a/toxcore/group_onion_announce.c +++ b/toxcore/group_onion_announce.c @@ -9,6 +9,12 @@ #include #include "ccompat.h" +#include "crypto_core.h" +#include "group_announce.h" +#include "logger.h" +#include "mono_time.h" +#include "network.h" +#include "onion_announce.h" static_assert(GCA_ANNOUNCE_MAX_SIZE <= ONION_MAX_EXTRA_DATA_SIZE, "GC_Announce does not fit into the onion packet extra data"); diff --git a/toxcore/group_pack.c b/toxcore/group_pack.c index c681d821..f0351650 100644 --- a/toxcore/group_pack.c +++ b/toxcore/group_pack.c @@ -13,9 +13,13 @@ #include #include +#include "DHT.h" #include "bin_pack.h" #include "bin_unpack.h" #include "ccompat.h" +#include "group_common.h" +#include "group_moderation.h" +#include "logger.h" #include "util.h" bool group_privacy_state_from_int(uint8_t value, Group_Privacy_State *out) @@ -428,7 +432,7 @@ static void save_pack_self_info(const GC_Chat *chat, Bin_Pack *bp) bin_pack_u16(bp, self->nick_length); // 1 bin_pack_u08(bp, (uint8_t)self->role); // 2 - bin_pack_u08(bp, (uint8_t)self->status); // 3 + bin_pack_u08(bp, self->status); // 3 bin_pack_bin(bp, self->nick, self->nick_length); // 4 } diff --git a/toxcore/logger.c b/toxcore/logger.c index 6c532623..468e9ad5 100644 --- a/toxcore/logger.c +++ b/toxcore/logger.c @@ -8,7 +8,6 @@ */ #include "logger.h" -#include #include #include #include diff --git a/toxcore/mono_time.c b/toxcore/mono_time.c index 7076cb07..6603c62b 100644 --- a/toxcore/mono_time.c +++ b/toxcore/mono_time.c @@ -26,12 +26,14 @@ #include #endif +#ifdef FUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION #include +#endif #include -#include #include #include "ccompat.h" +#include "mem.h" #include "util.h" /** don't call into system billions of times for no reason */ diff --git a/toxcore/net_crypto.c b/toxcore/net_crypto.c index cf11ef15..52bc2e84 100644 --- a/toxcore/net_crypto.c +++ b/toxcore/net_crypto.c @@ -10,13 +10,19 @@ */ #include "net_crypto.h" -#include -#include #include +#include "DHT.h" +#include "LAN_discovery.h" +#include "TCP_client.h" +#include "TCP_connection.h" #include "ccompat.h" +#include "crypto_core.h" #include "list.h" +#include "logger.h" +#include "mem.h" #include "mono_time.h" +#include "network.h" #include "util.h" typedef struct Packet_Data { diff --git a/toxcore/network.c b/toxcore/network.c index 726a3410..83386324 100644 --- a/toxcore/network.c +++ b/toxcore/network.c @@ -89,7 +89,7 @@ #include "ccompat.h" #include "logger.h" -#include "mono_time.h" +#include "mem.h" #include "util.h" // Disable MSG_NOSIGNAL on systems not supporting it, e.g. Windows, FreeBSD @@ -366,7 +366,11 @@ IP6 get_ip6_loopback(void) #define INVALID_SOCKET (-1) #endif -const Socket net_invalid_socket = { (int)INVALID_SOCKET }; +Socket net_invalid_socket(void) +{ + const Socket invalid_socket = { (int)INVALID_SOCKET }; + return invalid_socket; +} Family net_family_unspec(void) { @@ -460,7 +464,8 @@ bool net_family_is_tox_tcp_ipv6(Family family) bool sock_valid(Socket sock) { - return sock.sock != net_invalid_socket.sock; + const Socket invalid_socket = net_invalid_socket(); + return sock.sock != invalid_socket.sock; } struct Network_Addr { diff --git a/toxcore/network.h b/toxcore/network.h index d6056764..dbef9bc8 100644 --- a/toxcore/network.h +++ b/toxcore/network.h @@ -226,7 +226,7 @@ Socket net_socket(const Network *ns, Family domain, int type, int protocol); */ bool sock_valid(Socket sock); -extern const Socket net_invalid_socket; +Socket net_invalid_socket(void); /** * Calls send(sockfd, buf, len, MSG_NOSIGNAL). diff --git a/toxcore/onion.c b/toxcore/onion.c index 3e515752..ae201cf7 100644 --- a/toxcore/onion.c +++ b/toxcore/onion.c @@ -9,12 +9,16 @@ #include "onion.h" #include -#include #include +#include "DHT.h" #include "ccompat.h" +#include "crypto_core.h" +#include "logger.h" +#include "mem.h" #include "mono_time.h" -#include "util.h" +#include "network.h" +#include "shared_key_cache.h" #define RETURN_1 ONION_RETURN_1 #define RETURN_2 ONION_RETURN_2 diff --git a/toxcore/onion_announce.c b/toxcore/onion_announce.c index ffe368e3..fe489c37 100644 --- a/toxcore/onion_announce.c +++ b/toxcore/onion_announce.c @@ -15,9 +15,14 @@ #include "DHT.h" #include "LAN_discovery.h" #include "ccompat.h" +#include "crypto_core.h" +#include "logger.h" +#include "mem.h" #include "mono_time.h" +#include "network.h" +#include "onion.h" #include "shared_key_cache.h" -#include "util.h" +#include "timed_auth.h" #define PING_ID_TIMEOUT ONION_ANNOUNCE_TIMEOUT diff --git a/toxcore/onion_client.c b/toxcore/onion_client.c index 53718ffc..56441ce1 100644 --- a/toxcore/onion_client.c +++ b/toxcore/onion_client.c @@ -13,10 +13,20 @@ #include #include +#include "DHT.h" #include "LAN_discovery.h" +#include "TCP_connection.h" #include "ccompat.h" +#include "crypto_core.h" #include "group_onion_announce.h" +#include "logger.h" +#include "mem.h" #include "mono_time.h" +#include "net_crypto.h" +#include "network.h" +#include "onion.h" +#include "onion_announce.h" +#include "ping_array.h" #include "util.h" /** @brief defines for the array size and timeout for onion announce packets. */ diff --git a/toxcore/ping.c b/toxcore/ping.c index f8a96edf..dc7658a2 100644 --- a/toxcore/ping.c +++ b/toxcore/ping.c @@ -9,15 +9,15 @@ */ #include "ping.h" -#include #include #include "DHT.h" #include "ccompat.h" +#include "crypto_core.h" +#include "mem.h" #include "mono_time.h" #include "network.h" #include "ping_array.h" -#include "util.h" #define PING_NUM_MAX 512 diff --git a/toxcore/ping_array.c b/toxcore/ping_array.c index f303d802..7c0ce87e 100644 --- a/toxcore/ping_array.c +++ b/toxcore/ping_array.c @@ -8,13 +8,12 @@ */ #include "ping_array.h" -#include #include #include "ccompat.h" #include "crypto_core.h" +#include "mem.h" #include "mono_time.h" -#include "util.h" typedef struct Ping_Array_Entry { uint8_t *data; diff --git a/toxcore/shared_key_cache.c b/toxcore/shared_key_cache.c index 0adc1e82..8f8f6c1b 100644 --- a/toxcore/shared_key_cache.c +++ b/toxcore/shared_key_cache.c @@ -4,12 +4,13 @@ #include "shared_key_cache.h" -#include #include #include // memcpy(...) #include "ccompat.h" #include "crypto_core.h" +#include "logger.h" +#include "mem.h" #include "mono_time.h" typedef struct Shared_Key { diff --git a/toxcore/state.c b/toxcore/state.c index e4f769ad..69f11f3c 100644 --- a/toxcore/state.c +++ b/toxcore/state.c @@ -7,6 +7,7 @@ #include #include "ccompat.h" +#include "logger.h" /** state load/save */ int state_load(const Logger *log, state_load_cb *state_load_callback, void *outer, diff --git a/toxcore/timed_auth.c b/toxcore/timed_auth.c index ebd51002..a52f9d9a 100644 --- a/toxcore/timed_auth.c +++ b/toxcore/timed_auth.c @@ -6,6 +6,8 @@ #include #include "ccompat.h" +#include "crypto_core.h" +#include "mono_time.h" non_null(1,6) nullable(4) static void create_timed_auth_to_hash(const Mono_Time *mono_time, uint16_t timeout, bool previous, const uint8_t *data, diff --git a/toxcore/tox.c b/toxcore/tox.c index 290f6bb8..15ae2369 100644 --- a/toxcore/tox.c +++ b/toxcore/tox.c @@ -13,18 +13,24 @@ #include "tox.h" #include -#include #include +#include "DHT.h" #include "Messenger.h" +#include "TCP_client.h" #include "ccompat.h" +#include "crypto_core.h" +#include "friend_requests.h" #include "group.h" #include "group_chats.h" -#include "group_moderation.h" +#include "group_common.h" #include "logger.h" #include "mem.h" #include "mono_time.h" +#include "net_crypto.h" #include "network.h" +#include "onion_client.h" +#include "state.h" #include "tox_private.h" #include "tox_struct.h" diff --git a/toxcore/tox_api.c b/toxcore/tox_api.c index 9b3a888d..02bb8e15 100644 --- a/toxcore/tox_api.c +++ b/toxcore/tox_api.c @@ -4,7 +4,6 @@ #include "tox.h" #include -#include #include "ccompat.h" #include "tox_private.h" diff --git a/toxcore/tox_dispatch.c b/toxcore/tox_dispatch.c index 54278514..25dafdcb 100644 --- a/toxcore/tox_dispatch.c +++ b/toxcore/tox_dispatch.c @@ -7,6 +7,8 @@ #include #include "ccompat.h" +#include "tox.h" +#include "tox_events.h" struct Tox_Dispatch { tox_events_conference_connected_cb *conference_connected_callback; diff --git a/toxcore/tox_events.c b/toxcore/tox_events.c index 1676743b..40bfcea0 100644 --- a/toxcore/tox_events.c +++ b/toxcore/tox_events.c @@ -5,16 +5,16 @@ #include "tox_events.h" #include -#include -#include #include +#include "bin_pack.h" #include "bin_unpack.h" #include "ccompat.h" #include "events/events_alloc.h" +#include "logger.h" #include "mem.h" #include "tox.h" -#include "tox_private.h" +#include "tox_struct.h" /***************************************************** diff --git a/toxcore/tox_private.c b/toxcore/tox_private.c index abe09d6b..11526f95 100644 --- a/toxcore/tox_private.c +++ b/toxcore/tox_private.c @@ -10,10 +10,15 @@ #include +#include "DHT.h" #include "ccompat.h" +#include "crypto_core.h" #include "group_chats.h" +#include "group_common.h" #include "mem.h" +#include "net_crypto.h" #include "network.h" +#include "tox.h" #include "tox_struct.h" #define SET_ERROR_PARAMETER(param, x) \ diff --git a/toxcore/tox_unpack.c b/toxcore/tox_unpack.c index 9d58879a..35bffb10 100644 --- a/toxcore/tox_unpack.c +++ b/toxcore/tox_unpack.c @@ -7,7 +7,7 @@ #include #include "bin_unpack.h" -#include "ccompat.h" +#include "tox.h" non_null() static bool tox_conference_type_from_int(uint32_t value, Tox_Conference_Type *out) diff --git a/toxcore/util.c b/toxcore/util.c index 507524df..a84d181b 100644 --- a/toxcore/util.c +++ b/toxcore/util.c @@ -13,11 +13,10 @@ #include "util.h" -#include #include -#include #include "ccompat.h" +#include "mem.h" bool is_power_of_2(uint64_t x) {