Skip to content

Commit

Permalink
cleanup: Small improvements found by PVS Studio.
Browse files Browse the repository at this point in the history
  • Loading branch information
iphydf committed Feb 11, 2024
1 parent 8201019 commit 961891d
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 21 deletions.
8 changes: 2 additions & 6 deletions toxcore/announce.c
Original file line number Diff line number Diff line change
Expand Up @@ -239,9 +239,7 @@ bool announce_store_data(Announcements *announce, const uint8_t *data_public_key
if (length > 0) {
assert(data != nullptr);

if (entry->data != nullptr) {
free(entry->data);
}
free(entry->data);

uint8_t *entry_data = (uint8_t *)malloc(length);

Expand Down Expand Up @@ -702,9 +700,7 @@ void kill_announcements(Announcements *announce)
shared_key_cache_free(announce->shared_keys);

for (uint32_t i = 0; i < ANNOUNCE_BUCKETS * ANNOUNCE_BUCKET_SIZE; ++i) {
if (announce->entries[i].data != nullptr) {
free(announce->entries[i].data);
}
free(announce->entries[i].data);
}

free(announce);
Expand Down
4 changes: 1 addition & 3 deletions toxcore/group_connection.c
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,7 @@ static bool array_entry_is_empty(const GC_Message_Array_Entry *array_entry)
non_null()
static void clear_array_entry(GC_Message_Array_Entry *const array_entry)
{
if (array_entry->data != nullptr) {
free(array_entry->data);
}
free(array_entry->data);

*array_entry = (GC_Message_Array_Entry) {
nullptr
Expand Down
4 changes: 1 addition & 3 deletions toxcore/group_moderation.c
Original file line number Diff line number Diff line change
Expand Up @@ -864,9 +864,7 @@ uint16_t sanctions_list_replace_sig(Moderation *moderation, const uint8_t *publi

void sanctions_list_cleanup(Moderation *moderation)
{
if (moderation->sanctions != nullptr) {
free(moderation->sanctions);
}
free(moderation->sanctions);

moderation->sanctions = nullptr;
moderation->num_sanctions = 0;
Expand Down
9 changes: 3 additions & 6 deletions toxcore/network_test_util.cc
Original file line number Diff line number Diff line change
Expand Up @@ -106,14 +106,11 @@ IP_Port random_ip_port(const Random *rng)
return ip_port;
}

bool operator==(Family const &a, Family const &b) { return a.value == b.value; }
bool operator==(Family a, Family b) { return a.value == b.value; }

bool operator==(IP4 const &a, IP4 const &b) { return a.uint32 == b.uint32; }
bool operator==(IP4 a, IP4 b) { return a.uint32 == b.uint32; }

bool operator==(IP6 const &a, IP6 const &b)
{
return a.uint64[0] == b.uint64[0] && a.uint64[1] == b.uint64[1];
}
bool operator==(IP6 a, IP6 b) { return a.uint64[0] == b.uint64[0] && a.uint64[1] == b.uint64[1]; }

bool operator==(IP const &a, IP const &b)
{
Expand Down
6 changes: 3 additions & 3 deletions toxcore/network_test_util.hh
Original file line number Diff line number Diff line change
Expand Up @@ -83,10 +83,10 @@ public:
IP_Port operator()();
};

bool operator==(Family const &a, Family const &b);
bool operator==(Family a, Family b);

bool operator==(IP4 const &a, IP4 const &b);
bool operator==(IP6 const &a, IP6 const &b);
bool operator==(IP4 a, IP4 b);
bool operator==(IP6 a, IP6 b);
bool operator==(IP const &a, IP const &b);
bool operator==(IP_Port const &a, IP_Port const &b);

Expand Down

0 comments on commit 961891d

Please sign in to comment.