lwip-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: RE: [lwip-devel] [bug #26273] etharp.c : fix alignment issue in etha


From: Simon Goldschmidt
Subject: Re: RE: [lwip-devel] [bug #26273] etharp.c : fix alignment issue in etharp_raw
Date: Wed, 22 Apr 2009 09:29:19 +0200

> Casting pointers is not guaranteed to conform to alignment restrictions of
> the target processor.  Non-casted pointers to char, short, int, and long
> as well as implicit casts to these are safe.  If you can use standard C
> constructs without casts, it should both be portable and work on all 
> platforms.
>  A bad aspect of C is that it has some portability shortcomings - pointer
> casting and bit-fields come to mind.  I always try to avoid all pointer
> casts other than to void * and char *.

The issue here is that a 4-byte-aligned struct is casted to a 2-byte-aligned 
struct and copied (using operator=) to another 2-byte-aligned struct. However, 
the compiler seems to somehow think it has to copy to a 4-byte-aligned struct 
and corrupts memory.

I don't think that has to do with portability of casts, but rather think it's a 
bug in the compiler's implementation of operator= for structs...

Anyway, the only real portable solution seems to be using memcpy, although I'm 
not a friend of that :-(

Simon
-- 
Psssst! Schon vom neuen GMX MultiMessenger gehört? Der kann`s mit allen: 
http://www.gmx.net/de/go/multimessenger01




reply via email to

[Prev in Thread] Current Thread [Next in Thread]