Re: [head tinderbox] failure on ia64/ia64

From: Andrey Simonenko <simon_at_comsys.ntu-kpi.kiev.ua>
Date: Tue, 1 Feb 2011 12:28:15 +0200
On Mon, Jan 31, 2011 at 04:56:06PM -0800, Marcel Moolenaar wrote:
> 
> Take the statement at line 116 for example:
> 	*((int *)CMSG_DATA(cmsg)) = fd;
> 
> We're effectively casting from a (char *) to a (int *) and then doing
> a 32-bit access (write). The easy fix (casting through (void *) is not
> possible, because you cannot guarantee that the address is properly
> aligned. cmsg points to memory set aside by the following local
> variable:
> 	unsigned char ctrl[CMSG_SPACE(sizeof(fd))];
> 
> There's no guarantee that the compiler will align the character array
> at a 32-bit boundary (though in practice it seems to be). I have seen
> this kind of construct fail on ARM and PowerPC for example.
> 

Why not to use such declaration:

	union {
		struct cmsghdr cm;
		char ctrl[CMSG_SPACE(sizeof(fd))];
	} control_un;

At least this is necessary to satisfy that CMSG_FIRSTHDR() will give
address of correctly aligned struct cmsghdr{}.
Received on Tue Feb 01 2011 - 09:54:26 UTC

This archive was generated by hypermail 2.4.0 : Wed May 19 2021 - 11:40:11 UTC