From owner-svn-src-all@freebsd.org Thu Mar 5 18:30:47 2020 Return-Path: Delivered-To: svn-src-all@mailman.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.nyi.freebsd.org (Postfix) with ESMTP id EF74D248425; Thu, 5 Mar 2020 18:30:47 +0000 (UTC) (envelope-from slw@zxy.spb.ru) Received: from zxy.spb.ru (zxy.spb.ru [195.70.199.98]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 48YK7T5cTdz3y5q; Thu, 5 Mar 2020 18:30:45 +0000 (UTC) (envelope-from slw@zxy.spb.ru) Received: from slw by zxy.spb.ru with local (Exim 4.86 (FreeBSD)) (envelope-from ) id 1j9vGb-0003xr-DL; Thu, 05 Mar 2020 21:30:41 +0300 Date: Thu, 5 Mar 2020 21:30:41 +0300 From: Slawa Olhovchenkov To: Dimitry Andric Cc: Gleb Smirnoff , svn-src-head , svn-src-all , src-committers@freebsd.org Subject: Re: svn commit: r358655 - head/sbin/mount_nfs Message-ID: <20200305183041.GU8012@zxy.spb.ru> 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> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1A13B93C-7D87-4210-AD3D-2B198C166CE1@FreeBSD.org> User-Agent: Mutt/1.5.24 (2015-08-30) X-SA-Exim-Connect-IP: X-SA-Exim-Mail-From: slw@zxy.spb.ru X-SA-Exim-Scanned: No (on zxy.spb.ru); SAEximRunCond expanded to false X-Rspamd-Queue-Id: 48YK7T5cTdz3y5q X-Spamd-Bar: ---- Authentication-Results: mx1.freebsd.org; none X-Spamd-Result: default: False [-4.20 / 15.00]; NEURAL_HAM_LONG(-1.00)[-1.000,0]; REPLY(-4.00)[]; NEURAL_SPAM_MEDIUM(0.80)[0.800,0] X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 05 Mar 2020 18:30:48 -0000 On Thu, Mar 05, 2020 at 07:19:59PM +0100, Dimitry Andric wrote: > On 5 Mar 2020, at 18:44, Gleb Smirnoff 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)