From f46f51e554c962ee3ef60b8f01040740924eaa43 Mon Sep 17 00:00:00 2001 From: iphydf Date: Mon, 10 Jan 2022 10:50:05 +0000 Subject: [PATCH] cleanup: Don't use memcpy where assignment can be used. See https://github.com/TokTok/hs-tokstyle/pull/104. --- other/bootstrap_daemon/docker/tox-bootstrapd.sha256 | 2 +- toxcore/DHT.c | 4 +--- toxcore/TCP_server.c | 2 +- toxcore/net_crypto.c | 6 +++--- toxcore/onion_client.c | 2 +- 5 files changed, 7 insertions(+), 9 deletions(-) diff --git a/other/bootstrap_daemon/docker/tox-bootstrapd.sha256 b/other/bootstrap_daemon/docker/tox-bootstrapd.sha256 index f35ddcd4..51b032a6 100644 --- a/other/bootstrap_daemon/docker/tox-bootstrapd.sha256 +++ b/other/bootstrap_daemon/docker/tox-bootstrapd.sha256 @@ -1 +1 @@ -973f8254b9f8c50cbf0df93fb609d83bfeaeffdcbe7b836d6e0f701bdabf493f /usr/local/bin/tox-bootstrapd +c2d45e89278e21f452cce2589299648bb94c38d75b0e974fb4f1c012182543af /usr/local/bin/tox-bootstrapd diff --git a/toxcore/DHT.c b/toxcore/DHT.c index 68a16fde..05669410 100644 --- a/toxcore/DHT.c +++ b/toxcore/DHT.c @@ -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) { diff --git a/toxcore/TCP_server.c b/toxcore/TCP_server.c index 5f6ddc54..9b56e6ea 100644 --- a/toxcore/TCP_server.c +++ b/toxcore/TCP_server.c @@ -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)); } diff --git a/toxcore/net_crypto.c b/toxcore/net_crypto.c index 28653f2f..16a4a175 100644 --- a/toxcore/net_crypto.c +++ b/toxcore/net_crypto.c @@ -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)) { @@ -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; @@ -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]); diff --git a/toxcore/onion_client.c b/toxcore/onion_client.c index 83bf7488..044a27ba 100644 --- a/toxcore/onion_client.c +++ b/toxcore/onion_client.c @@ -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; }