Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Eli Zaretskii <eliz@gnu.org>
To: Pedro Alves <palves@redhat.com>
Cc: gdb-patches@sourceware.org
Subject: Re: [pushed] Fix struct sockaddr/sockaddr_in/sockaddr_un strict aliasing violations
Date: Sat, 07 Mar 2015 18:53:00 -0000	[thread overview]
Message-ID: <83oao4ljwg.fsf@gnu.org> (raw)
In-Reply-To: <54FB4162.5090601@redhat.com>

> Date: Sat, 07 Mar 2015 18:20:18 +0000
> From: Pedro Alves <palves@redhat.com>
> CC: gdb-patches@sourceware.org
> 
> Those are BSD socket types, they've been this way ever since BSD
> invented them.  The structs are not type compatible, even though
> they have some common fields that are are put at the same offsets,
> by design.
> 
> See e.g.:
> 
>   http://stackoverflow.com/questions/1429645/how-to-cast-sockaddr-storage-and-avoid-breaking-strict-aliasing-rules

IMO, the right way to handle this is to have our own struct (NOT
union!) with the data, and fill the correct struct from it, field by
field, when we need to pass it to a library function.

A union is just a type-cast in disguise; if using it is wrong, we
shouldn't try.  (And what if one of these days GCC will acquire a
capability to see through them?)

> It's not a C++ restriction.  The old code was invalid C code.

I'm talking about the new code.


  reply	other threads:[~2015-03-07 18:53 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-03-07 17:44 Pedro Alves
2015-03-07 18:00 ` Eli Zaretskii
2015-03-07 18:20   ` Pedro Alves
2015-03-07 18:53     ` Eli Zaretskii [this message]
2015-03-09 10:45       ` Pedro Alves
2015-03-09 11:10         ` Pedro Alves
2015-03-09 11:38           ` Pedro Alves
2015-03-09 16:04             ` Eli Zaretskii

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=83oao4ljwg.fsf@gnu.org \
    --to=eliz@gnu.org \
    --cc=gdb-patches@sourceware.org \
    --cc=palves@redhat.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