From mboxrd@z Thu Jan 1 00:00:00 1970 X-Msuck: nntp://news.gmane.org/gmane.linux.lib.musl.general/3289 Path: news.gmane.org!not-for-mail From: Szabolcs Nagy Newsgroups: gmane.linux.lib.musl.general Subject: Re: [patch] add ether_(aton, ntoa) Date: Sun, 5 May 2013 18:24:19 +0200 Message-ID: <20130505162419.GW12689@port70.net> References: <20130415014005.GR20323@brightrain.aerifal.cx> <20130420014945.GI20323@brightrain.aerifal.cx> Reply-To: musl@lists.openwall.com NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: ger.gmane.org 1367771074 8434 80.91.229.3 (5 May 2013 16:24:34 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Sun, 5 May 2013 16:24:34 +0000 (UTC) To: musl@lists.openwall.com Original-X-From: musl-return-3293-gllmg-musl=m.gmane.org@lists.openwall.com Sun May 05 18:24:34 2013 Return-path: Envelope-to: gllmg-musl@plane.gmane.org Original-Received: from mother.openwall.net ([195.42.179.200]) by plane.gmane.org with smtp (Exim 4.69) (envelope-from ) id 1UZ1jl-0002JY-4Y for gllmg-musl@plane.gmane.org; Sun, 05 May 2013 18:24:33 +0200 Original-Received: (qmail 24105 invoked by uid 550); 5 May 2013 16:24:31 -0000 Mailing-List: contact musl-help@lists.openwall.com; run by ezmlm Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: Original-Received: (qmail 24097 invoked from network); 5 May 2013 16:24:31 -0000 Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.5.21 (2010-09-15) Xref: news.gmane.org gmane.linux.lib.musl.general:3289 Archived-At: * Strake [2013-05-05 09:02:04 -0500]: > On 19/04/2013, Rich Felker wrote: > > &x has the wrong type; strtoul requires char **, not const char **. > > A separate temp var is required for the output, as in. > > > > char *y; > > n = strtoul (x, &y, 16); > > x = y; > > > > or similar. As far as I know the naive cast one could make to "fix" > > the type mismatch is not valid; it would be an aliasing violation. > > What bad could happen? the naive cast is strtoul(x, (char**)&x, 16) (const char **) and (char **) are not compatible types and they are not required to have the same representation and alignment so the conversion itself may invoke undefined behaviour but even if the representation and alignment is the same an object with effective type (const char*) cannot be accessed through a (char*) lvalue expression within strtoul so the aliasing rules are violated as well (a compiler may reorder the loads from x and the stores to *(char**)&x arbitarily)