mirror of
https://github.com/freebsd/freebsd-src
synced 2024-07-23 03:06:48 +00:00
Cast pointer to uintptr_t to avoid alignment warnings.
Both struct ip and struct udphdr both have an aligment of 2, but the cast from struct ip to a uint32_t pointer confused GCC 9 into raising the required alignment to 4 and then raising a -Waddress-of-packed-member error when casting to struct udphdr. Reviewed by: imp Differential Revision: https://reviews.freebsd.org/D31941
This commit is contained in:
parent
cd0525f615
commit
dba02df30d
|
@ -109,9 +109,9 @@ ip_packet(u_char protocol, size_t len)
|
||||||
|
|
||||||
struct udphdr *
|
struct udphdr *
|
||||||
set_udp(struct ip *p, u_short sport, u_short dport) {
|
set_udp(struct ip *p, u_short sport, u_short dport) {
|
||||||
uint32_t *up = (void *)p;
|
int hlen = p->ip_hl << 2;
|
||||||
struct udphdr *u = (void *)&(up[p->ip_hl]);
|
struct udphdr *u = (struct udphdr *)((uintptr_t)p + hlen);
|
||||||
int payload = ntohs(p->ip_len) - 4*p->ip_hl;
|
int payload = ntohs(p->ip_len) - hlen;
|
||||||
|
|
||||||
REQUIRE(payload >= (int)sizeof(*u));
|
REQUIRE(payload >= (int)sizeof(*u));
|
||||||
p->ip_p = IPPROTO_UDP;
|
p->ip_p = IPPROTO_UDP;
|
||||||
|
|
Loading…
Reference in a new issue