[SLOF] [PATCH] libnet: Fix compiler warnings with GCC 9

Segher Boessenkool segher at kernel.crashing.org
Mon Sep 23 20:49:01 AEST 2019


On Mon, Sep 23, 2019 at 08:16:21AM +0200, Thomas Huth wrote:
> > Or disable this particular warning. What exactly
> > does it protect against?
> If I've googled it right, assigning an unaligned pointer value is
> undefined behavior according to the C standard. So the compiler could do
> weird stuff if we simply ignore it.

It is UB indeed, see C11 6.3.2.3/7:
    A pointer to an object type may be converted to a pointer to a
    different object type.  If the resulting pointer is not correctly
    aligned for the referenced type, the behavior is undefined.

I like to point people to
  https://commandcenter.blogspot.com/2012/04/byte-order-fallacy.html
for how to avoid causing such silly problems in the first place.


Segher


More information about the SLOF mailing list