Date: Thu, 5 Mar 2020 21:30:41 +0300 From: Slawa Olhovchenkov <slw@zxy.spb.ru> To: Dimitry Andric <dim@FreeBSD.org> Cc: Gleb Smirnoff <glebius@FreeBSD.org>, svn-src-head <svn-src-head@freebsd.org>, svn-src-all <svn-src-all@freebsd.org>, src-committers@freebsd.org Subject: Re: svn commit: r358655 - head/sbin/mount_nfs Message-ID: <20200305183041.GU8012@zxy.spb.ru> In-Reply-To: <1A13B93C-7D87-4210-AD3D-2B198C166CE1@FreeBSD.org> References: <202003042227.024MRGsW072613@repo.freebsd.org> <244e28ea-1217-cefc-354e-02ecb201637a@FreeBSD.org> <20200305163350.GU5741@FreeBSD.org> <20200305172454.GJ8028@zxy.spb.ru> <20200305173515.GK8028@zxy.spb.ru> <20200305174411.GV5741@FreeBSD.org> <1A13B93C-7D87-4210-AD3D-2B198C166CE1@FreeBSD.org>
next in thread | previous in thread | raw e-mail | index | archive | help
On Thu, Mar 05, 2020 at 07:19:59PM +0100, Dimitry Andric wrote: > On 5 Mar 2020, at 18:44, Gleb Smirnoff <glebius@FreeBSD.org> wrote: > > > > On Thu, Mar 05, 2020 at 08:35:15PM +0300, Slawa Olhovchenkov wrote: > > S> > > D> sbin/mount_nfs/mount_nfs.c:549:10: error: cast from 'char *' to 'struct > > S> > > D> if_msghdr *' increases required alignment from 1 to 4 > > S> > > D> [-Werror,-Wcast-align] > > S> > > D> ifm = (struct if_msghdr *)buf; > > S> > > D> ^~~~~~~~~~~~~~~~~~~~~~~ > > S> > > D> 1 error generated. > > S> > > D> > > S> > > D> In practice I don't think the buffer can ever get misaligned, so can you > > S> > > D> please add a NO_WCAST_ALIGN= to the Makefile? > > S> > > > > S> > > route(8) handles the same problem via intermediate (void *) cast. What is > > S> > > preferred way to solve the problem? Change compiler flags file wide, or > > S> > > just through (void *) cast? > > S> > > > S> > Copy to aligned buffer or got SIGBUS on some architectures? > > S> > > S> char buf[2048] __aligned(__alignof(struct if_msghdr)); > > S> > > S> resolve this watning. > > > > Thanks, Slawa! I think this is the most elegant solution. > > Why don't just declare the buffer as: > > struct if_msghdr buf; > > and then do: > > nread = read(s, &buf, sizeof buf); > > ? You are never reading more than one if_msghdr anyway, and then there > is no need to cast anything. My inspiration: route socket can return other messages (man 4 route)
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20200305183041.GU8012>