From: Mike Frysinger <vapier@gentoo.org>
To: stephen.hemminger@vyatta.com, netdev@vger.kernel.org
Subject: [PATCH] dnet: fix strict aliasing warnings
Date: Wed, 9 Jun 2010 20:52:41 -0400 [thread overview]
Message-ID: <1276131161-18135-1-git-send-email-vapier@gentoo.org> (raw)
Recent gcc doesn't like it when you cast char pointers to uint16_t
pointers and then dereference it. So use memcpy() instead and let
gcc take care of optimizing things away (when appropriate). This
should also fix alignment issues on arches where gcc packs the char
pointer tighter than 16bits.
Signed-off-by: Mike Frysinger <vapier@gentoo.org>
---
lib/dnet_ntop.c | 8 ++++++--
lib/dnet_pton.c | 5 ++++-
2 files changed, 10 insertions(+), 3 deletions(-)
diff --git a/lib/dnet_ntop.c b/lib/dnet_ntop.c
index 9500df8..507a7eb 100644
--- a/lib/dnet_ntop.c
+++ b/lib/dnet_ntop.c
@@ -1,4 +1,5 @@
#include <errno.h>
+#include <string.h>
#include <sys/types.h>
#include <netinet/in.h>
@@ -35,11 +36,14 @@ static __inline__ int do_digit(char *str, u_int16_t *addr, u_int16_t scale, size
static const char *dnet_ntop1(const struct dn_naddr *dna, char *str, size_t len)
{
- u_int16_t addr = dn_ntohs(*(u_int16_t *)dna->a_addr);
- u_int16_t area = addr >> 10;
+ u_int16_t addr, area;
size_t pos = 0;
int started = 0;
+ memcpy(&addr, dna->a_addr, sizeof(addr));
+ addr = dn_ntohs(addr);
+ area = addr >> 10;
+
if (dna->a_len != 2)
return NULL;
diff --git a/lib/dnet_pton.c b/lib/dnet_pton.c
index bd7727a..7385756 100644
--- a/lib/dnet_pton.c
+++ b/lib/dnet_pton.c
@@ -1,4 +1,5 @@
#include <errno.h>
+#include <string.h>
#include <sys/types.h>
#include <netinet/in.h>
@@ -37,6 +38,7 @@ static int dnet_num(const char *src, u_int16_t * dst)
static int dnet_pton1(const char *src, struct dn_naddr *dna)
{
+ u_int16_t addr;
u_int16_t area = 0;
u_int16_t node = 0;
int pos;
@@ -48,7 +50,8 @@ static int dnet_pton1(const char *src, struct dn_naddr *dna)
if ((pos == 0) || (node > 1023))
return 0;
dna->a_len = 2;
- *(u_int16_t *)dna->a_addr = dn_htons((area << 10) | node);
+ addr = dn_htons((area << 10) | node);
+ memcpy(dna->a_addr, &addr, sizeof(addr));
return 1;
}
--
1.7.1
reply other threads:[~2010-06-10 0:53 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1276131161-18135-1-git-send-email-vapier@gentoo.org \
--to=vapier@gentoo.org \
--cc=netdev@vger.kernel.org \
--cc=stephen.hemminger@vyatta.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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 NNTP newsgroup(s).