Skip to content

Commit

Permalink
cleanup: Enable most cppcheck warnings as errors.
Browse files Browse the repository at this point in the history
Cleaned up some of the warnings it gives. Disabled the ones that are
less useful for us at this time.
  • Loading branch information
iphydf committed Feb 21, 2022
1 parent a9ccf1b commit 8d2b1d8
Show file tree
Hide file tree
Showing 18 changed files with 136 additions and 118 deletions.
4 changes: 2 additions & 2 deletions auto_tests/auto_test_support.c
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@ static void autotox_add_friend(AutoTox *autotoxes, uint32_t adding, uint32_t add
static void initialise_friend_graph(Graph_Type graph, uint32_t num_toxes, AutoTox *autotoxes)
{
if (graph == GRAPH_LINEAR) {
printf("toxes #%u-#%u each add adjacent toxes as friends\n", 0, num_toxes - 1);
printf("toxes #%d-#%u each add adjacent toxes as friends\n", 0, num_toxes - 1);

for (uint32_t i = 0; i < num_toxes; ++i) {
for (uint32_t j = i - 1; j != i + 3; j += 2) {
Expand All @@ -245,7 +245,7 @@ static void initialise_friend_graph(Graph_Type graph, uint32_t num_toxes, AutoTo
}
}
} else if (graph == GRAPH_COMPLETE) {
printf("toxes #%u-#%u add each other as friends\n", 0, num_toxes - 1);
printf("toxes #%d-#%u add each other as friends\n", 0, num_toxes - 1);

for (uint32_t i = 0; i < num_toxes; ++i) {
for (uint32_t j = 0; j < num_toxes; ++j) {
Expand Down
8 changes: 4 additions & 4 deletions auto_tests/auto_test_support.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,17 +21,17 @@ typedef struct AutoTox {
void *state;
} AutoTox;

bool all_connected(AutoTox *toxes, uint32_t tox_count);
bool all_connected(AutoTox *autotoxes, uint32_t tox_count);

bool all_friends_connected(AutoTox *toxes, uint32_t tox_count);
bool all_friends_connected(AutoTox *autotoxes, uint32_t tox_count);

void iterate_all_wait(AutoTox *toxes, uint32_t tox_count, uint32_t wait);
void iterate_all_wait(AutoTox *autotoxes, uint32_t tox_count, uint32_t wait);

void save_autotox(AutoTox *autotox);
void kill_autotox(AutoTox *autotox);
void reload(AutoTox *autotox);

void set_mono_time_callback(AutoTox *tox);
void set_mono_time_callback(AutoTox *autotox);

typedef enum Graph_Type {
GRAPH_COMPLETE = 0,
Expand Down
1 change: 0 additions & 1 deletion other/analysis/gen-file.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ CPPFLAGS+=("-Iother/bootstrap_daemon/src")
CPPFLAGS+=("-Iother/fun")
CPPFLAGS+=("-Itesting")
CPPFLAGS+=("-Itesting/fuzzing")
CPPFLAGS+=("-Itesting/groupchats")
CPPFLAGS+=("-Itoxcore")
CPPFLAGS+=("-Itoxcore/events")
CPPFLAGS+=("-Itoxav")
Expand Down
22 changes: 21 additions & 1 deletion other/analysis/run-cppcheck
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,29 @@ SKIP_GTEST=1

set -e

CPPCHECK="--enable=all"
CPPCHECK+=("--inconclusive")
CPPCHECK+=("--error-exitcode=1")
# Used for VLA.
CPPCHECK+=("--suppress=allocaCalled")
# We actually write C code.
CPPCHECK+=("--suppress=cstyleCast")
# Used to enable/disable parts using if with constant condition.
CPPCHECK+=("--suppress=knownConditionTrueFalse")
# Cppcheck does not need standard library headers to get proper results.
CPPCHECK+=("--suppress=missingIncludeSystem")
# Range-for is fine.
CPPCHECK+=("--suppress=useStlAlgorithm")
# TODO(iphydf): Maybe fix?
CPPCHECK+=("--suppress=shadowArgument")
CPPCHECK+=("--suppress=shadowFunction")
CPPCHECK+=("--suppress=signConversion")
# TODO(iphydf): Fixed in the toxav refactor PR.
CPPCHECK+=("--suppress=redundantAssignment")

run() {
echo "Running cppcheck in variant '$*'"
cppcheck amalgamation.cc "${CPPFLAGS[@]}" "$@"
cppcheck "${CPPCHECK[@]}" amalgamation.cc "${CPPFLAGS[@]}" "$@"
}

. other/analysis/variants.sh
6 changes: 3 additions & 3 deletions other/analysis/run-gcc
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,12 @@ run() {
-Wfloat-equal \
-Wformat=2 \
-Wframe-address \
-Wframe-larger-than=133168 \
-Wignored-qualifiers \
-Wframe-larger-than=12400 \
-Wignored-attributes \
-Wignored-qualifiers \
-Winit-self \
-Winline \
-Wlarger-than=133120 \
-Wlarger-than=530000 \
-Wmaybe-uninitialized \
-Wmemset-transposed-args \
-Wmisleading-indentation \
Expand Down
2 changes: 1 addition & 1 deletion other/bootstrap_daemon/docker/tox-bootstrapd.sha256
Original file line number Diff line number Diff line change
@@ -1 +1 @@
dc97c6a50cf2e3d06dc24216194569b06445922a5182362af2124114653d7f71 /usr/local/bin/tox-bootstrapd
e60be1422bb4ba3bf080faca429174afb4804211d5d5fe1ba365ed65f505b361 /usr/local/bin/tox-bootstrapd
2 changes: 1 addition & 1 deletion other/fun/create_common.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ static void handle_args(const int argc, const char *const argv[], const char *co

crypto_scalarmult_base(public_key, secret_key);
} else if (argc == 2) {
printf("Error: Secret key must be a %d character hex string.\n", crypto_box_SECRETKEYBYTES * 2);
printf("Error: Secret key must be a %u character hex string.\n", crypto_box_SECRETKEYBYTES * 2);
exit(1);
} else {
print_usage(argv[0], does_what);
Expand Down
32 changes: 16 additions & 16 deletions toxav/toxav.c
Original file line number Diff line number Diff line change
Expand Up @@ -638,7 +638,7 @@ bool toxav_call_control(ToxAV *av, uint32_t friend_number, Toxav_Call_Control co

return rc == TOXAV_ERR_CALL_CONTROL_OK;
}
bool toxav_audio_set_bit_rate(ToxAV *av, uint32_t friend_number, uint32_t audio_bit_rate,
bool toxav_audio_set_bit_rate(ToxAV *av, uint32_t friend_number, uint32_t bit_rate,
Toxav_Err_Bit_Rate_Set *error)
{
Toxav_Err_Bit_Rate_Set rc = TOXAV_ERR_BIT_RATE_SET_OK;
Expand All @@ -649,7 +649,7 @@ bool toxav_audio_set_bit_rate(ToxAV *av, uint32_t friend_number, uint32_t audio_
goto RETURN;
}

if (audio_bit_rate > 0 && audio_bit_rate_invalid(audio_bit_rate)) {
if (bit_rate > 0 && audio_bit_rate_invalid(bit_rate)) {
rc = TOXAV_ERR_BIT_RATE_SET_INVALID_BIT_RATE;
goto RETURN;
}
Expand All @@ -663,11 +663,11 @@ bool toxav_audio_set_bit_rate(ToxAV *av, uint32_t friend_number, uint32_t audio_
goto RETURN;
}

LOGGER_DEBUG(av->m->log, "Setting new audio bitrate to: %d", audio_bit_rate);
LOGGER_DEBUG(av->m->log, "Setting new audio bitrate to: %d", bit_rate);

if (call->audio_bit_rate == audio_bit_rate) {
LOGGER_DEBUG(av->m->log, "Audio bitrate already set to: %d", audio_bit_rate);
} else if (audio_bit_rate == 0) {
if (call->audio_bit_rate == bit_rate) {
LOGGER_DEBUG(av->m->log, "Audio bitrate already set to: %d", bit_rate);
} else if (bit_rate == 0) {
LOGGER_DEBUG(av->m->log, "Turned off audio sending");

if (msi_change_capabilities(call->msi_call, call->msi_call->
Expand All @@ -694,10 +694,10 @@ bool toxav_audio_set_bit_rate(ToxAV *av, uint32_t friend_number, uint32_t audio_
goto RETURN;
}
} else {
LOGGER_DEBUG(av->m->log, "Set new audio bit rate %d", audio_bit_rate);
LOGGER_DEBUG(av->m->log, "Set new audio bit rate %d", bit_rate);
}

call->audio_bit_rate = audio_bit_rate;
call->audio_bit_rate = bit_rate;
pthread_mutex_unlock(call->toxav_call_mutex);
}

Expand All @@ -710,7 +710,7 @@ bool toxav_audio_set_bit_rate(ToxAV *av, uint32_t friend_number, uint32_t audio_

return rc == TOXAV_ERR_BIT_RATE_SET_OK;
}
bool toxav_video_set_bit_rate(ToxAV *av, uint32_t friend_number, uint32_t video_bit_rate,
bool toxav_video_set_bit_rate(ToxAV *av, uint32_t friend_number, uint32_t bit_rate,
Toxav_Err_Bit_Rate_Set *error)
{
Toxav_Err_Bit_Rate_Set rc = TOXAV_ERR_BIT_RATE_SET_OK;
Expand All @@ -721,7 +721,7 @@ bool toxav_video_set_bit_rate(ToxAV *av, uint32_t friend_number, uint32_t video_
goto RETURN;
}

if (video_bit_rate > 0 && video_bit_rate_invalid(video_bit_rate)) {
if (bit_rate > 0 && video_bit_rate_invalid(bit_rate)) {
rc = TOXAV_ERR_BIT_RATE_SET_INVALID_BIT_RATE;
goto RETURN;
}
Expand All @@ -735,11 +735,11 @@ bool toxav_video_set_bit_rate(ToxAV *av, uint32_t friend_number, uint32_t video_
goto RETURN;
}

LOGGER_DEBUG(av->m->log, "Setting new video bitrate to: %d", video_bit_rate);
LOGGER_DEBUG(av->m->log, "Setting new video bitrate to: %d", bit_rate);

if (call->video_bit_rate == video_bit_rate) {
LOGGER_DEBUG(av->m->log, "Video bitrate already set to: %d", video_bit_rate);
} else if (video_bit_rate == 0) {
if (call->video_bit_rate == bit_rate) {
LOGGER_DEBUG(av->m->log, "Video bitrate already set to: %d", bit_rate);
} else if (bit_rate == 0) {
LOGGER_DEBUG(av->m->log, "Turned off video sending");

/* Video sending is turned off; notify peer */
Expand All @@ -766,10 +766,10 @@ bool toxav_video_set_bit_rate(ToxAV *av, uint32_t friend_number, uint32_t video_
goto RETURN;
}
} else {
LOGGER_DEBUG(av->m->log, "Set new video bit rate %d", video_bit_rate);
LOGGER_DEBUG(av->m->log, "Set new video bit rate %d", bit_rate);
}

call->video_bit_rate = video_bit_rate;
call->video_bit_rate = bit_rate;
pthread_mutex_unlock(call->toxav_call_mutex);
}

Expand Down
2 changes: 1 addition & 1 deletion toxcore/LAN_discovery.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ Broadcast_Info *lan_discovery_init(DHT *dht);
* Clear packet handlers.
*/
non_null()
void lan_discovery_kill(DHT *dht, Broadcast_Info *info);
void lan_discovery_kill(DHT *dht, Broadcast_Info *broadcast);

/**
* Is IP a local ip or not.
Expand Down
11 changes: 4 additions & 7 deletions toxcore/Messenger.c
Original file line number Diff line number Diff line change
Expand Up @@ -1617,15 +1617,12 @@ static void do_reqchunk_filecb(Messenger *m, int32_t friendnumber, void *userdat
*/
static void break_files(const Messenger *m, int32_t friendnumber)
{
Friend *const f = &m->friendlist[friendnumber];

// TODO(irungentoo): Inform the client which file transfers get killed with a callback?
for (uint32_t i = 0; i < MAX_CONCURRENT_FILE_PIPES; ++i) {
if (m->friendlist[friendnumber].file_sending[i].status != FILESTATUS_NONE) {
m->friendlist[friendnumber].file_sending[i].status = FILESTATUS_NONE;
}

if (m->friendlist[friendnumber].file_receiving[i].status != FILESTATUS_NONE) {
m->friendlist[friendnumber].file_receiving[i].status = FILESTATUS_NONE;
}
f->file_sending[i].status = FILESTATUS_NONE;
f->file_receiving[i].status = FILESTATUS_NONE;
}
}

Expand Down
2 changes: 1 addition & 1 deletion toxcore/bin_unpack.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ non_null() bool bin_unpack_bool(bool *val, const msgpack_object *obj);
non_null() bool bin_unpack_u16(uint16_t *val, const msgpack_object *obj);
non_null() bool bin_unpack_u32(uint32_t *val, const msgpack_object *obj);
non_null() bool bin_unpack_u64(uint64_t *val, const msgpack_object *obj);
non_null() bool bin_unpack_bytes(uint8_t **data, size_t *data_length, const msgpack_object *obj);
non_null() bool bin_unpack_bytes(uint8_t **data_ptr, size_t *data_length_ptr, const msgpack_object *obj);
non_null() bool bin_unpack_bytes_fixed(uint8_t *data, uint32_t data_length, const msgpack_object *obj);

#endif // C_TOXCORE_TOXCORE_BIN_UNPACK_H
18 changes: 9 additions & 9 deletions toxcore/crypto_core.c
Original file line number Diff line number Diff line change
Expand Up @@ -190,10 +190,10 @@ int32_t encrypt_precompute(const uint8_t *public_key, const uint8_t *secret_key,
return crypto_box_beforenm(shared_key, public_key, secret_key);
}

int32_t encrypt_data_symmetric(const uint8_t *secret_key, const uint8_t *nonce,
int32_t encrypt_data_symmetric(const uint8_t *shared_key, const uint8_t *nonce,
const uint8_t *plain, size_t length, uint8_t *encrypted)
{
if (length == 0 || secret_key == nullptr || nonce == nullptr || plain == nullptr || encrypted == nullptr) {
if (length == 0 || shared_key == nullptr || nonce == nullptr || plain == nullptr || encrypted == nullptr) {
return -1;
}

Expand Down Expand Up @@ -226,7 +226,7 @@ int32_t encrypt_data_symmetric(const uint8_t *secret_key, const uint8_t *nonce,
memcpy(temp_plain + crypto_box_ZEROBYTES, plain, length);

if (crypto_box_afternm(temp_encrypted, temp_plain, length + crypto_box_ZEROBYTES, nonce,
secret_key) != 0) {
shared_key) != 0) {
crypto_free(temp_plain, size_temp_plain);
crypto_free(temp_encrypted, size_temp_encrypted);
return -1;
Expand All @@ -241,10 +241,10 @@ int32_t encrypt_data_symmetric(const uint8_t *secret_key, const uint8_t *nonce,
return length + crypto_box_MACBYTES;
}

int32_t decrypt_data_symmetric(const uint8_t *secret_key, const uint8_t *nonce,
int32_t decrypt_data_symmetric(const uint8_t *shared_key, const uint8_t *nonce,
const uint8_t *encrypted, size_t length, uint8_t *plain)
{
if (length <= crypto_box_BOXZEROBYTES || secret_key == nullptr || nonce == nullptr || encrypted == nullptr
if (length <= crypto_box_BOXZEROBYTES || shared_key == nullptr || nonce == nullptr || encrypted == nullptr
|| plain == nullptr) {
return -1;
}
Expand Down Expand Up @@ -276,7 +276,7 @@ int32_t decrypt_data_symmetric(const uint8_t *secret_key, const uint8_t *nonce,
memcpy(temp_encrypted + crypto_box_BOXZEROBYTES, encrypted, length);

if (crypto_box_open_afternm(temp_plain, temp_encrypted, length + crypto_box_BOXZEROBYTES, nonce,
secret_key) != 0) {
shared_key) != 0) {
crypto_free(temp_plain, size_temp_plain);
crypto_free(temp_encrypted, size_temp_encrypted);
return -1;
Expand Down Expand Up @@ -396,11 +396,11 @@ void crypto_sha512(uint8_t *hash, const uint8_t *data, size_t length)
crypto_hash_sha512(hash, data, length);
}

void random_bytes(uint8_t *data, size_t length)
void random_bytes(uint8_t *bytes, size_t length)
{
#ifdef FUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION
fuzz_random_bytes(data, length);
fuzz_random_bytes(bytes, length);
#else
randombytes(data, length);
randombytes(bytes, length);
#endif
}
20 changes: 10 additions & 10 deletions toxcore/events/friend_status.c
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@

struct Tox_Event_Friend_Status {
uint32_t friend_number;
Tox_User_Status connection_status;
Tox_User_Status status;
};

non_null()
Expand Down Expand Up @@ -55,16 +55,16 @@ uint32_t tox_event_friend_status_get_friend_number(const Tox_Event_Friend_Status
}

non_null()
static void tox_event_friend_status_set_connection_status(Tox_Event_Friend_Status *friend_status,
Tox_User_Status connection_status)
static void tox_event_friend_status_set_status(Tox_Event_Friend_Status *friend_status,
Tox_User_Status status)
{
assert(friend_status != nullptr);
friend_status->connection_status = connection_status;
friend_status->status = status;
}
Tox_User_Status tox_event_friend_status_get_connection_status(const Tox_Event_Friend_Status *friend_status)
Tox_User_Status tox_event_friend_status_get_status(const Tox_Event_Friend_Status *friend_status)
{
assert(friend_status != nullptr);
return friend_status->connection_status;
return friend_status->status;
}

non_null()
Expand All @@ -76,7 +76,7 @@ static void tox_event_friend_status_pack(
bin_pack_u32(mp, TOX_EVENT_FRIEND_STATUS);
bin_pack_array(mp, 2);
bin_pack_u32(mp, event->friend_number);
bin_pack_u32(mp, event->connection_status);
bin_pack_u32(mp, event->status);
}

non_null()
Expand All @@ -90,7 +90,7 @@ static bool tox_event_friend_status_unpack(
}

return bin_unpack_u32(&event->friend_number, &obj->via.array.ptr[0])
&& tox_unpack_user_status(&event->connection_status, &obj->via.array.ptr[1]);
&& tox_unpack_user_status(&event->status, &obj->via.array.ptr[1]);
}


Expand Down Expand Up @@ -187,7 +187,7 @@ bool tox_events_unpack_friend_status(Tox_Events *events, const msgpack_object *o
*****************************************************/


void tox_events_handle_friend_status(Tox *tox, uint32_t friend_number, Tox_User_Status connection_status,
void tox_events_handle_friend_status(Tox *tox, uint32_t friend_number, Tox_User_Status status,
void *user_data)
{
Tox_Events_State *state = tox_events_alloc(user_data);
Expand All @@ -201,5 +201,5 @@ void tox_events_handle_friend_status(Tox *tox, uint32_t friend_number, Tox_User_
}

tox_event_friend_status_set_friend_number(friend_status, friend_number);
tox_event_friend_status_set_connection_status(friend_status, connection_status);
tox_event_friend_status_set_status(friend_status, status);
}
Loading

0 comments on commit 8d2b1d8

Please sign in to comment.