From f627a26a7b1c3619ba66f84b87092ff8ba7a95b6 Mon Sep 17 00:00:00 2001 From: iphydf Date: Tue, 17 Jul 2018 01:18:04 +0000 Subject: Run Clang global static analysis on Travis. This uses a single .cc file containing almost all the code in the repository to perform whole program analysis. --- other/BUILD.bazel | 12 --- other/analysis/gen-file.sh | 116 ++++++++++++++++++---------- other/analysis/run-clang | 22 +++++- other/analysis/run-clang-analyze | 8 ++ other/analysis/run-cppcheck | 4 +- other/analysis/run-gcc | 23 ++---- other/analysis/run-infer | 4 +- other/analysis/run-sparse | 9 --- other/bootstrap_daemon/src/config.c | 4 +- other/bootstrap_daemon/src/tox-bootstrapd.c | 2 + other/cpufeatures.c | 2 +- other/fun/cracker.c | 2 +- other/fun/sign.c | 15 ++-- other/fun/strkey.c | 2 +- other/monolith.h | 38 --------- 15 files changed, 124 insertions(+), 139 deletions(-) create mode 100755 other/analysis/run-clang-analyze delete mode 100755 other/analysis/run-sparse delete mode 100644 other/monolith.h (limited to 'other') diff --git a/other/BUILD.bazel b/other/BUILD.bazel index 8bcdc4b4..d0fcf850 100644 --- a/other/BUILD.bazel +++ b/other/BUILD.bazel @@ -1,17 +1,5 @@ load("//tools:no_undefined.bzl", "cc_library") -cc_library( - name = "monolith", - hdrs = ["monolith.h"], - visibility = ["//c-toxcore/auto_tests:__pkg__"], - deps = [ - "//c-toxcore/testing:monolith", - "//c-toxcore/toxav:monolith", - "//c-toxcore/toxcore:monolith", - "//c-toxcore/toxencryptsave:monolith", - ], -) - cc_library( name = "bootstrap_node_packets", srcs = ["bootstrap_node_packets.c"], diff --git a/other/analysis/gen-file.sh b/other/analysis/gen-file.sh index 710e20d7..89144eff 100644 --- a/other/analysis/gen-file.sh +++ b/other/analysis/gen-file.sh @@ -1,48 +1,80 @@ -CPPFLAGS="-DMIN_LOGGER_LEVEL=LOG_TRACE -Iauto_tests -Itoxcore -Itoxav -Itoxencryptsave `pkg-config --cflags libsodium opus vpx`" +#!/bin/sh + +CPPFLAGS="$CPPFLAGS -DMIN_LOGGER_LEVEL=LOGGER_LEVEL_TRACE" +CPPFLAGS="$CPPFLAGS -isystem /usr/include/opus" +CPPFLAGS="$CPPFLAGS -Iauto_tests" +CPPFLAGS="$CPPFLAGS -Iother" +CPPFLAGS="$CPPFLAGS -Iother/bootstrap_daemon/src" +CPPFLAGS="$CPPFLAGS -Iother/fun" +CPPFLAGS="$CPPFLAGS -Itesting" +CPPFLAGS="$CPPFLAGS -Itoxcore" +CPPFLAGS="$CPPFLAGS -Itoxav" +CPPFLAGS="$CPPFLAGS -Itoxencryptsave" + +LDFLAGS="$LDFLAGS -lopus -lsodium -lvpx -lpthread -lconfig" put() { if [ "$SKIP_LINES" = "" ]; then - echo "#line 1 \"$1\"" >> test.c + echo "#line 1 \"$1\"" >> amalgamation.cc + fi + cat $1 >> amalgamation.cc +} + +putmain() { + echo "namespace $(echo $1 | sed -e 's/[^a-zA-Z0-9_]/_/g') {" >> amalgamation.cc + if [ "$SKIP_LINES" = "" ]; then + echo "#line 1 \"$1\"" >> amalgamation.cc fi - cat $1 >> test.c + sed -e 's/^int main(/static &/' $1 >> amalgamation.cc + echo "} // namespace $(echo $1 | sed -e 's/[^a-zA-Z0-9_]/_/g')" >> amalgamation.cc +} + +callmain() { + echo " call($(echo $1 | sed -e 's/[^a-zA-Z0-9_]/_/g')::main, argc, argv);" >> amalgamation.cc } -:> test.c - -put toxcore/tox.c - -put toxcore/DHT.c -put toxcore/LAN_discovery.c -put toxcore/Messenger.c -put toxcore/TCP_client.c -put toxcore/TCP_connection.c -put toxcore/TCP_server.c -put toxcore/crypto_core.c -put toxcore/crypto_core_mem.c -put toxcore/friend_connection.c -put toxcore/friend_requests.c -put toxcore/group.c -put toxcore/list.c -put toxcore/logger.c -put toxcore/network.c -put toxcore/net_crypto.c -put toxcore/onion.c -put toxcore/onion_announce.c -put toxcore/onion_client.c -put toxcore/ping.c -put toxcore/ping_array.c -put toxcore/tox_api.c -put toxcore/util.c - -# Not included yet, since there are too many issues with this code. -#put toxav/audio.c -#put toxav/bwcontroller.c -#put toxav/groupav.c -#put toxav/msi.c -#put toxav/ring_buffer.c -#put toxav/rtp.c -#put toxav/toxav.c -#put toxav/toxav_old.c -#put toxav/video.c - -put toxencryptsave/toxencryptsave.c +:> amalgamation.cc + +echo "#include " >> amalgamation.cc +echo "#include " >> amalgamation.cc +echo "#include " >> amalgamation.cc +echo "#include " >> amalgamation.cc + +echo "#define TOX_DEFINED" >> amalgamation.cc +echo "typedef struct Messenger Tox;" >> amalgamation.cc + +put auto_tests/check_compat.h + +FIND_QUERY="find . '-(' -name '*.cc' -or -name '*.c' '-)'" +FIND_QUERY="$FIND_QUERY -and -not -wholename './super_donators/*'" +FIND_QUERY="$FIND_QUERY -and -not -wholename './toxav/*.cc'" +FIND_QUERY="$FIND_QUERY -and -not -wholename './toxcore/*.cc'" +FIND_QUERY="$FIND_QUERY -and -not -wholename './toxencryptsave/*.cc'" +FIND_QUERY="$FIND_QUERY -and -not -name amalgamation.cc" +FIND_QUERY="$FIND_QUERY -and -not -name av_test.c" +FIND_QUERY="$FIND_QUERY -and -not -name dht_test.c" +FIND_QUERY="$FIND_QUERY -and -not -name version_test.c" + +for i in $(eval $FIND_QUERY); do + if ! grep -q '^int main(' $i; then + put $i + fi +done + +for i in $(eval $FIND_QUERY); do + if grep -q '^int main(' $i; then + putmain $i + fi +done + +echo "static void call(int m(), int argc, char **argv) { m(); }" >> amalgamation.cc +echo "static void call(int m(int, char **), int argc, char **argv) { m(argc, argv); }" >> amalgamation.cc + +echo "int main(int argc, char **argv) {" >> amalgamation.cc +for i in $(eval $FIND_QUERY); do + if grep -q '^int main(' $i; then + callmain $i + fi +done +echo " return 0;" >> amalgamation.cc +echo "}" >> amalgamation.cc diff --git a/other/analysis/run-clang b/other/analysis/run-clang index 1c8da7ea..60e59eab 100755 --- a/other/analysis/run-clang +++ b/other/analysis/run-clang @@ -2,6 +2,22 @@ . other/analysis/gen-file.sh -put auto_tests/lan_discovery_test.c - -clang --analyze test.c $CPPFLAGS +echo "Running Clang compiler" +clang++ -o /dev/null amalgamation.cc \ + $CPPFLAGS \ + $LDFLAGS \ + -std=c++11 \ + -Weverything \ + -Wno-c++98-compat-pedantic \ + -Wno-c99-extensions \ + -Wno-cast-align \ + -Wno-conversion \ + -Wno-covered-switch-default \ + -Wno-documentation-deprecated-sync \ + -Wno-missing-field-initializers \ + -Wno-old-style-cast \ + -Wno-padded \ + -Wno-sign-compare \ + -Wno-unreachable-code-return \ + -Wno-unused-parameter \ + -Wno-used-but-marked-unused \ diff --git a/other/analysis/run-clang-analyze b/other/analysis/run-clang-analyze new file mode 100755 index 00000000..0e6d9af0 --- /dev/null +++ b/other/analysis/run-clang-analyze @@ -0,0 +1,8 @@ +#!/bin/sh + +. other/analysis/gen-file.sh + +echo "Running Clang static analyzer" +clang++ --analyze amalgamation.cc \ + $CPPFLAGS \ + -std=c++11 diff --git a/other/analysis/run-cppcheck b/other/analysis/run-cppcheck index 9e928c9a..dc369840 100755 --- a/other/analysis/run-cppcheck +++ b/other/analysis/run-cppcheck @@ -2,6 +2,4 @@ . other/analysis/gen-file.sh -put auto_tests/lan_discovery_test.c - -cppcheck test.c $CPPFLAGS +cppcheck amalgamation.cc $CPPFLAGS diff --git a/other/analysis/run-gcc b/other/analysis/run-gcc index ffd42f4e..3ea32782 100755 --- a/other/analysis/run-gcc +++ b/other/analysis/run-gcc @@ -2,12 +2,14 @@ . other/analysis/gen-file.sh -put auto_tests/lan_discovery_test.c - +echo "Running GCC" # TODO(iphydf): Get rid of all VLAs, then enable -fstack-protector -Wstack-protector -gcc -O3 -c -o /dev/null test.c $CPPFLAGS \ - -std=c99 \ +g++ -O3 -o /dev/null amalgamation.cc \ + $CPPFLAGS \ + $LDFLAGS \ + -std=c++11 \ -pedantic \ + -fdiagnostics-color=always \ -Wall \ -Wextra \ -Wno-aggregate-return \ @@ -22,18 +24,9 @@ gcc -O3 -c -o /dev/null test.c $CPPFLAGS \ -Wno-unused-parameter \ -Wstrict-aliasing=0 \ -Wstrict-overflow=1 \ - \ - -Wbad-function-cast \ + \ -Wmissing-declarations \ - -Wmissing-parameter-type \ - -Wmissing-prototypes \ - -Wnested-externs \ - -Wold-style-declaration \ - -Wold-style-definition \ - -Wstrict-prototypes \ -Wbool-compare \ - -Wc99-c11-compat \ - -Wc++-compat \ -Wcast-align \ -Wcast-qual \ -Wchar-subscripts \ @@ -45,10 +38,8 @@ gcc -O3 -c -o /dev/null test.c $CPPFLAGS \ -Wformat=2 \ -Wframe-address \ -Wframe-larger-than=133168 \ - -Wjump-misses-init \ -Wignored-qualifiers \ -Wignored-attributes \ - -Wincompatible-pointer-types \ -Winit-self \ -Winline \ -Wlarger-than=133120 \ diff --git a/other/analysis/run-infer b/other/analysis/run-infer index 942d0cfd..2a897227 100755 --- a/other/analysis/run-infer +++ b/other/analysis/run-infer @@ -5,6 +5,4 @@ SKIP_LINES=1 . other/analysis/gen-file.sh -put auto_tests/lan_discovery_test.c - -infer -- clang -fsyntax-only test.c $CPPFLAGS +infer -- clang++ -fsyntax-only amalgamation.cc $CPPFLAGS diff --git a/other/analysis/run-sparse b/other/analysis/run-sparse deleted file mode 100755 index b4d0f736..00000000 --- a/other/analysis/run-sparse +++ /dev/null @@ -1,9 +0,0 @@ -#!/bin/sh - -. other/analysis/gen-file.sh - -put auto_tests/lan_discovery_test.c - -sparse test.c $CPPFLAGS \ - -Wsparse-all \ - -Wno-declaration-after-statement diff --git a/other/bootstrap_daemon/src/config.c b/other/bootstrap_daemon/src/config.c index 9fde33b2..0a7f566b 100644 --- a/other/bootstrap_daemon/src/config.c +++ b/other/bootstrap_daemon/src/config.c @@ -303,7 +303,7 @@ int get_general_config(const char *cfg_file_path, char **pid_file_path, char **k * @return binary on success, * NULL on failure. */ -static uint8_t *hex_string_to_bin(const char *hex_string) +static uint8_t *bootstrap_hex_string_to_bin(const char *hex_string) { if (strlen(hex_string) % 2 != 0) { return nullptr; @@ -407,7 +407,7 @@ int bootstrap_from_config(const char *cfg_file_path, DHT *dht, int enable_ipv6) goto next; } - bs_public_key_bin = hex_string_to_bin(bs_public_key); + bs_public_key_bin = bootstrap_hex_string_to_bin(bs_public_key); address_resolved = dht_bootstrap_from_address(dht, bs_address, enable_ipv6, net_htons(bs_port), bs_public_key_bin); free(bs_public_key_bin); diff --git a/other/bootstrap_daemon/src/tox-bootstrapd.c b/other/bootstrap_daemon/src/tox-bootstrapd.c index fd05f8a2..b17fc2ba 100644 --- a/other/bootstrap_daemon/src/tox-bootstrapd.c +++ b/other/bootstrap_daemon/src/tox-bootstrapd.c @@ -22,7 +22,9 @@ * You should have received a copy of the GNU General Public License * along with Tox. If not, see . */ +#ifndef _XOPEN_SOURCE #define _XOPEN_SOURCE 600 +#endif // system provided #include diff --git a/other/cpufeatures.c b/other/cpufeatures.c index e52a90ff..3da06e58 100644 --- a/other/cpufeatures.c +++ b/other/cpufeatures.c @@ -1,5 +1,5 @@ -#define typeof __typeof__ #ifdef ANDROID_CPU_FEATURES +#define typeof __typeof__ #include ANDROID_CPU_FEATURES #endif diff --git a/other/fun/cracker.c b/other/fun/cracker.c index 502a8af0..fd9564f6 100644 --- a/other/fun/cracker.c +++ b/other/fun/cracker.c @@ -20,7 +20,7 @@ #include "../../testing/misc_tools.h" #include "../../toxcore/ccompat.h" -void print_key(uint8_t *client_id) +static void print_key(uint8_t *client_id) { uint32_t j; diff --git a/other/fun/sign.c b/other/fun/sign.c index 007d19a0..547af311 100644 --- a/other/fun/sign.c +++ b/other/fun/sign.c @@ -21,7 +21,7 @@ #include "../../testing/misc_tools.h" // hex_string_to_bin #include "../../toxcore/ccompat.h" -int load_file(char *filename, char **result) +static int load_file(char *filename, unsigned char **result) { int size = 0; FILE *f = fopen(filename, "rb"); @@ -34,7 +34,7 @@ int load_file(char *filename, char **result) fseek(f, 0, SEEK_END); size = ftell(f); fseek(f, 0, SEEK_SET); - *result = (char *)malloc(size + 1); + *result = (unsigned char *)malloc(size + 1); if (size != fread(*result, sizeof(char), size, f)) { free(*result); @@ -72,7 +72,7 @@ int main(int argc, char *argv[]) if (argc == 5 && argv[1][0] == 's') { unsigned char *secret_key = hex_string_to_bin(argv[2]); - char *data; + unsigned char *data; int size = load_file(argv[3], &data); if (size < 0) { @@ -80,7 +80,7 @@ int main(int argc, char *argv[]) } unsigned long long smlen; - char *sm = malloc(size + crypto_sign_ed25519_BYTES * 2); + unsigned char *sm = (unsigned char *)malloc(size + crypto_sign_ed25519_BYTES * 2); crypto_sign_ed25519(sm, &smlen, data, size, secret_key); free(secret_key); @@ -106,19 +106,18 @@ int main(int argc, char *argv[]) if (argc == 4 && argv[1][0] == 'c') { unsigned char *public_key = hex_string_to_bin(argv[2]); - char *data; + unsigned char *data; int size = load_file(argv[3], &data); if (size < 0) { goto fail; } - char *signe = malloc(size + crypto_sign_ed25519_BYTES); + unsigned char *signe = (unsigned char *)malloc(size + crypto_sign_ed25519_BYTES); memcpy(signe, data + size - crypto_sign_ed25519_BYTES, crypto_sign_ed25519_BYTES); // Move signature from end to beginning of file. memcpy(signe + crypto_sign_ed25519_BYTES, data, size - crypto_sign_ed25519_BYTES); - unsigned long long smlen; - char *m = malloc(size); + unsigned char *m = (unsigned char *)malloc(size); unsigned long long mlen; if (crypto_sign_ed25519_open(m, &mlen, signe, size, public_key) == -1) { diff --git a/other/fun/strkey.c b/other/fun/strkey.c index ef54a404..d769318a 100644 --- a/other/fun/strkey.c +++ b/other/fun/strkey.c @@ -43,7 +43,7 @@ #define PRINT_TRIES_COUNT -void print_key(unsigned char *key) +static void print_key(unsigned char *key) { size_t i; diff --git a/other/monolith.h b/other/monolith.h deleted file mode 100644 index 356252f2..00000000 --- a/other/monolith.h +++ /dev/null @@ -1,38 +0,0 @@ -#include "../toxcore/tox.c" - -#include "../toxcore/DHT.c" -#include "../toxcore/LAN_discovery.c" -#include "../toxcore/Messenger.c" -#include "../toxcore/TCP_client.c" -#include "../toxcore/TCP_connection.c" -#include "../toxcore/TCP_server.c" -#include "../toxcore/crypto_core.c" -#include "../toxcore/crypto_core_mem.c" -#include "../toxcore/friend_connection.c" -#include "../toxcore/friend_requests.c" -#include "../toxcore/group.c" -#include "../toxcore/list.c" -#include "../toxcore/logger.c" -#include "../toxcore/mono_time.c" -#include "../toxcore/network.c" -#include "../toxcore/net_crypto.c" -#include "../toxcore/onion.c" -#include "../toxcore/onion_announce.c" -#include "../toxcore/onion_client.c" -#include "../toxcore/ping.c" -#include "../toxcore/ping_array.c" -#include "../toxcore/state.c" -#include "../toxcore/tox_api.c" -#include "../toxcore/util.c" - -#include "../toxav/audio.c" -#include "../toxav/bwcontroller.c" -#include "../toxav/groupav.c" -#include "../toxav/msi.c" -#include "../toxav/ring_buffer.c" -#include "../toxav/rtp.c" -#include "../toxav/toxav.c" -#include "../toxav/toxav_old.c" -#include "../toxav/video.c" - -#include "../toxencryptsave/toxencryptsave.c" -- cgit v1.2.3