Skip to content

Commit

Permalink
cleanup: Don't use memcpy where assignment can be used.
Browse files Browse the repository at this point in the history
  • Loading branch information
iphydf committed Jan 10, 2022
1 parent 7411f70 commit 75a0fd8
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 8 deletions.
4 changes: 1 addition & 3 deletions toxcore/DHT.c
Original file line number Diff line number Diff line change
Expand Up @@ -1580,9 +1580,7 @@ int dht_delfriend(DHT *dht, const uint8_t *public_key, uint16_t lock_count)
--dht->num_friends;

if (dht->num_friends != friend_num) {
memcpy(&dht->friends_list[friend_num],
&dht->friends_list[dht->num_friends],
sizeof(DHT_Friend));
dht->friends_list[friend_num] = dht->friends_list[dht->num_friends];
}

if (dht->num_friends == 0) {
Expand Down
2 changes: 1 addition & 1 deletion toxcore/TCP_server.c
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ static void wipe_secure_connection(TCP_Secure_Connection *con)

static void move_secure_connection(TCP_Secure_Connection *con_new, TCP_Secure_Connection *con_old)
{
memcpy(con_new, con_old, sizeof(TCP_Secure_Connection));
*con_new = *con_old;
crypto_memzero(con_old, sizeof(TCP_Secure_Connection));
}

Expand Down
6 changes: 3 additions & 3 deletions toxcore/net_crypto.c
Original file line number Diff line number Diff line change
Expand Up @@ -755,7 +755,7 @@ static int add_data_to_buffer(const Logger *log, Packets_Array *array, uint32_t
return -1;
}

memcpy(new_d, data, sizeof(Packet_Data));
*new_d = *data;
array->buffer[num] = new_d;

if (number - array->buffer_start >= num_packets_array(array)) {
Expand Down Expand Up @@ -808,7 +808,7 @@ static int64_t add_data_end_of_buffer(const Logger *log, Packets_Array *array, c
return -1;
}

memcpy(new_d, data, sizeof(Packet_Data));
*new_d = *data;
uint32_t id = array->buffer_end;
array->buffer[id % CRYPTO_PACKET_BUFFER_SIZE] = new_d;
++array->buffer_end;
Expand All @@ -832,7 +832,7 @@ static int64_t read_data_beg_buffer(const Logger *log, Packets_Array *array, Pac
return -1;
}

memcpy(data, array->buffer[num], sizeof(Packet_Data));
*data = *array->buffer[num];
uint32_t id = array->buffer_start;
++array->buffer_start;
free(array->buffer[num]);
Expand Down
2 changes: 1 addition & 1 deletion toxcore/onion_client.c
Original file line number Diff line number Diff line change
Expand Up @@ -391,7 +391,7 @@ static int random_path(const Onion_Client *onion_c, Onion_Client_Paths *onion_pa
}

++onion_paths->last_path_used_times[pathnum];
memcpy(path, &onion_paths->paths[pathnum], sizeof(Onion_Path));
*path = onion_paths->paths[pathnum];
return 0;
}

Expand Down

0 comments on commit 75a0fd8

Please sign in to comment.