diff options
author | peter <peter@FreeBSD.org> | 2002-08-10 03:00:55 +0000 |
---|---|---|
committer | peter <peter@FreeBSD.org> | 2002-08-10 03:00:55 +0000 |
commit | 097002081e769ea13d5d8731050ac0c5be401987 (patch) | |
tree | b5f7a4f2b3864b56e40d7870c7a611e111e4766b /sbin/ping/ping.c | |
parent | f779e835e5d8cb858cdc744d7757adf40b0fe8d7 (diff) | |
download | FreeBSD-src-097002081e769ea13d5d8731050ac0c5be401987.zip FreeBSD-src-097002081e769ea13d5d8731050ac0c5be401987.tar.gz |
Fix the broken "avoid unaligned data" fix. The problem is that the builtin
gcc memcpy "knows" about types that are supposed to be actually already
aligned and triggers alignment errors doing the memcpy itself.
"Fix" this by changing it to a bcopy(). In this case, we had:
struct timeval *tp;
struct timeval tv1;
memcpy(&tv1,tp,sizeof(tv1));
.. and since gcc *knows* that a pointer to a timeval is longword aligned
and that tv1 is longword aligned, then it can use an inline that assumes
alignment. The following works too:
cp = (char *)tp;
memcpy(&tv1,cp,sizeof(tv1));
Simply casting (char *)tp for the memcpy doesn't work. :-(
This affected different 64 bit platforms in different ways and depends
a lot on gcc as well. I've seen this on alpha and ia64 at least, although
alpha isn't doing it right now.
Diffstat (limited to 'sbin/ping/ping.c')
-rw-r--r-- | sbin/ping/ping.c | 4 |
1 files changed, 2 insertions, 2 deletions
diff --git a/sbin/ping/ping.c b/sbin/ping/ping.c index f91df86..b60766d 100644 --- a/sbin/ping/ping.c +++ b/sbin/ping/ping.c @@ -841,8 +841,8 @@ pr_pack(buf, cc, from, tv) #else tp = (struct timeval *)icp->icmp_data; #endif - /* Avoid unaligned data: */ - memcpy(&tv1,tp,sizeof(tv1)); + /* Avoid unaligned data (cannot use memcpy) */ + bcopy(tp, &tv1, sizeof(tv1)); tvsub(tv, &tv1); triptime = ((double)tv->tv_sec) * 1000.0 + ((double)tv->tv_usec) / 1000.0; |