Skip to content

Commit fad6e4e

Browse files
committed
cleanup: Make all .c files include the headers they need.
1 parent ef4897a commit fad6e4e

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

65 files changed

+272
-88
lines changed

.clang-tidy

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,12 @@ CheckOptions:
3535
value: lower_case
3636

3737
- key: llvmlibc-restrict-system-libc-headers.Includes
38-
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"
38+
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"
3939
- key: hicpp-signed-bitwise.IgnorePositiveIntegerLiterals
4040
value: true
4141
- key: concurrency-mt-unsafe.FunctionSet
4242
value: posix
43+
- key: misc-include-cleaner.IgnoreHeaders
44+
value: "pthread.h;stdbool.h;stddef.h;stdint.;stdint.h;stdint...;cstdint;sodium.*;sys/.*;unistd.h;opus.*;vpx.*;attributes.h;tox_struct.h"
45+
- key: readability-function-cognitive-complexity.Threshold
46+
value: 153 # TODO(iphydf): Decrease. tox_new is the highest at the moment.

.github/settings.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,14 +27,15 @@ branches:
2727
- "ci/circleci: bazel-msan"
2828
- "ci/circleci: bazel-tsan"
2929
- "ci/circleci: clang-analyze"
30-
- "ci/circleci: clang-tidy"
3130
- "ci/circleci: cpplint"
3231
- "ci/circleci: infer"
3332
- "ci/circleci: static-analysis"
3433
- "ci/circleci: tsan"
3534
- "ci/circleci: ubsan"
3635
- "cimple"
3736
- "cimplefmt"
37+
- "clang-tidy"
38+
- "cppcheck"
3839
- "CodeFactor"
3940
- "code-review/reviewable"
4041
- "common / buildifier"

other/BUILD.bazel

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,11 @@ cc_binary(
2121
"//c-toxcore/toxcore:Messenger",
2222
"//c-toxcore/toxcore:TCP_server",
2323
"//c-toxcore/toxcore:ccompat",
24-
"//c-toxcore/toxcore:friend_requests",
2524
"//c-toxcore/toxcore:group_onion_announce",
2625
"//c-toxcore/toxcore:logger",
2726
"//c-toxcore/toxcore:mono_time",
2827
"//c-toxcore/toxcore:network",
2928
"//c-toxcore/toxcore:onion_announce",
3029
"//c-toxcore/toxcore:tox",
31-
"//c-toxcore/toxcore:util",
3230
],
3331
)

other/DHT_bootstrap.c

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,17 @@
1616
#include "../toxcore/DHT.h"
1717
#include "../toxcore/LAN_discovery.h"
1818
#include "../toxcore/ccompat.h"
19-
#include "../toxcore/friend_requests.h"
19+
#include "../toxcore/crypto_core.h"
20+
#include "../toxcore/forwarding.h"
21+
#include "../toxcore/group_announce.h"
2022
#include "../toxcore/group_onion_announce.h"
2123
#include "../toxcore/logger.h"
24+
#include "../toxcore/mem.h"
2225
#include "../toxcore/mono_time.h"
26+
#include "../toxcore/network.h"
27+
#include "../toxcore/onion.h"
28+
#include "../toxcore/onion_announce.h"
2329
#include "../toxcore/tox.h"
24-
#include "../toxcore/util.h"
2530

2631
#define TCP_RELAY_ENABLED
2732

other/analysis/run-clang-tidy

Lines changed: 45 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -8,38 +8,47 @@ ERRORS="*"
88

99
# TODO(iphydf): Fix these.
1010
ERRORS="$ERRORS,-cert-err34-c"
11-
ERRORS="$ERRORS,-cert-str34-c"
1211
ERRORS="$ERRORS,-readability-suspicious-call-argument"
1312

13+
# TODO(iphydf): Fix once cimple 0.0.19 is released.
14+
CHECKS="$CHECKS,-google-readability-casting"
15+
1416
# TODO(iphydf): Fix these.
1517
CHECKS="$CHECKS,-bugprone-switch-missing-default-case"
16-
CHECKS="$CHECKS,-misc-include-cleaner"
1718

1819
# TODO(iphydf): We might want some of these. For the ones we don't want, add a
1920
# comment explaining why not.
2021
CHECKS="$CHECKS,-clang-analyzer-optin.performance.Padding"
2122
CHECKS="$CHECKS,-hicpp-signed-bitwise"
22-
CHECKS="$CHECKS,-readability-function-cognitive-complexity"
2323

2424
# TODO(iphydf): Maybe fix these?
25-
CHECKS="$CHECKS,-bugprone-easily-swappable-parameters"
2625
CHECKS="$CHECKS,-bugprone-implicit-widening-of-multiplication-result"
2726
CHECKS="$CHECKS,-bugprone-integer-division"
28-
CHECKS="$CHECKS,-clang-analyzer-core.NullDereference"
29-
CHECKS="$CHECKS,-clang-analyzer-valist.Uninitialized"
30-
CHECKS="$CHECKS,-cppcoreguidelines-avoid-non-const-global-variables"
3127
CHECKS="$CHECKS,-misc-no-recursion"
3228

