[head tinderbox] failure on ia64/ia64
Andrey Simonenko
simon at comsys.ntu-kpi.kiev.ua
Tue Feb 1 10:54:26 UTC 2011
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{}.
More information about the freebsd-current
mailing list