Skip to content

Commit 623e3ee

Browse files
committed
cleanup: Don't use memcpy to cast arbitrary structs to uint8_t[].
We can memcpy integral types and array types. There's no need to directly memcpy into or from struct types.
1 parent c71567d commit 623e3ee

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

toxcore/network.c

+4-4
Original file line numberDiff line numberDiff line change
@@ -1705,7 +1705,7 @@ int unpack_ip_port(IP_Port *ip_port, const uint8_t *data, uint16_t length, bool
17051705
}
17061706

17071707
ip_port->ip.family = host_family;
1708-
memcpy(&ip_port->ip.ip.v4, data + 1, SIZE_IP4);
1708+
memcpy(ip_port->ip.ip.v4.uint8, data + 1, SIZE_IP4);
17091709
memcpy(&ip_port->port, data + 1 + SIZE_IP4, sizeof(uint16_t));
17101710
return size;
17111711
} else {
@@ -1716,7 +1716,7 @@ int unpack_ip_port(IP_Port *ip_port, const uint8_t *data, uint16_t length, bool
17161716
}
17171717

17181718
ip_port->ip.family = host_family;
1719-
memcpy(&ip_port->ip.ip.v6, data + 1, SIZE_IP6);
1719+
memcpy(ip_port->ip.ip.v6.uint8, data + 1, SIZE_IP6);
17201720
memcpy(&ip_port->port, data + 1 + SIZE_IP6, sizeof(uint16_t));
17211721
return size;
17221722
}
@@ -2059,10 +2059,10 @@ int32_t net_getipport(const Memory *mem, const char *node, IP_Port **res, int to
20592059

20602060
if (cur->ai_family == AF_INET) {
20612061
const struct sockaddr_in *addr = (const struct sockaddr_in *)(const void *)cur->ai_addr;
2062-
memcpy(&ip_port->ip.ip.v4, &addr->sin_addr, sizeof(IP4));
2062+
ip_port->ip.ip.v4.uint32 = addr->sin_addr.s_addr;
20632063
} else if (cur->ai_family == AF_INET6) {
20642064
const struct sockaddr_in6 *addr = (const struct sockaddr_in6 *)(const void *)cur->ai_addr;
2065-
memcpy(&ip_port->ip.ip.v6, &addr->sin6_addr, sizeof(IP6));
2065+
memcpy(ip_port->ip.ip.v6.uint8, addr->sin6_addr.s6_addr, sizeof(IP6));
20662066
} else {
20672067
continue;
20682068
}

0 commit comments

Comments
 (0)