public inbox for passt-dev@passt.top
 help / color / mirror / code / Atom feed
* [PATCH] arp, dhcp: Fix strict aliasing warnings reported by gcc 4.9 with -Ofast
@ 2022-02-28 21:19 Stefano Brivio
  0 siblings, 0 replies; only message in thread
From: Stefano Brivio @ 2022-02-28 21:19 UTC (permalink / raw)
  To: passt-dev

[-- Attachment #1: Type: text/plain, Size: 1876 bytes --]

Signed-off-by: Stefano Brivio <sbrivio(a)redhat.com>
---
 arp.c  |  3 ++-
 dhcp.c | 14 +++++++-------
 2 files changed, 9 insertions(+), 8 deletions(-)

diff --git a/arp.c b/arp.c
index b5af49f..3195692 100644
--- a/arp.c
+++ b/arp.c
@@ -58,7 +58,8 @@ int arp(struct ctx *c, struct ethhdr *eh, size_t len)
 	/* Discard announcements (but not 0.0.0.0 "probes"): we might have the
 	 * same IP address, hide that.
 	 */
-	if (*((uint32_t *)&am->sip) && !memcmp(am->sip, am->tip, 4))
+	if (memcmp(am->sip, (unsigned char[4]){ 0, 0, 0, 0 }, 4) &&
+	    !memcmp(am->sip, am->tip, 4))
 		return 1;
 
 	/* Don't resolve our own address, either. */
diff --git a/dhcp.c b/dhcp.c
index ab1249c..197a515 100644
--- a/dhcp.c
+++ b/dhcp.c
@@ -40,9 +40,9 @@
 struct opt {
 	int sent;
 	int slen;
-	unsigned char s[255];
+	uint8_t s[255];
 	int clen;
-	unsigned char c[255];
+	uint8_t c[255];
 };
 
 static struct opt opts[255];
@@ -312,9 +312,9 @@ int dhcp(struct ctx *c, struct ethhdr *eh, size_t len)
 	     m->chaddr[3], m->chaddr[4], m->chaddr[5]);
 
 	m->yiaddr = c->addr4;
-	*(unsigned long *)opts[1].s =  c->mask4;
-	*(unsigned long *)opts[3].s =  c->gw4;
-	*(unsigned long *)opts[54].s = c->gw4;
+	memcpy(opts[1].s,  &c->mask4, sizeof(c->mask4));
+	memcpy(opts[3].s,  &c->gw4,   sizeof(c->gw4));
+	memcpy(opts[54].s, &c->gw4,   sizeof(c->gw4));
 
 	/* If the gateway is not on the assigned subnet, send an option 121
 	 * (Classless Static Routing) adding a dummy route to it.
@@ -323,8 +323,8 @@ int dhcp(struct ctx *c, struct ethhdr *eh, size_t len)
 		/* a.b.c.d/32:0.0.0.0, 0:a.b.c.d */
 		opts[121].slen = 14;
 		opts[121].s[0] = 32;
-		*(unsigned long *)&opts[121].s[1] = c->gw4;
-		*(unsigned long *)&opts[121].s[10] = c->gw4;
+		memcpy(opts[121].s + 1,  &c->gw4, sizeof(c->gw4));
+		memcpy(opts[121].s + 10, &c->gw4, sizeof(c->gw4));
 	}
 
 	if (c->mtu != -1) {
-- 
@@ -40,9 +40,9 @@
 struct opt {
 	int sent;
 	int slen;
-	unsigned char s[255];
+	uint8_t s[255];
 	int clen;
-	unsigned char c[255];
+	uint8_t c[255];
 };
 
 static struct opt opts[255];
@@ -312,9 +312,9 @@ int dhcp(struct ctx *c, struct ethhdr *eh, size_t len)
 	     m->chaddr[3], m->chaddr[4], m->chaddr[5]);
 
 	m->yiaddr = c->addr4;
-	*(unsigned long *)opts[1].s =  c->mask4;
-	*(unsigned long *)opts[3].s =  c->gw4;
-	*(unsigned long *)opts[54].s = c->gw4;
+	memcpy(opts[1].s,  &c->mask4, sizeof(c->mask4));
+	memcpy(opts[3].s,  &c->gw4,   sizeof(c->gw4));
+	memcpy(opts[54].s, &c->gw4,   sizeof(c->gw4));
 
 	/* If the gateway is not on the assigned subnet, send an option 121
 	 * (Classless Static Routing) adding a dummy route to it.
@@ -323,8 +323,8 @@ int dhcp(struct ctx *c, struct ethhdr *eh, size_t len)
 		/* a.b.c.d/32:0.0.0.0, 0:a.b.c.d */
 		opts[121].slen = 14;
 		opts[121].s[0] = 32;
-		*(unsigned long *)&opts[121].s[1] = c->gw4;
-		*(unsigned long *)&opts[121].s[10] = c->gw4;
+		memcpy(opts[121].s + 1,  &c->gw4, sizeof(c->gw4));
+		memcpy(opts[121].s + 10, &c->gw4, sizeof(c->gw4));
 	}
 
 	if (c->mtu != -1) {
-- 
2.34.1


^ permalink raw reply related	[flat|nested] only message in thread

only message in thread, other threads:[~2022-02-28 21:19 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-02-28 21:19 [PATCH] arp, dhcp: Fix strict aliasing warnings reported by gcc 4.9 with -Ofast Stefano Brivio

Code repositories for project(s) associated with this public inbox

	https://passt.top/passt

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for IMAP folder(s).