|
Date: Sun, 5 May 2013 18:24:19 +0200 From: Szabolcs Nagy <nsz@...t70.net> To: musl@...ts.openwall.com Subject: Re: [patch] add ether_(aton, ntoa) * Strake <strake888@...il.com> [2013-05-05 09:02:04 -0500]: > On 19/04/2013, Rich Felker <dalias@...ifal.cx> 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)
Powered by blists - more mailing lists
Confused about mailing lists and their use? Read about mailing lists on Wikipedia and check out these guidelines on proper formatting of your messages.