[collectd] [PATCH] Fix gcc-4.4 strict-aliasing issue

Florian Forster octo at verplant.org
Thu Mar 12 09:01:00 CET 2009


Hi Alan,

On Wed, Mar 11, 2009 at 10:47:59AM +0100, Sebastian Harl wrote:
> Imho, this should rather be fixed in GCC.

I've looked at the code somewhat closer and apparently the issue is a
little different from what I though previously: The problem is that we
have a `sockaddr_storage', take the address of it, cast it to e. g. a
`sockaddr_in *' and then write to the struct using that address.

Apparently, the problem is that it's not a pointer to begin with, but a
statically allocated struct. Something like this would probably work (I
didn't actually try, so I might be wrong):
  struct sockaddr_storage *sas = malloc (sizeof (*sas));
  struct sockaddr_in *sai = (void *) sas;
  sai->sin_addr.s_addr = htonl (INADDR_ANY);

So, one ``clean'' way around this problem would be to use `memcpy' to
write to the struct.

When taking a closer look at the problematic code in liboping, I
realized that it was actually absolutely useless, because that
`struct sockaddr_storage' was never used again. It's a legacy from
setting the source address, which has been changed in the meantime.

Alan, could you checkout liboping and check if it still produces that
error/warning? You can get it from my Git repository:
  $ git clone git://git.verplant.org/liboping.git

Regards,
-octo
-- 
Florian octo Forster
Hacker in training
GnuPG: 0x91523C3D
http://verplant.org/
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: Digital signature
Url : http://mailman.verplant.org/pipermail/collectd/attachments/20090312/a0384722/attachment.pgp 


More information about the collectd mailing list