From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 66118 invoked by alias); 7 Mar 2015 18:53:03 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Received: (qmail 66101 invoked by uid 89); 7 Mar 2015 18:53:02 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-2.5 required=5.0 tests=AWL,BAYES_00,RCVD_IN_DNSWL_NONE,SPF_SOFTFAIL autolearn=no version=3.3.2 X-HELO: mtaout29.012.net.il Received: from mtaout29.012.net.il (HELO mtaout29.012.net.il) (80.179.55.185) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Sat, 07 Mar 2015 18:53:01 +0000 Received: from conversion-daemon.mtaout29.012.net.il by mtaout29.012.net.il (HyperSendmail v2007.08) id <0NKU00500UIKYC00@mtaout29.012.net.il> for gdb-patches@sourceware.org; Sat, 07 Mar 2015 20:49:05 +0200 (IST) Received: from HOME-C4E4A596F7 ([87.69.4.28]) by mtaout29.012.net.il (HyperSendmail v2007.08) with ESMTPA id <0NKU00MKNUXTCC90@mtaout29.012.net.il>; Sat, 07 Mar 2015 20:49:05 +0200 (IST) Date: Sat, 07 Mar 2015 18:53:00 -0000 From: Eli Zaretskii Subject: Re: [pushed] Fix struct sockaddr/sockaddr_in/sockaddr_un strict aliasing violations In-reply-to: <54FB4162.5090601@redhat.com> To: Pedro Alves Cc: gdb-patches@sourceware.org Reply-to: Eli Zaretskii Message-id: <83oao4ljwg.fsf@gnu.org> References: <1425750266-14385-1-git-send-email-palves@redhat.com> <83r3t0lmb9.fsf@gnu.org> <54FB4162.5090601@redhat.com> X-IsSubscribed: yes X-SW-Source: 2015-03/txt/msg00198.txt.bz2 > Date: Sat, 07 Mar 2015 18:20:18 +0000 > From: Pedro Alves > 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.