Re-introduced bugs by merging s3 and s4 libraries :-((

Volker Lendecke Volker.Lendecke at SerNet.DE
Tue Mar 3 12:35:44 GMT 2009


On Tue, Mar 03, 2009 at 07:08:50AM -0500, Derrell Lipman wrote:
> > With your merge of convert_string_talloc you re-introduced a
> > bug that we got rid of in S3 long ago: convert_string_talloc
> > and others now take a void ** as destination pointer. This
> > is not portable C.
> >
> 
> Volker, can you point me to the non-portability issues you've seen with
> void**? It is easy to misuse void*, for example by assigning a function
> pointer to it (that's illegal in C), but if void* is used properly then I
> believe that void** should be portable. I'm really interested in where you
> saw problems.

void** as such is not the problem, it is void** as a
function argument. You might want to look at the gcc manpage
for the optimization switch -fstrict-aliasing. This is why I
always ask people to compile with -O3, this reveals tons of
warnings like the "dereferencing type-punned pointer will
break strict-aliasing rules" one that this bug
re-introduced.

What does that warning mean: C allows the compiler to assume
that an object is only ever pointed at by pointers of the
same type.

Later gcc versions according to the manpages do
optimizations based on this assumption. void* and char*
break this permission to assume this, so for everything that
you need to cast, like the struct sockaddr* argument passed
to connect(2) for example, you need to cast via void* or
char*. If you have a function that takes void** as a
parameter, there is no way to do a proper cast that breaks
the permission to assume the equality of pointer types.

As a side note, casting a function pointer to any data
pointer like void* or the other way round is also not
portable C. This would work on all platforms we have right
now, but some old memory models had for example 16 bit wide
data pointers and 32 bit wide function pointers. You can't
portably cast between those two.

Hope that helps,

Volker
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: not available
Url : http://lists.samba.org/archive/samba-technical/attachments/20090303/71735bf9/attachment.bin


More information about the samba-technical mailing list