Skip to content

Commit

Permalink
Fix a bunch of compiler warnings and remove suppressions.
Browse files Browse the repository at this point in the history
  • Loading branch information
iphydf committed Feb 23, 2018
1 parent b2a2a0b commit 593b04d
Show file tree
Hide file tree
Showing 50 changed files with 236 additions and 209 deletions.
57 changes: 28 additions & 29 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -107,54 +107,53 @@ if(NOT MSVC)
add_flag("-Weverything")

# Disable specific warning flags for both C and C++.

# TODO(iphydf): Clean these up. Probably all of these are actual bugs.
add_flag("-Wno-cast-align")
# Very verbose, not very useful. This warns about things like int -> uint
# conversions that change sign without a cast and narrowing conversions.
add_flag("-Wno-conversion")
# TODO(iphydf): Check enum values when received from the user, then assume
# correctness and remove this suppression.
add_flag("-Wno-covered-switch-default")
# Due to clang's tolower() macro being recursive https://github.com/TokTok/c-toxcore/pull/481
# Due to clang's tolower() macro being recursive
# https://github.com/TokTok/c-toxcore/pull/481
add_flag("-Wno-disabled-macro-expansion")
# We don't put __attribute__ on the public API.
add_flag("-Wno-documentation-deprecated-sync")
# Bootstrap daemon does this.
add_flag("-Wno-format-nonliteral")
# struct Foo foo = {0}; is a common idiom.
add_flag("-Wno-missing-field-initializers")
add_flag("-Wno-missing-prototypes")
add_flag("-Wno-packed")
# Useful sometimes, but we accept padding in structs for clarity.
# Reordering fields to avoid padding will reduce readability.
add_flag("-Wno-padded")
add_flag("-Wno-parentheses")
# This warns on things like _XOPEN_SOURCE, which we currently need (we
# probably won't need these in the future).
add_flag("-Wno-reserved-id-macro")
add_flag("-Wno-return-type")
# TODO(iphydf): Clean these up. They are likely not bugs, but still
# potential issues and probably confusing.
add_flag("-Wno-sign-compare")
add_flag("-Wno-sign-conversion")
# Our use of mutexes results in a false positive, see 1bbe446
# Our use of mutexes results in a false positive, see 1bbe446.
add_flag("-Wno-thread-safety-analysis")
# File transfer code has this.
add_flag("-Wno-type-limits")
add_flag("-Wno-undef")
add_flag("-Wno-unreachable-code")
add_flag("-Wno-unused-macros")
# Callbacks often don't use all their parameters.
add_flag("-Wno-unused-parameter")
# libvpx uses __attribute__((unused)) for "potentially unused" static
# functions to avoid unused static function warnings.
add_flag("-Wno-used-but-marked-unused")
# We use variable length arrays a lot.
add_flag("-Wno-vla")

# Disable specific warning flags for C.
add_cflag("-Wno-assign-enum")
add_cflag("-Wno-bad-function-cast")
add_cflag("-Wno-double-promotion")
add_cflag("-Wno-gnu-zero-variadic-macro-arguments")
add_cflag("-Wno-packed")
add_cflag("-Wno-shadow")
add_cflag("-Wno-shorten-64-to-32")
add_cflag("-Wno-unreachable-code-return")
add_cflag("-Wno-unused-but-set-variable")
add_cflag("-Wno-used-but-marked-unused")

# Disable specific warning flags for C++.
add_cxxflag("-Wno-c++98-compat")

# Comma at end of enum is supported everywhere we run.
add_cxxflag("-Wno-c++98-compat-pedantic")
# TODO(iphydf): Stop using flexible array members.
add_cxxflag("-Wno-c99-extensions")
add_cxxflag("-Wno-double-promotion")
add_cxxflag("-Wno-narrowing")
# We're C-compatible, so use C style casts.
add_cxxflag("-Wno-old-style-cast")
add_cxxflag("-Wno-shadow")
add_cxxflag("-Wno-used-but-marked-unused")
add_cxxflag("-Wno-variadic-macros")
add_cxxflag("-Wno-vla-extension")

