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.
This commit is contained in:
iphydf 2018-07-17 01:18:04 +00:00
parent 7245ac11ef
commit f627a26a7b
No known key found for this signature in database
GPG Key ID: 3855DBA2D74403C9
35 changed files with 230 additions and 531 deletions

1
.gitignore vendored
View File

@ -27,6 +27,7 @@ CTestTestfile.cmake
*.pc
# Testing
/amalgamation.*
testing/data
*~

View File

@ -37,6 +37,13 @@ travis_install() {
}
}
run_static_analysis() {
export CPPFLAGS="-isystem $CACHEDIR/include"
export LDFLAGS="-L $CACHEDIR/lib"
other/analysis/run-clang
other/analysis/run-clang-analyze
}
travis_script() {
. ".travis/flags-$CC.sh"
@ -50,6 +57,9 @@ travis_script() {
other/astyle/format-source . "$ASTYLE"
# Use () to run in a separate process so the exports are local.
(run_static_analysis)
cmake -B_build -H. \
-DCMAKE_C_FLAGS="$C_FLAGS" \
-DCMAKE_CXX_FLAGS="$CXX_FLAGS" \

View File

@ -104,7 +104,7 @@ if(TRACE)
endif()
if(MIN_LOGGER_LEVEL)
add_definitions(-DMIN_LOGGER_LEVEL=LOG_${MIN_LOGGER_LEVEL})
add_definitions(-DMIN_LOGGER_LEVEL=LOGGER_LEVEL_${MIN_LOGGER_LEVEL})
endif()
option(USE_IPV6 "Use IPv6 in tests" ON)
@ -403,14 +403,6 @@ function(auto_test target)
endif()
endfunction()
if(BUILD_TOXAV)
add_definitions(-D__STDC_LIMIT_MACROS=1)
add_executable(auto_monolith_test ${CPUFEATURES}
auto_tests/monolith_test.cc)
target_link_libraries(auto_monolith_test ${toxcore_LINK_MODULES})
add_test(NAME monolith COMMAND ${CROSSCOMPILING_EMULATOR} auto_monolith_test)
endif()
auto_test(TCP)
auto_test(bootstrap)
auto_test(conference)

View File

@ -25,32 +25,10 @@ test_sizes = {
deps = [
":check_compat",
":run_auto_test",
"//c-toxcore/other:monolith",
"//c-toxcore/testing:misc_tools",
"//c-toxcore/toxav",
"//c-toxcore/toxcore",
"//c-toxcore/toxcore:DHT_srcs",
"//c-toxcore/toxencryptsave",
],
) for src in glob(["*_test.c"])]
cc_library(
name = "monolith",
hdrs = glob([
"*.c",
"*.h",
]),
)
cc_test(
name = "monolith_test",
size = "small",
srcs = ["monolith_test.cc"],
copts = ["-Wno-sign-compare"],
deps = [
":check_compat",
":monolith",
":run_auto_test",
"//c-toxcore/other:monolith",
"//c-toxcore/testing:misc_tools",
],
)

View File

@ -65,7 +65,7 @@ static void rebuild_peer_list(Tox *tox)
ck_assert_msg(err == TOX_ERR_CONFERENCE_PEER_QUERY_OK,
"failed to get conference peer %u's name size (conference = %u): err = %d", peer_number, conference_number, err);
uint8_t *const name = malloc(size);
uint8_t *const name = (uint8_t *)malloc(size);
tox_conference_peer_get_name(tox, conference_number, peer_number, name, &err);
ck_assert_msg(err == TOX_ERR_CONFERENCE_PEER_QUERY_OK,
"failed to get conference peer %u's name (conference = %u): err = %d", peer_number, conference_number, err);

View File

@ -234,7 +234,7 @@ static void test_many_group(void)
uint32_t peer_count = tox_conference_peer_count(toxes[i], 0, nullptr);
ck_assert_msg(peer_count == NUM_GROUP_TOX, "\n\tBad number of group peers (pre check)."
"\n\t\t\tExpected: %u but tox_instance(%u) only has: %u\n\n",
"\n\t\t\tExpected: %d but tox_instance(%u) only has: %u\n\n",
NUM_GROUP_TOX, i, (unsigned)peer_count);
uint8_t title[2048];

View File

@ -140,20 +140,18 @@ static void tox_file_chunk_request(Tox *tox, uint32_t friend_number, uint32_t fi
m_send_reached = 1;
}
TOX_ERR_FILE_SEND_CHUNK error;
VLA(uint8_t, f_data, length);
memset(f_data, sending_num, length);
if (tox_file_send_chunk(tox, friend_number, file_number, position, f_data, length, &error)) {
++sending_num;
sending_pos += length;
} else {
TOX_ERR_FILE_SEND_CHUNK error;
tox_file_send_chunk(tox, friend_number, file_number, position, f_data, length, &error);
if (error != TOX_ERR_FILE_SEND_CHUNK_OK) {
ck_abort_msg("Could not send chunk, error num=%d pos=%d len=%d", (int)error, (int)position, (int)length);
}
if (error != TOX_ERR_FILE_SEND_CHUNK_OK) {
ck_abort_msg("Wrong error code");
}
++sending_num;
sending_pos += length;
}

View File

@ -1,254 +0,0 @@
/* Nop-test, just to make sure our code compiles as C++.
*/
#ifdef __FreeBSD__
// Include this here, because _XOPEN_SOURCE hides symbols we need.
//
// https://lists.freebsd.org/pipermail/freebsd-standards/2004-March/000474.html.
#include <net/if.h>
#endif
#ifdef __APPLE__
#define _DARWIN_C_SOURCE
#endif
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include "../other/monolith.h"
#define DHT_C_INCLUDED
#include "../testing/misc_tools.c"
#include "check_compat.h"
#include <ctype.h>
namespace TCP_test {
int main(void);
#include "TCP_test.c"
} // namespace TCP_test
namespace bootstrap_test {
int main(void);
#include "bootstrap_test.c"
} // namespace bootstrap_test
namespace conference_simple_test {
int main(void);
#include "conference_simple_test.c"
} // namespace conference_simple_test
namespace conference_test {
int main(void);
#include "conference_test.c"
} // namespace conference_test
namespace crypto_test {
int main(void);
#include "crypto_test.c"
} // namespace crypto_test
namespace dht_test {
int main(void);
#include "dht_test.c"
} // namespace dht_test
namespace encryptsave_test {
int main(void);
#include "encryptsave_test.c"
} // namespace encryptsave_test
namespace file_saving_test {
int main(void);
#include "file_saving_test.c"
} // namespace file_saving_test
namespace friend_request_test {
int main(void);
#include "friend_request_test.c"
} // namespace friend_request_test
namespace lan_discovery_test {
int main(void);
#include "lan_discovery_test.c"
} // namespace lan_discovery_test
namespace lossless_packet_test {
int main(void);
#include "lossless_packet_test.c"
} // namespace lossless_packet_test
namespace lossy_packet_test {
int main(void);
#include "lossy_packet_test.c"
} // namespace lossy_packet_test
namespace messenger_test {
int main(void);
#include "messenger_test.c"
} // namespace messenger_test
namespace network_test {
int main(void);
#include "network_test.c"
} // namespace network_test
namespace onion_test {
int main(void);
#include "onion_test.c"
} // namespace onion_test
namespace save_friend_test {
int main(void);
#include "save_friend_test.c"
} // namespace save_friend_test
namespace save_load_test {
int main(void);
#include "save_load_test.c"
} // namespace save_load_test
namespace send_message_test {
int main(void);
#include "send_message_test.c"
} // namespace send_message_test
namespace set_name_test {
int main(void);
#include "set_name_test.c"
} // namespace set_name_test
namespace set_status_message_test {
int main(void);
#include "set_status_message_test.c"
} // namespace set_status_message_test
namespace skeleton_test {
int main(void);
#include "skeleton_test.c"
} // namespace skeleton_test
namespace toxav_basic_test {
int main(void);
#include "toxav_basic_test.c"
} // namespace toxav_basic_test
namespace toxav_many_test {
int main(void);
#include "toxav_many_test.c"
} // namespace toxav_many_test
namespace tox_many_tcp_test {
int main(void);
#include "tox_many_tcp_test.c"
} // namespace tox_many_tcp_test
namespace tox_many_test {
int main(void);
#include "tox_many_test.c"
} // namespace tox_many_test
namespace tox_one_test {
int main(void);
#include "tox_one_test.c"
} // namespace tox_one_test
namespace tox_strncasecmp_test {
int main(void);
#include "tox_strncasecmp_test.c"
} // namespace tox_strncasecmp_test
namespace typing_test {
int main(void);
#include "typing_test.c"
} // namespace typing_test
namespace version_test {
int main(void);
#include "version_test.c"
} // namespace version_test
#define PRINT_SIZE 0
template <typename T, size_t Expected, size_t Actual = sizeof(T)>
void check_size(char const *type) {
#if PRINT_SIZE
printf("CHECK_SIZE(%s, %zu);\n", type, Actual);
#else
static_assert(Actual == Expected, "Bad sizeof - see template expansion errors for details");
#endif
}
#define CHECK_SIZE(TYPE, SIZE) check_size<TYPE, SIZE>(#TYPE)
/**
* The main function static-asserts that we are aware of all the sizes of all
* the structs it toxcore. If you find this failing after you make a change,
* switch on the PRINT_SIZE above and copy the number into this function.
*/
int main(int argc, char *argv[]) {
static_assert(sizeof(uint64_t) >= sizeof(size_t),
"Assumption violated: size_t is more than 64 bits wide");
#if defined(__x86_64__) && defined(__LP64__)
// toxcore/DHT
CHECK_SIZE(Client_data, 496);
CHECK_SIZE(Cryptopacket_Handler, 16);
CHECK_SIZE(DHT, 676528);
CHECK_SIZE(DHT_Friend, 5104);
CHECK_SIZE(Hardening, 144);
CHECK_SIZE(IPPTs, 40);
CHECK_SIZE(IPPTsPng, 232);
CHECK_SIZE(NAT, 48);
CHECK_SIZE(Node_format, 64);
CHECK_SIZE(Shared_Key, 80);
CHECK_SIZE(Shared_Keys, 81920);
// toxcore/friend_connection
CHECK_SIZE(Friend_Conn, 1784);
CHECK_SIZE(Friend_Connections, 72);
// toxcore/friend_requests
CHECK_SIZE(Friend_Requests, 1080);
// toxcore/group
CHECK_SIZE(Group_c, 728);
CHECK_SIZE(Group_Chats, 2120);
CHECK_SIZE(Group_Peer, 480);
// toxcore/list
CHECK_SIZE(BS_List, 32);
// toxcore/logger
CHECK_SIZE(Logger, 24);
// toxcore/Messenger
CHECK_SIZE(File_Transfers, 72);
CHECK_SIZE(Friend, 39264);
CHECK_SIZE(Messenger, 2008);
CHECK_SIZE(Messenger_Options, 72);
CHECK_SIZE(Receipts, 16);
// toxcore/net_crypto
#ifdef __linux__
CHECK_SIZE(Crypto_Connection, 525392);
CHECK_SIZE(Net_Crypto, 272);
#endif
CHECK_SIZE(New_Connection, 168);
CHECK_SIZE(Packet_Data, 1384);
CHECK_SIZE(Packets_Array, 262152);
// toxcore/network
CHECK_SIZE(IP, 24);
CHECK_SIZE(IP4, 4);
#if USE_IPV6
CHECK_SIZE(IP6, 16);
#endif
CHECK_SIZE(IP_Port, 32);
CHECK_SIZE(Networking_Core, 4112);
CHECK_SIZE(Packet_Handler, 16);
// toxcore/onion_announce
CHECK_SIZE(Cmp_data, 296);
CHECK_SIZE(Onion_Announce, 128048);
CHECK_SIZE(Onion_Announce_Entry, 288);
// toxcore/onion_client
CHECK_SIZE(Last_Pinged, 40);
CHECK_SIZE(Onion_Client, 15816);
CHECK_SIZE(Onion_Client_Cmp_data, 176);
CHECK_SIZE(Onion_Client_Paths, 2520);
CHECK_SIZE(Onion_Friend, 1936);
CHECK_SIZE(Onion_Friend, 1936);
CHECK_SIZE(Onion_Node, 168);
// toxcore/onion
CHECK_SIZE(Onion, 245832);
CHECK_SIZE(Onion_Path, 392);
// toxcore/ping_array
CHECK_SIZE(Ping_Array, 24);
CHECK_SIZE(Ping_Array_Entry, 32);
// toxcore/ping
CHECK_SIZE(Ping, 2072);
// toxcore/TCP_client
CHECK_SIZE(TCP_Client_Connection, 12064);
CHECK_SIZE(TCP_Proxy_Info, 40);
// toxcore/TCP_connection
CHECK_SIZE(TCP_con, 112);
CHECK_SIZE(TCP_Connections, 200);
CHECK_SIZE(TCP_Connection_to, 112);
// toxcore/TCP_server
CHECK_SIZE(TCP_Priority_List, 16);
CHECK_SIZE(TCP_Secure_Connection, 11816);
#ifdef TCP_SERVER_USE_EPOLL
CHECK_SIZE(TCP_Server, 6049968); // 6MB!
#else
CHECK_SIZE(TCP_Server, 6049952); // 6MB!
#endif
// toxcore/tox
CHECK_SIZE(Tox_Options, 64);
#endif
return 0;
}

View File

@ -24,16 +24,16 @@ static void accept_friend_request(Tox *m, const uint8_t *public_key, const uint8
}
#define NUM_TOXES 90
#define NUM_FRIENDS 50
#define TCP_TEST_NUM_TOXES 90
#define TCP_TEST_NUM_FRIENDS 50
static void test_many_clients(void)
{
time_t cur_time = time(nullptr);
Tox *toxes[NUM_TOXES];
uint32_t index[NUM_TOXES];
Tox *toxes[TCP_TEST_NUM_TOXES];
uint32_t index[TCP_TEST_NUM_TOXES];
for (uint32_t i = 0; i < NUM_TOXES; ++i) {
for (uint32_t i = 0; i < TCP_TEST_NUM_TOXES; ++i) {
index[i] = i + 1;
toxes[i] = tox_new_log(nullptr, nullptr, &index[i]);
ck_assert_msg(toxes[i] != nullptr, "failed to create tox instances %u", i);
@ -43,22 +43,22 @@ static void test_many_clients(void)
struct {
uint16_t tox1;
uint16_t tox2;
} pairs[NUM_FRIENDS];
} pairs[TCP_TEST_NUM_FRIENDS];
uint8_t address[TOX_ADDRESS_SIZE];
uint32_t num_f = 0;
for (uint32_t i = 0; i < NUM_TOXES; ++i) {
for (uint32_t i = 0; i < TCP_TEST_NUM_TOXES; ++i) {
num_f += tox_self_get_friend_list_size(toxes[i]);
}
ck_assert_msg(num_f == 0, "bad num friends: %u", num_f);
for (uint32_t i = 0; i < NUM_FRIENDS; ++i) {
for (uint32_t i = 0; i < TCP_TEST_NUM_FRIENDS; ++i) {
loop_top:
pairs[i].tox1 = random_u32() % NUM_TOXES;
pairs[i].tox2 = (pairs[i].tox1 + random_u32() % (NUM_TOXES - 1) + 1) % NUM_TOXES;
pairs[i].tox1 = random_u32() % TCP_TEST_NUM_TOXES;
pairs[i].tox2 = (pairs[i].tox1 + random_u32() % (TCP_TEST_NUM_TOXES - 1) + 1) % TCP_TEST_NUM_TOXES;
for (uint32_t j = 0; j < i; ++j) {
if (pairs[j].tox2 == pairs[i].tox1 && pairs[j].tox1 == pairs[i].tox2) {
@ -84,18 +84,18 @@ loop_top:
ck_assert_msg(num != UINT32_MAX && test == TOX_ERR_FRIEND_ADD_OK, "failed to add friend error code: %i", test);
}
for (uint32_t i = 0; i < NUM_TOXES; ++i) {
for (uint32_t i = 0; i < TCP_TEST_NUM_TOXES; ++i) {
num_f += tox_self_get_friend_list_size(toxes[i]);
}
ck_assert_msg(num_f == NUM_FRIENDS, "bad num friends: %u", num_f);
ck_assert_msg(num_f == TCP_TEST_NUM_FRIENDS, "bad num friends: %u", num_f);
uint16_t last_count = 0;
while (1) {
uint16_t counter = 0;
for (uint32_t i = 0; i < NUM_TOXES; ++i) {
for (uint32_t i = 0; i < TCP_TEST_NUM_TOXES; ++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_UDP) {
++counter;
@ -108,18 +108,18 @@ loop_top:
last_count = counter;
}
if (counter == NUM_FRIENDS * 2) {
if (counter == TCP_TEST_NUM_FRIENDS * 2) {
break;
}
for (uint32_t i = 0; i < NUM_TOXES; ++i) {
for (uint32_t i = 0; i < TCP_TEST_NUM_TOXES; ++i) {
tox_iterate(toxes[i], nullptr);
}
c_sleep(50);
}
for (uint32_t i = 0; i < NUM_TOXES; ++i) {
for (uint32_t i = 0; i < TCP_TEST_NUM_TOXES; ++i) {
tox_kill(toxes[i]);
}

View File

@ -28,7 +28,7 @@ static void set_random_name_and_status_message(Tox *tox, uint8_t *name, uint8_t
}
}
START_TEST(test_one)
static void test_one(void)
{
uint8_t name[TOX_MAX_NAME_LENGTH];
uint8_t status_message[TOX_MAX_STATUS_MESSAGE_LENGTH];
@ -128,30 +128,13 @@ START_TEST(test_one)
tox_kill(tox1);
tox_kill(tox2);
}
END_TEST
static Suite *tox_suite(void)
{
Suite *s = suite_create("Tox one");
DEFTESTCASE(one);
return s;
}
int main(void)
{
setvbuf(stdout, nullptr, _IONBF, 0);
Suite *tox = tox_suite();
SRunner *test_runner = srunner_create(tox);
test_one();
int number_failed = 0;
srunner_run_all(test_runner, CK_NORMAL);
number_failed = srunner_ntests_failed(test_runner);
srunner_free(test_runner);
return number_failed;
return 0;
}

View File

@ -72,7 +72,7 @@ AC_ARG_ENABLE([logging],
if test "x$enableval" = "xyes"; then
TOX_LOGGER="yes"
AC_DEFINE([MIN_LOGGER_LEVEL], [LOG_DEBUG], [LOG_LEVEL value])
AC_DEFINE([MIN_LOGGER_LEVEL], [LOGGER_LEVEL_DEBUG], [Logger_Level value])
fi
]
)
@ -85,19 +85,19 @@ AC_ARG_WITH(log-level,
AC_MSG_WARN([Logging disabled!])
else
if test "x$withval" = "xTRACE"; then
AC_DEFINE([MIN_LOGGER_LEVEL], [LOG_TRACE], [LOG_LEVEL value])
AC_DEFINE([MIN_LOGGER_LEVEL], [LOGGER_LEVEL_TRACE], [Logger_Level value])
elif test "x$withval" = "xDEBUG"; then
AC_DEFINE([MIN_LOGGER_LEVEL], [LOG_DEBUG], [LOG_LEVEL value])
AC_DEFINE([MIN_LOGGER_LEVEL], [LOGGER_LEVEL_DEBUG], [Logger_Level value])
elif test "x$withval" = "xINFO"; then
AC_DEFINE([MIN_LOGGER_LEVEL], [LOG_INFO], [LOG_LEVEL value])
AC_DEFINE([MIN_LOGGER_LEVEL], [LOGGER_LEVEL_INFO], [Logger_Level value])
elif test "x$withval" = "xWARNING"; then
AC_DEFINE([MIN_LOGGER_LEVEL], [LOG_WARNING], [LOG_LEVEL value])
AC_DEFINE([MIN_LOGGER_LEVEL], [LOGGER_LEVEL_WARNING], [Logger_Level value])
elif test "x$withval" = "xERROR"; then
AC_DEFINE([MIN_LOGGER_LEVEL], [LOG_ERROR], [LOG_LEVEL value])
AC_DEFINE([MIN_LOGGER_LEVEL], [LOGGER_LEVEL_ERROR], [Logger_Level value])
else
AC_MSG_WARN([Invalid logger level: $withval. Using default 'DEBUG'])
fi

View File

@ -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"],

View File

@ -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 >> test.c
cat $1 >> amalgamation.cc
}
:> test.c
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
sed -e 's/^int main(/static &/' $1 >> amalgamation.cc
echo "} // namespace $(echo $1 | sed -e 's/[^a-zA-Z0-9_]/_/g')" >> amalgamation.cc
}
put toxcore/tox.c
callmain() {
echo " call($(echo $1 | sed -e 's/[^a-zA-Z0-9_]/_/g')::main, argc, argv);" >> amalgamation.cc
}
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
:> amalgamation.cc
# 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
echo "#include <algorithm>" >> amalgamation.cc
echo "#include <cstdio>" >> amalgamation.cc
echo "#include <memory>" >> amalgamation.cc
echo "#include <random>" >> amalgamation.cc
put toxencryptsave/toxencryptsave.c
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

View File

@ -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 \

View File

@ -0,0 +1,8 @@
#!/bin/sh
. other/analysis/gen-file.sh
echo "Running Clang static analyzer"
clang++ --analyze amalgamation.cc \
$CPPFLAGS \
-std=c++11

View File

@ -2,6 +2,4 @@
. other/analysis/gen-file.sh
put auto_tests/lan_discovery_test.c
cppcheck test.c $CPPFLAGS
cppcheck amalgamation.cc $CPPFLAGS

View File

@ -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 \

View File

@ -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

View File

@ -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

View File

@ -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);

View File

@ -22,7 +22,9 @@
* You should have received a copy of the GNU General Public License
* along with Tox. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef _XOPEN_SOURCE
#define _XOPEN_SOURCE 600
#endif
// system provided
#include <sys/stat.h>

View File

@ -1,5 +1,5 @@
#define typeof __typeof__
#ifdef ANDROID_CPU_FEATURES
#define typeof __typeof__
#include ANDROID_CPU_FEATURES
#endif

View File

@ -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;

View File

@ -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) {

View File

@ -43,7 +43,7 @@
#define PRINT_TRIES_COUNT
void print_key(unsigned char *key)
static void print_key(unsigned char *key)
{
size_t i;

View File

@ -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"

View File

@ -35,7 +35,7 @@ cc_binary(
copts = ["-O1"],
deps = [
"//c-toxcore/toxav",
"//c-toxcore/toxav:monolith",
"//c-toxcore/toxav:ring_buffer_srcs",
"//c-toxcore/toxcore",
"@opencv//:core",
"@opencv//:highgui",
@ -52,13 +52,3 @@ cc_binary(
"//c-toxcore/toxcore",
],
)
cc_library(
name = "monolith",
hdrs = [
"misc_tools.c",
"misc_tools.h",
],
visibility = ["//c-toxcore/other:__pkg__"],
deps = ["//c-toxcore/toxcore"],
)

View File

@ -28,7 +28,9 @@
* You should have received a copy of the GNU General Public License
* along with Tox. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef _XOPEN_SOURCE
#define _XOPEN_SOURCE 600
#endif
#include <stdlib.h>
#include <stdio.h>

View File

@ -102,6 +102,7 @@ struct Global_State : std::vector<Local_State> {
// Non-copyable;
Global_State(Global_State const &) = delete;
Global_State(Global_State &&) = default;
~Global_State();
explicit Global_State(std::vector<Action> const &actions)
: actions_(actions), rnd_(actions), action_counter_(actions.size()) {}
@ -115,6 +116,8 @@ struct Global_State : std::vector<Local_State> {
std::vector<unsigned> action_counter_;
};
Global_State::~Global_State() {}
void handle_friend_connection_status(Tox *tox, uint32_t friend_number,
TOX_CONNECTION connection_status, void *user_data) {
Local_State *state = static_cast<Local_State *>(user_data);
@ -394,4 +397,6 @@ int main() {
for (uint32_t i = 0; i < toxes.action_counter().size(); i++) {
std::printf("%u x '%s'\n", toxes.action_counter().at(i), actions[i].title);
}
return 0;
}

View File

@ -27,6 +27,16 @@ cc_test(
],
)
cc_library(
name = "ring_buffer_srcs",
hdrs = [
"ring_buffer.c",
"ring_buffer.h",
],
visibility = ["//c-toxcore/testing:__pkg__"],
deps = ["//c-toxcore/toxcore:ccompat"],
)
cc_library(
name = "bwcontroller",
srcs = ["bwcontroller.c"],
@ -117,20 +127,3 @@ cc_library(
":video",
],
)
cc_library(
name = "monolith",
hdrs = glob([
"*.c",
"*.h",
]),
visibility = [
"//c-toxcore/other:__pkg__",
"//c-toxcore/testing:__pkg__",
],
deps = [
"//c-toxcore/toxcore:group",
"@libvpx",
"@opus",
],
)

View File

@ -17,6 +17,9 @@
* You should have received a copy of the GNU General Public License
* along with Tox. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef C_TOXCORE_TOXAV_GROUPAV_H
#define C_TOXCORE_TOXAV_GROUPAV_H
#include "../toxcore/group.h"
/* Audio encoding/decoding */
@ -50,3 +53,5 @@ int join_av_groupchat(const Logger *log, Group_Chats *g_c, uint32_t friendnumber
int group_send_audio(Group_Chats *g_c, uint32_t groupnumber, const int16_t *pcm, unsigned int samples, uint8_t channels,
uint32_t sample_rate);
#endif // C_TOXCORE_TOXAV_GROUPAV_H

View File

@ -134,6 +134,27 @@ cc_library(
],
)
cc_library(
name = "DHT_srcs",
hdrs = [
"DHT.c",
"DHT.h",
"LAN_discovery.c",
"LAN_discovery.h",
"ping.c",
"ping.h",
],
visibility = [
"//c-toxcore/auto_tests:__pkg__",
"//c-toxcore/other/bootstrap_daemon:__pkg__",
],
deps = [
":logger",
":ping_array",
":state",
],
)
cc_library(
name = "onion",
srcs = ["onion.c"],
@ -242,17 +263,3 @@ cc_library(
"//c-toxcore/toxencryptsave:defines",
],
)
cc_library(
name = "monolith",
hdrs = glob([
"*.c",
"*.h",
]),
linkopts = ["-lpthread"],
visibility = ["//c-toxcore/other:__pkg__"],
deps = [
"//c-toxcore/toxencryptsave:defines",
"@libsodium",
],
)

View File

@ -44,19 +44,19 @@ struct Logger {
static const char *logger_level_name(Logger_Level level)
{
switch (level) {
case LOG_TRACE:
case LOGGER_LEVEL_TRACE:
return "TRACE";
case LOG_DEBUG:
case LOGGER_LEVEL_DEBUG:
return "DEBUG";
case LOG_INFO:
case LOGGER_LEVEL_INFO:
return "INFO";
case LOG_WARNING:
case LOGGER_LEVEL_WARNING:
return "WARNING";
case LOG_ERROR:
case LOGGER_LEVEL_ERROR:
return "ERROR";
}

View File

@ -29,15 +29,15 @@
#include "ccompat.h"
#ifndef MIN_LOGGER_LEVEL
#define MIN_LOGGER_LEVEL LOG_INFO
#define MIN_LOGGER_LEVEL LOGGER_LEVEL_INFO
#endif
typedef enum Logger_Level {
LOG_TRACE,
LOG_DEBUG,
LOG_INFO,
LOG_WARNING,
LOG_ERROR
LOGGER_LEVEL_TRACE,
LOGGER_LEVEL_DEBUG,
LOGGER_LEVEL_INFO,
LOGGER_LEVEL_WARNING,
LOGGER_LEVEL_ERROR
} Logger_Level;
typedef struct Logger Logger;
@ -84,10 +84,10 @@ void logger_write(
} while (0)
/* To log with an logger */
#define LOGGER_TRACE(log, ...) LOGGER_WRITE(log, LOG_TRACE , __VA_ARGS__)
#define LOGGER_DEBUG(log, ...) LOGGER_WRITE(log, LOG_DEBUG , __VA_ARGS__)
#define LOGGER_INFO(log, ...) LOGGER_WRITE(log, LOG_INFO , __VA_ARGS__)
#define LOGGER_WARNING(log, ...) LOGGER_WRITE(log, LOG_WARNING, __VA_ARGS__)
#define LOGGER_ERROR(log, ...) LOGGER_WRITE(log, LOG_ERROR , __VA_ARGS__)
#define LOGGER_TRACE(log, ...) LOGGER_WRITE(log, LOGGER_LEVEL_TRACE , __VA_ARGS__)
#define LOGGER_DEBUG(log, ...) LOGGER_WRITE(log, LOGGER_LEVEL_DEBUG , __VA_ARGS__)
#define LOGGER_INFO(log, ...) LOGGER_WRITE(log, LOGGER_LEVEL_INFO , __VA_ARGS__)
#define LOGGER_WARNING(log, ...) LOGGER_WRITE(log, LOGGER_LEVEL_WARNING, __VA_ARGS__)
#define LOGGER_ERROR(log, ...) LOGGER_WRITE(log, LOGGER_LEVEL_ERROR , __VA_ARGS__)
#endif /* TOXLOGGER_H */

View File

@ -25,10 +25,14 @@
#include "config.h"
#endif
#ifndef _XOPEN_SOURCE
#define _XOPEN_SOURCE 600
#endif
#ifndef TOX_DEFINED
#define TOX_DEFINED
typedef struct Messenger Tox;
#endif
#include "tox.h"
#include <assert.h>