From owner-freebsd-bugs@FreeBSD.ORG Mon Jul 21 04:51:42 2003 Return-Path: Delivered-To: freebsd-bugs@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 734CA37B401; Mon, 21 Jul 2003 04:51:42 -0700 (PDT) Received: from mailbox.univie.ac.at (mailbox.univie.ac.at [131.130.1.27]) by mx1.FreeBSD.org (Postfix) with ESMTP id 47DD643FD7; Mon, 21 Jul 2003 04:51:39 -0700 (PDT) (envelope-from l.ertl@univie.ac.at) Received: from wireless (adslle.cc.univie.ac.at [131.130.102.11]) by mailbox.univie.ac.at (8.12.2/8.12.2) with ESMTP id h6LBpOm6114048; Mon, 21 Jul 2003 13:51:29 +0200 Date: Mon, 21 Jul 2003 13:51:23 +0200 (CEST) From: Lukas Ertl To: Bruce Evans In-Reply-To: <20030721161710.Q3367@gamplex.bde.org> Message-ID: <20030721134859.I625@korben.in.tern> References: <200307202006.h6KK62li015250@korben.in.tern> <20030721161710.Q3367@gamplex.bde.org> MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=ISO-8859-1 Content-Transfer-Encoding: QUOTED-PRINTABLE X-DCC-ZID-Univie-Metrics: mx1 4246; Body=0 Fuz1=0 Fuz2=0 cc: freebsd-bugs@freebsd.org cc: FreeBSD-gnats-submit@freebsd.org Subject: Re: bin/54672: [PATCH] fix gcc 3.3 compiler warning for ifconfig(8) X-BeenThere: freebsd-bugs@freebsd.org X-Mailman-Version: 2.1.1 Precedence: list List-Id: Bug reports List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 21 Jul 2003 11:51:43 -0000 On Mon, 21 Jul 2003, Bruce Evans wrote: > On Sun, 20 Jul 2003, Lukas Ertl wrote: > > > first and last are both declared as u_short, which can't hold values la= rger > > then 0xffff, so the comparison isn't needed. > > This is machine-dependent. u_short can hold values up to USHRT_MAX, whic= h > is >=3D 0xffff (perhaps strictly larger). > > There doesn't seem to be any good reason to use u_shorts; similar code in > at_getaddr() uses u_ints so it accidentally avoids the warning except on > machines with 16-bit u_ints. > > Using strtoul() as mentioned in the XXX before the above code would avoid > the warning less accidentally since 0xffff < ULONG_MAX on all machines. Well, would this patch be better: ---8<--- Index: sbin/ifconfig/ifconfig.c =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D RCS file: /usr/local/bsdcvs/src/sbin/ifconfig/ifconfig.c,v retrieving revision 1.90 diff -u -u -r1.90 ifconfig.c --- sbin/ifconfig/ifconfig.c=0928 Apr 2003 16:37:38 -0000=091.90 +++ sbin/ifconfig/ifconfig.c=0921 Jul 2003 11:50:33 -0000 @@ -1680,17 +1680,34 @@ =09bcopy(LLADDR(&sdl), sa->sa_data, sdl.sdl_alen); } -/* XXX FIXME -- should use strtoul for better parsing. */ void setatrange(const char *range, int dummy __unused, int s, const struct afswtch *afp) { -=09u_short=09first =3D 123, last =3D 123; +=09u_int=09first =3D 123, last =3D 123; +=09char=09*p, *endptr; + +=09if ((p =3D strchr(range, '-')) =3D=3D NULL) +=09=09errx(1, "illegal range '%s'", range); + +=09*p =3D '\0'; +=09p++; + +=09if ((*range =3D=3D '\0') || (*p =3D=3D '\0')) +=09=09errx(1, "illegal range '%s-%s'", range, p); + +=09first =3D strtoul(range, &endptr, 10); +=09if (endptr =3D=3D range || *endptr !=3D '\0') +=09=09errx(1, "illegal range '%s-%s'", range, p); + +=09last =3D strtoul(p, &endptr, 10); +=09if (endptr =3D=3D p || *endptr !=3D '\0') +=09=09errx(1, "illegal range '%s-%s'", range, p); + +=09if (first =3D=3D 0 || first > 0xffff || last =3D=3D 0 || last > 0xffff +=09 || first > last) +=09=09errx(1, "%s-%s: illegal net range: %u-%u", range, p, first, last); -=09if (sscanf(range, "%hu-%hu", &first, &last) !=3D 2 -=09 || first =3D=3D 0 || first > 0xffff -=09 || last =3D=3D 0 || last > 0xffff || first > last) -=09=09errx(1, "%s: illegal net range: %u-%u", range, first, last); =09at_nr.nr_firstnet =3D htons(first); =09at_nr.nr_lastnet =3D htons(last); } ---8<--- regards, le --=20 Lukas Ertl eMail: l.ertl@univie.ac.at UNIX-Systemadministrator Tel.: (+43 1) 4277-14073 Zentraler Informatikdienst (ZID) Fax.: (+43 1) 4277-9140 der Universit=E4t Wien http://mailbox.univie.ac.at/~le/