From owner-freebsd-audit Mon Sep 3 14:20:55 2001 Delivered-To: freebsd-audit@freebsd.org Received: from green.bikeshed.org (freefall.freebsd.org [216.136.204.21]) by hub.freebsd.org (Postfix) with ESMTP id B50EF37B403; Mon, 3 Sep 2001 14:20:51 -0700 (PDT) Received: from localhost (green@localhost) by green.bikeshed.org (8.11.4/8.11.1) with ESMTP id f83LKoS53035; Mon, 3 Sep 2001 17:20:50 -0400 (EDT) (envelope-from green@green.bikeshed.org) Message-Id: <200109032120.f83LKoS53035@green.bikeshed.org> X-Mailer: exmh version 2.5 07/13/2001 with nmh-1.0.4 To: Warner Losh Cc: Mike Barcroft , David Hill , audit@FreeBSD.ORG Subject: Re: users.c PATCH - please review In-Reply-To: Message from Warner Losh of "Sun, 02 Sep 2001 20:35:14 MDT." <200109030235.f832ZFh22600@harmony.village.org> From: "Brian F. Feldman" Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Date: Mon, 03 Sep 2001 17:20:50 -0400 Sender: owner-freebsd-audit@FreeBSD.ORG Precedence: bulk List-ID: List-Archive: (Web Archive) List-Help: (List Instructions) List-Subscribe: List-Unsubscribe: X-Loop: FreeBSD.ORG Warner Losh wrote: > In message <20010901125802.F85574@coffee.q9media.com> Mike Barcroft writes: > : David Hill writes: > : > I have patched users/users.c so that it will compile under WARNS?=2. I have both attached and cut/pasted it to the message. > : > Please review it. > : > : > diff -ru /usr/src/usr.bin/users.orig/users.c /usr/src/usr.bin/users/users.c > : > --- /usr/src/usr.bin/users.orig/users.c Fri Aug 27 21:07:14 1999 > : > +++ /usr/src/usr.bin/users/users.c Fri Aug 31 15:58:20 2001 > : > @@ -117,5 +117,8 @@ > : > scmp(p, q) > : > const void *p, *q; > : > { > : > - return(strncmp((char *)p, (char *)q, UT_NAMESIZE)); > : > + const char *const pp1 = p; > : > + const char *const pp2 = q; > : > + > : > + return(strncmp(pp1, pp2, UT_NAMESIZE)); > : > } > : > : Why create new local variables? Just get rid of the bogus casts. > > Why not just > return (strncmp((const char *)p, (const char *)q, UT_NAMESIZE)); > > Also, const char *const is wrong. No need for the second const. Technically, there's nothing wrong with declaring "a const pointer to a const character", just casting to that would be very strange (and probably illegal; not sure). In any case, I'm not sure I see the point of not just using two (const char *) casts and not increasing the function size other than adding a blank line and space for style(9). That should remove any warning about casting away const qualification. -- Brian Fundakowski Feldman \ FreeBSD: The Power to Serve! / green@FreeBSD.org `------------------------------' To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-audit" in the body of the message