Fwd: Re: Bug in r244780

Diane Bruce db at db.net
Sun Dec 30 20:04:05 UTC 2012


On Sat, Dec 29, 2012 at 08:17:18PM +0100, Christoph Mallon wrote:
> On 29.12.2012 17:02, Diane Bruce wrote:
> >>  	/* Create new group and copy old group into it. */
> >> -	if ((newgr = malloc(len)) == NULL)
> >> +	if ((dst = malloc(len)) == NULL)
> >>  		return (NULL);
> >> +	newgr = (struct group*)dst;
> > 
> > Unfortunately the new compiler (clang) will error out on this. It's
> > really anal. The error will be that it cannot convert char * alignment
> > to struct group * alignment. 1 vs. 4 (or 8). BTDT
> 
> This sounds like a bug.
> First, it should not be an error, but at most a warning.

Please take this up with toolchain at FreeBSD.org

> Second, the cast is fine, as the pointer itself is a result of malloc().
> Obviously clang only checks the type of the variable.
> Probably, the diagnostic can be suppressed with an intermediate cast to void*.
> Third, the other casts (newgr + 1 casted to a char** and so on) are borderline invalid due to strict aliasing rules.
> Therefore I prefer my method of chopping off bytes of a char buffer instead of munging differently typed pointers.
> 
> 	Christoph

- Diane
-- 
- db at FreeBSD.org db at db.net http://www.db.net/~db


More information about the freebsd-toolchain mailing list