Skip to content

Commit

Permalink
cleanup: Use explicit 0 instead of PACKET_ID_PADDING.
Browse files Browse the repository at this point in the history
Calling it a packet ID is a lie, and we'd rather "memzero" than memset
with some named value that happens to be 0.
  • Loading branch information
iphydf committed Jan 24, 2024
1 parent 6370d0f commit a7258e4
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 3 deletions.
4 changes: 2 additions & 2 deletions toxcore/net_crypto.c
Original file line number Diff line number Diff line change
Expand Up @@ -1139,7 +1139,7 @@ static int send_data_packet_helper(Net_Crypto *c, int crypt_connection_id, uint3
VLA(uint8_t, packet, sizeof(uint32_t) + sizeof(uint32_t) + padding_length + length);
memcpy(packet, &buffer_start, sizeof(uint32_t));
memcpy(packet + sizeof(uint32_t), &num, sizeof(uint32_t));
memset(packet + (sizeof(uint32_t) * 2), PACKET_ID_PADDING, padding_length);
memset(packet + (sizeof(uint32_t) * 2), 0, padding_length);
memcpy(packet + (sizeof(uint32_t) * 2) + padding_length, data, length);

return send_data_packet(c, crypt_connection_id, packet, SIZEOF_VLA(packet));
Expand Down Expand Up @@ -1589,7 +1589,7 @@ static int handle_data_packet_core(Net_Crypto *c, int crypt_connection_id, const
const uint8_t *real_data = data + (sizeof(uint32_t) * 2);
uint16_t real_length = len - (sizeof(uint32_t) * 2);

while (real_data[0] == PACKET_ID_PADDING) { /* Remove Padding */
while (real_data[0] == 0) { /* Remove Padding */
++real_data;
--real_length;

Expand Down
1 change: 0 additions & 1 deletion toxcore/net_crypto.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@
/*** Messages. */

typedef enum Packet_Id {
PACKET_ID_PADDING = 0, // Denotes padding
PACKET_ID_REQUEST = 1, // Used to request unreceived packets
PACKET_ID_KILL = 2, // Used to kill connection

Expand Down

0 comments on commit a7258e4

Please sign in to comment.