Skip to content

Commit f46f51e

Browse files
committed
cleanup: Don't use memcpy where assignment can be used.
See TokTok/hs-tokstyle#104.
1 parent 7411f70 commit f46f51e

File tree

5 files changed

+7
-9
lines changed

5 files changed

+7
-9
lines changed
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
973f8254b9f8c50cbf0df93fb609d83bfeaeffdcbe7b836d6e0f701bdabf493f /usr/local/bin/tox-bootstrapd
1+
c2d45e89278e21f452cce2589299648bb94c38d75b0e974fb4f1c012182543af /usr/local/bin/tox-bootstrapd

toxcore/DHT.c

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1580,9 +1580,7 @@ int dht_delfriend(DHT *dht, const uint8_t *public_key, uint16_t lock_count)
15801580
--dht->num_friends;
15811581

15821582
if (dht->num_friends != friend_num) {
1583-
memcpy(&dht->friends_list[friend_num],
1584-
&dht->friends_list[dht->num_friends],
1585-
sizeof(DHT_Friend));
1583+
dht->friends_list[friend_num] = dht->friends_list[dht->num_friends];
15861584
}
15871585

15881586
if (dht->num_friends == 0) {

toxcore/TCP_server.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ static void wipe_secure_connection(TCP_Secure_Connection *con)
154154

155155
static void move_secure_connection(TCP_Secure_Connection *con_new, TCP_Secure_Connection *con_old)
156156
{
157-
memcpy(con_new, con_old, sizeof(TCP_Secure_Connection));
157+
*con_new = *con_old;
158158
crypto_memzero(con_old, sizeof(TCP_Secure_Connection));
159159
}
160160

toxcore/net_crypto.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -755,7 +755,7 @@ static int add_data_to_buffer(const Logger *log, Packets_Array *array, uint32_t
755755
return -1;
756756
}
757757

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

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

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

835-
memcpy(data, array->buffer[num], sizeof(Packet_Data));
835+
*data = *array->buffer[num];
836836
uint32_t id = array->buffer_start;
837837
++array->buffer_start;
838838
free(array->buffer[num]);

toxcore/onion_client.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -391,7 +391,7 @@ static int random_path(const Onion_Client *onion_c, Onion_Client_Paths *onion_pa
391391
}
392392

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

0 commit comments

Comments
 (0)