Skip to content

Commit 961891d

Browse files
committed
cleanup: Small improvements found by PVS Studio.
1 parent 8201019 commit 961891d

File tree

5 files changed

+10
-21
lines changed

5 files changed

+10
-21
lines changed

toxcore/announce.c

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -239,9 +239,7 @@ bool announce_store_data(Announcements *announce, const uint8_t *data_public_key
239239
if (length > 0) {
240240
assert(data != nullptr);
241241

242-
if (entry->data != nullptr) {
243-
free(entry->data);
244-
}
242+
free(entry->data);
245243

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

@@ -702,9 +700,7 @@ void kill_announcements(Announcements *announce)
702700
shared_key_cache_free(announce->shared_keys);
703701

704702
for (uint32_t i = 0; i < ANNOUNCE_BUCKETS * ANNOUNCE_BUCKET_SIZE; ++i) {
705-
if (announce->entries[i].data != nullptr) {
706-
free(announce->entries[i].data);
707-
}
703+
free(announce->entries[i].data);
708704
}
709705

710706
free(announce);

toxcore/group_connection.c

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,7 @@ static bool array_entry_is_empty(const GC_Message_Array_Entry *array_entry)
4141
non_null()
4242
static void clear_array_entry(GC_Message_Array_Entry *const array_entry)
4343
{
44-
if (array_entry->data != nullptr) {
45-
free(array_entry->data);
46-
}
44+
free(array_entry->data);
4745

4846
*array_entry = (GC_Message_Array_Entry) {
4947
nullptr

toxcore/group_moderation.c

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -864,9 +864,7 @@ uint16_t sanctions_list_replace_sig(Moderation *moderation, const uint8_t *publi
864864

865865
void sanctions_list_cleanup(Moderation *moderation)
866866
{
867-
if (moderation->sanctions != nullptr) {
868-
free(moderation->sanctions);
869-
}
867+
free(moderation->sanctions);
870868

871869
moderation->sanctions = nullptr;
872870
moderation->num_sanctions = 0;

toxcore/network_test_util.cc

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -106,14 +106,11 @@ IP_Port random_ip_port(const Random *rng)
106106
return ip_port;
107107
}
108108

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

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

113-
bool operator==(IP6 const &a, IP6 const &b)
114-
{
115-
return a.uint64[0] == b.uint64[0] && a.uint64[1] == b.uint64[1];
116-
}
113+
bool operator==(IP6 a, IP6 b) { return a.uint64[0] == b.uint64[0] && a.uint64[1] == b.uint64[1]; }
117114

118115
bool operator==(IP const &a, IP const &b)
119116
{

toxcore/network_test_util.hh

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -83,10 +83,10 @@ public:
8383
IP_Port operator()();
8484
};
8585

86-
bool operator==(Family const &a, Family const &b);
86+
bool operator==(Family a, Family b);
8787

88-
bool operator==(IP4 const &a, IP4 const &b);
89-
bool operator==(IP6 const &a, IP6 const &b);
88+
bool operator==(IP4 a, IP4 b);
89+
bool operator==(IP6 a, IP6 b);
9090
bool operator==(IP const &a, IP const &b);
9191
bool operator==(IP_Port const &a, IP_Port const &b);
9292

0 commit comments

Comments
 (0)