# Downgrade to warning so we still see it.
add_flag("-Wno-error=unused-variable")
Expand Down
10 changes: 2 additions & 8 deletions auto_tests/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,7 @@ cc_library(
name = src[:-2],
size = "small",
srcs = [src],
copts = [
"-Wno-parentheses",
"-Wno-sign-compare",
],
copts = ["-Wno-sign-compare"],
deps = [
":helpers",
"//c-toxcore/other:monolith",
Expand All @@ -37,10 +34,7 @@ cc_test(
name = "monolith_test",
size = "small",
srcs = ["monolith_test.cpp"],
copts = [
"-Wno-parentheses",
"-Wno-sign-compare",
],
copts = ["-Wno-sign-compare"],
deps = [
":helpers",
":monolith",
Expand Down
8 changes: 3 additions & 5 deletions auto_tests/TCP_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,8 @@
#endif

#if !USE_IPV6
# undef TOX_AF_INET6
# define TOX_AF_INET6 TOX_AF_INET
# define get_ip6_loopback get_ip4_loopback
# define IP6 IP4
#undef TOX_AF_INET6
#define TOX_AF_INET6 TOX_AF_INET
#endif

static inline IP get_loopback()
Expand Down Expand Up @@ -769,7 +767,7 @@ static Suite *TCP_suite(void)
return s;
}

int main(int argc, char *argv[])
int main(void)
{
setvbuf(stdout, nullptr, _IONBF, 0);

Expand Down
10 changes: 5 additions & 5 deletions auto_tests/check_compat.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,26 +16,26 @@ typedef struct Suite Suite;
typedef struct SRunner SRunner;
enum SRunMode { CK_NORMAL };

Suite *suite_create(const char *title)
static inline Suite *suite_create(const char *title)
{
printf("Running test suite: %s\n", title);
return nullptr;
}

SRunner *srunner_create(Suite *s)
static inline SRunner *srunner_create(Suite *s)
{
return nullptr;
}

void srunner_free(SRunner *s)
static inline void srunner_free(SRunner *s)
{
}

void srunner_run_all(SRunner *r, int mode)
static inline void srunner_run_all(SRunner *r, int mode)
{
}

int srunner_ntests_failed(SRunner *r)
static inline int srunner_ntests_failed(SRunner *r)
{
return 0;
}
Expand Down
2 changes: 1 addition & 1 deletion auto_tests/conference_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,7 @@ static void test_many_group(void)
printf("test_many_group succeeded, took %d seconds\n", (int)(time(nullptr) - test_start_time));
}

int main(int argc, char *argv[])
int main(void)
{
setvbuf(stdout, nullptr, _IONBF, 0);

Expand Down
2 changes: 1 addition & 1 deletion auto_tests/crypto_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -354,7 +354,7 @@ static Suite *crypto_suite(void)
return s;
}

int main(int argc, char *argv[])
int main(void)
{
setvbuf(stdout, nullptr, _IONBF, 0);
srand((unsigned int) time(nullptr));
Expand Down
15 changes: 4 additions & 11 deletions auto_tests/dht_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,6 @@
// These tests currently fail.
static bool enable_broken_tests = false;

#define swap(x,y) do \
{ unsigned char swap_temp[sizeof(x) == sizeof(y) ? (signed)sizeof(x) : -1]; \
memcpy(swap_temp,&y,sizeof(x)); \
memcpy(&y,&x, sizeof(x)); \
memcpy(&x,swap_temp,sizeof(x)); \
} while(0)

#ifndef USE_IPV6
#define USE_IPV6 1
#endif
Expand Down Expand Up @@ -335,7 +328,9 @@ static void test_addto_lists(IP ip)
DHT *dht = new_DHT(nullptr, net, true);
ck_assert_msg(dht != nullptr, "Failed to create DHT");

IP_Port ip_port = { .ip = ip, .port = TOX_PORT_DEFAULT };
IP_Port ip_port;
ip_port.ip = ip;
ip_port.port = TOX_PORT_DEFAULT;
uint8_t public_key[CRYPTO_PUBLIC_KEY_SIZE];
int i, used;

Expand Down Expand Up @@ -413,8 +408,6 @@ END_TEST

#define DHT_DEFAULT_PORT (TOX_PORT_DEFAULT + 20)

#define DHT_LIST_LENGTH 128

static void print_pk(uint8_t *public_key)
{
uint32_t j;
Expand Down Expand Up @@ -799,7 +792,7 @@ static Suite *dht_suite(void)
return s;
}

int main(int argc, char *argv[])
int main(void)
{
setvbuf(stdout, nullptr, _IONBF, 0);
srand((unsigned int) time(nullptr));
Expand Down
2 changes: 1 addition & 1 deletion auto_tests/encryptsave_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ static Suite *encryptsave_suite(void)
return s;
}

int main(int argc, char *argv[])
int main(void)
{
setvbuf(stdout, nullptr, _IONBF, 0);
srand((unsigned int) time(nullptr));
Expand Down
14 changes: 11 additions & 3 deletions auto_tests/file_transfer_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,11 @@ START_TEST(test_few_clients)

printf("Starting file streaming transfer test.\n");

file_sending_done = file_accepted = file_size = sendf_ok = size_recv = 0;
file_sending_done = 0;
file_accepted = 0;
file_size = 0;
sendf_ok = 0;
size_recv = 0;
file_recv = 0;
tox_callback_file_recv_chunk(tox3, write_file);
tox_callback_file_recv_control(tox2, file_print_control);
Expand Down Expand Up @@ -335,7 +339,11 @@ START_TEST(test_few_clients)

printf("Starting file 0 transfer test.\n");

file_sending_done = file_accepted = file_size = sendf_ok = size_recv = 0;
file_sending_done = 0;
file_accepted = 0;
file_size = 0;
sendf_ok = 0;
size_recv = 0;
file_recv = 0;
tox_callback_file_recv_chunk(tox3, write_file);
tox_callback_file_recv_control(tox2, file_print_control);
Expand Down Expand Up @@ -395,7 +403,7 @@ static Suite *tox_suite(void)
return s;
}

int main(int argc, char *argv[])
int main(void)
{
setvbuf(stdout, nullptr, _IONBF, 0);
srand((unsigned int) time(nullptr));
Expand Down
2 changes: 1 addition & 1 deletion auto_tests/friend_request_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ static void test_friend_request(void)
tox_kill(tox2);
}

int main(int argc, char *argv[])
int main(void)
{
setvbuf(stdout, nullptr, _IONBF, 0);

Expand Down
4 changes: 3 additions & 1 deletion auto_tests/helpers.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@

#define ITERATION_INTERVAL 200

Tox *tox_new_log(struct Tox_Options *options, TOX_ERR_NEW *err, void *log_user_data);

static const char *tox_log_level_name(TOX_LOG_LEVEL level)
{
switch (level) {
Expand Down Expand Up @@ -54,7 +56,7 @@ static void print_debug_log(Tox *m, TOX_LOG_LEVEL level, const char *path, uint3
fprintf(stderr, "[#%d] %s %s:%d\t%s:\t%s\n", index, tox_log_level_name(level), file, line, func, message);
}

Tox *tox_new_log_lan(struct Tox_Options *options, TOX_ERR_NEW *err, void *log_user_data, bool lan_discovery)
static Tox *tox_new_log_lan(struct Tox_Options *options, TOX_ERR_NEW *err, void *log_user_data, bool lan_discovery)
{
struct Tox_Options *log_options = options;

Expand Down
2 changes: 1 addition & 1 deletion auto_tests/lossless_packet_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ static void test_lossless_packet(void)
tox_kill(tox2);
}

int main(int argc, char *argv[])
int main(void)
{
setvbuf(stdout, nullptr, _IONBF, 0);

Expand Down
2 changes: 1 addition & 1 deletion auto_tests/lossy_packet_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ static void test_lossy_packet(void)
tox_kill(tox2);
}

int main(int argc, char *argv[])
int main(void)
{
setvbuf(stdout, nullptr, _IONBF, 0);

Expand Down
7 changes: 3 additions & 4 deletions auto_tests/messenger_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,13 @@
#include <string.h>
#include <sys/types.h>

#if VANILLA_NACL
#ifdef VANILLA_NACL
#include <crypto_box.h> // crypto_box_PUBLICKEYBYTES and other defines.
#else
#include <sodium.h>
#endif

#define REALLY_BIG_NUMBER ((1) << (sizeof(uint16_t) * 7))
#define STRINGS_EQUAL(X, Y) (strcmp(X, Y) == 0)

static bool enable_broken_tests = false;

Expand Down Expand Up @@ -213,7 +212,7 @@ START_TEST(test_m_copy_userstatus)
assert(m_copy_userstatus(REALLY_BIG_NUMBER, buf, MAX_USERSTATUS_LENGTH) == -1);
m_copy_userstatus(friend_id_num, buf, MAX_USERSTATUS_LENGTH + 6);

assert(STRINGS_EQUAL(name_buf, friend_id_status));
assert(strcmp(name_buf, friend_id_status) == 0);
}
END_TEST
#endif
Expand Down Expand Up @@ -346,7 +345,7 @@ static Suite *messenger_suite(void)
return s;
}

int main(int argc, char *argv[])
int main(void)
{
setvbuf(stdout, nullptr, _IONBF, 0);

Expand Down
Loading

0 comments on commit 593b04d

Please sign in to comment.