29+
# TODO(iphydf): Only happens in bootstrap_daemon. Fix it.
30+
CHECKS="$CHECKS,-cppcoreguidelines-avoid-non-const-global-variables"
31+
3332
# TODO(iphydf): Probably fix these.
3433
CHECKS="$CHECKS,-cert-err33-c"
3534
CHECKS="$CHECKS,-cppcoreguidelines-avoid-magic-numbers"
36-
CHECKS="$CHECKS,-google-readability-casting"
37-
CHECKS="$CHECKS,-modernize-macro-to-enum"
3835
CHECKS="$CHECKS,-readability-magic-numbers"
3936

37+
# TODO(iphydf): We're using a lot of macros for constants. Should we convert
38+
# all of them to enum?
39+
CHECKS="$CHECKS,-modernize-macro-to-enum"
40+
4041
# Documented disabled checks. We don't want these for sure.
4142
# =========================================================
4243

44+
# https://stackoverflow.com/questions/58672959/why-does-clang-tidy-say-vsnprintf-has-an-uninitialized-va-list-argument
45+
CHECKS="$CHECKS,-clang-analyzer-valist.Uninitialized"
46+
47+
# We pass a lot of ints around, so many function parameters are some kind of
48+
# int type that can be converted from another int type. We won't be getting
49+
# away from that anytime soon.
50+
CHECKS="$CHECKS,-bugprone-easily-swappable-parameters"
51+
4352
# Callback handlers often don't use all their parameters. There's
4453
# IgnoreVirtual, but that doesn't work for C-style callbacks.
4554
CHECKS="$CHECKS,-misc-unused-parameters"
@@ -132,27 +141,46 @@ CHECKS="$CHECKS,-misc-static-assert"
132141

133142
set -eux
134143

144+
# TODO(iphydf): Add toxav.
145+
DIRS=(
146+
other/bootstrap_daemon/src
147+
other
148+
toxcore
149+
toxcore/events
150+
toxencryptsave
151+
)
152+
153+
copy_files() {
154+
find "${DIRS[@]}" \
155+
-maxdepth 1 -type d -exec mkdir -p "$1/{}" \;
156+
find "${DIRS[@]}" \
157+
-maxdepth 1 -name "*.c" -exec cp "{}" "$1/{}" \;
158+
}
159+
135160
run() {
136161
echo "Running clang-tidy in variant '$*'"
137162
EXTRA_ARGS=("$@")
138163
for i in "${!EXTRA_ARGS[@]}"; do
139164
EXTRA_ARGS[$i]="--extra-arg=${EXTRA_ARGS[$i]}"
140165
done
141-
find \
142-
other/bootstrap_daemon/src \
143-
other \
144-
toxav \
145-
toxcore \
146-
toxcore/events \
147-
toxencryptsave \
166+
ls .clang-tidy
167+
copy_files a
168+
if ! find "${DIRS[@]}" \
148169
-maxdepth 1 -name "*.c" -print0 \
149170
| xargs -0 -n15 -P"$(nproc)" clang-tidy \
150171
-p=_build \
151172
--extra-arg=-DMIN_LOGGER_LEVEL=LOGGER_LEVEL_TRACE \
152173
"${EXTRA_ARGS[@]}" \
174+
--fix \
153175
--checks="$CHECKS" \
154176
--warnings-as-errors="$ERRORS" \
155-
--use-color
177+
--use-color; then
178+
copy_files b
179+
colordiff -ru a b
180+
rm -rf a b
181+
false
182+
fi
183+
rm -rf a
156184
}
157185

158186
cmake . -B_build -GNinja -DCMAKE_EXPORT_COMPILE_COMMANDS=ON

other/bootstrap_daemon/BUILD.bazel

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ cc_binary(
1818
"//c-toxcore/toxcore:mono_time",
1919
"//c-toxcore/toxcore:onion_announce",
2020
"//c-toxcore/toxcore:tox",
21-
"//c-toxcore/toxcore:util",
2221
"@libconfig",
2322
],
2423
)
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
793cce1916b0d406b8e337d1a5243dc71b07727974cc83a3ef39b7af6cbf6cdb /usr/local/bin/tox-bootstrapd
1+
c93d2d972558f578c6893aa12c1dafadf8b3dbb959b68c22efbfe7ad00d20f88 /usr/local/bin/tox-bootstrapd

other/bootstrap_daemon/src/command_line_arguments.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,12 @@
1010
#include "command_line_arguments.h"
1111

1212
#include "global.h"
13+
#include "log.h"
1314

1415
#include "../../../toxcore/ccompat.h"
1516

1617
#include <getopt.h>
1718

18-
#include <stdlib.h>
1919
#include <string.h>
2020

2121

other/bootstrap_daemon/src/config.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
#include "config.h"
1111

1212
#include "config_defaults.h"
13+
#include "global.h"
1314
#include "log.h"
1415

1516
#include <stdio.h>
@@ -18,6 +19,10 @@
1819

1920
#include <libconfig.h>
2021

22+
#include "../../../toxcore/DHT.h"
23+
#include "../../../toxcore/ccompat.h"
24+
#include "../../../toxcore/crypto_core.h"
25+
#include "../../../toxcore/network.h"
2126
#include "../../bootstrap_node_packets.h"
2227

2328
/**

other/bootstrap_daemon/src/log.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
* Copyright © 2015-2016 Tox project.
44
*/
55

6+
#include <stdarg.h>
7+
68
/*
79
* Tox DHT bootstrap daemon.
810
* Logging utility with support of multiple logging backends.

0 commit comments

Comments
 (0)