From owner-freebsd-alpha Sun Jun 23 12: 7:33 2002 Delivered-To: freebsd-alpha@freebsd.org Received: from srv1.cosmo-project.de (srv1.cosmo-project.de [213.83.6.106]) by hub.freebsd.org (Postfix) with ESMTP id 0B86237B429 for ; Sun, 23 Jun 2002 12:06:22 -0700 (PDT) Received: from cicely5.cicely.de (cicely5.cicely.de [IPv6:3ffe:400:8d0:301:200:92ff:fe9b:20e7]) (authenticated bits=0) by srv1.cosmo-project.de (8.12.3/8.12.3) with ESMTP id g5NJ6HMa063564 (version=TLSv1/SSLv3 cipher=EDH-RSA-DES-CBC3-SHA bits=168 verify=OK); Sun, 23 Jun 2002 21:06:19 +0200 (CEST) (envelope-from ticso@cicely5.cicely.de) Received: from cicely5.cicely.de (localhost [IPv6:::1]) by cicely5.cicely.de (8.12.1/8.12.1) with ESMTP id g5NJ6GFJ024504 (version=TLSv1/SSLv3 cipher=EDH-RSA-DES-CBC3-SHA bits=168 verify=NO); Sun, 23 Jun 2002 21:06:16 +0200 (CEST)?g (envelope-from ticso@cicely5.cicely.de) Received: (from ticso@localhost) by cicely5.cicely.de (8.12.1/8.12.1/Submit) id g5NJ6FeT024503; Sun, 23 Jun 2002 21:06:15 +0200 (CEST)?g (envelope-from ticso) Date: Sun, 23 Jun 2002 21:06:15 +0200 From: Bernd Walter To: Christian Weisgerber Cc: freebsd-alpha@FreeBSD.ORG Subject: Re: -CURRENT: UA in locate Message-ID: <20020623190614.GW53233@cicely5.cicely.de> Reply-To: ticso@cicely.de References: Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Operating-System: FreeBSD cicely5.cicely.de 5.0-CURRENT i386 User-Agent: Mutt/1.5.1i Sender: owner-freebsd-alpha@FreeBSD.ORG Precedence: bulk List-ID: List-Archive: (Web Archive) List-Help: (List Instructions) List-Subscribe: List-Unsubscribe: X-Loop: FreeBSD.org On Sun, Jun 23, 2002 at 04:49:26PM +0000, Christian Weisgerber wrote: > The locate(1) command throws unaligned access errors in -CURRENT. > This has probably been triggered by the switch to gcc 3.1. > > Here's a diff with extended context to show what's going on: > > Index: util.c > =================================================================== > RCS file: /cvs/src/usr.bin/locate/locate/util.c,v > retrieving revision 1.9 > diff -u -U9 -r1.9 util.c > --- util.c 22 Mar 2002 01:22:48 -0000 1.9 > +++ util.c 23 Jun 2002 16:33:24 -0000 > @@ -225,19 +225,19 @@ > * Convert network byte order to host byte order if neccessary. > * So we can read on FreeBSD/i386 (little endian) a locate database > * which was built on SunOS/sparc (big endian). > */ > > int > getwm(p) > caddr_t p; > { > - static char buf[INTSIZE]; > + char buf[INTSIZE]; > register int i; > > for (i = 0; i < INTSIZE; i++) > buf[i] = *p++; > > i = *(int *)buf; > > if (i > MAXPATHLEN || i < -(MAXPATHLEN)) { > i = ntohl(i); > =================================================================== > > Apparently the author assumed that buf[] would be properly aligned, > so that dereferencing an integer pointer would be safe. I'm at a > loss how somebody can arrive at this assumption for a static object. > For an automatic variable on the other hand it is a reasonable > guess. > > Is that fix okay, or should we play games with "int buf; (char *)&buf"? The fix doesn't change the alignment contraints. Either make it a union with a stronger aligned type or malloc() it. But malloc'ing just an int is silly. It's used as an int later so it should be either be a union with an int or just an int and cast inside the loop as you already wrote. -- B.Walter COSMO-Project http://www.cosmo-project.de ticso@cicely.de Usergroup info@cosmo-project.de To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-alpha" in the body of the message