From owner-freebsd-bugs@FreeBSD.ORG Sun Jul 20 23:28:37 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 D12A737B401; Sun, 20 Jul 2003 23:28:37 -0700 (PDT) Received: from mailman.zeta.org.au (mailman.zeta.org.au [203.26.10.16]) by mx1.FreeBSD.org (Postfix) with ESMTP id 0E9D343FA3; Sun, 20 Jul 2003 23:28:36 -0700 (PDT) (envelope-from bde@zeta.org.au) Received: from gamplex.bde.org (katana.zip.com.au [61.8.7.246]) by mailman.zeta.org.au (8.9.3p2/8.8.7) with ESMTP id QAA31911; Mon, 21 Jul 2003 16:28:03 +1000 Date: Mon, 21 Jul 2003 16:28:02 +1000 (EST) From: Bruce Evans X-X-Sender: bde@gamplex.bde.org To: Lukas Ertl In-Reply-To: <200307202006.h6KK62li015250@korben.in.tern> Message-ID: <20030721161710.Q3367@gamplex.bde.org> References: <200307202006.h6KK62li015250@korben.in.tern> MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII 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 06:28:38 -0000 On Sun, 20 Jul 2003, Lukas Ertl wrote: > >Description: > > When compiling ifconfig(8), gcc-3.3 emits the following warning: > > cc -O -pipe -march=athlon -DUSE_IF_MEDIA -DINET6 -DUSE_VLANS -DUSE_IEEE80211 -DUSE_MAC -DNS -Wall -Wmissing-prototypes -Wcast-qual -Wwrite-strings -Wnested-externs -I.. -DRESCUE -c /usr/src/sbin/ifconfig/ifconfig.c > /usr/src/sbin/ifconfig/ifconfig.c: In function `setatrange': > /usr/src/sbin/ifconfig/ifconfig.c:1692: warning: comparison is always false due to limited range of data type > /usr/src/sbin/ifconfig/ifconfig.c:1692: warning: comparison is always false due to limited range of data type > > The bogus comparison is: > > if (sscanf(range, "%hu-%hu", &first, &last) != 2 > || first == 0 || first > 0xffff > || last == 0 || last > 0xffff || first > last) > > first and last are both declared as u_short, which can't hold values larger > then 0xffff, so the comparison isn't needed. This is machine-dependent. u_short can hold values up to USHRT_MAX, which is >= 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. Bruce