From owner-freebsd-bugs@FreeBSD.ORG Sun Jul 20 23:30:20 2003 Return-Path: Delivered-To: freebsd-bugs@hub.freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 1318837B401 for ; Sun, 20 Jul 2003 23:30:20 -0700 (PDT) Received: from freefall.freebsd.org (freefall.freebsd.org [216.136.204.21]) by mx1.FreeBSD.org (Postfix) with ESMTP id A8DFB43FAF for ; Sun, 20 Jul 2003 23:30:19 -0700 (PDT) (envelope-from gnats@FreeBSD.org) Received: from freefall.freebsd.org (gnats@localhost [127.0.0.1]) by freefall.freebsd.org (8.12.9/8.12.9) with ESMTP id h6L6UJUp036061 for ; Sun, 20 Jul 2003 23:30:19 -0700 (PDT) (envelope-from gnats@freefall.freebsd.org) Received: (from gnats@localhost) by freefall.freebsd.org (8.12.9/8.12.9/Submit) id h6L6UJA7036060; Sun, 20 Jul 2003 23:30:19 -0700 (PDT) Date: Sun, 20 Jul 2003 23:30:19 -0700 (PDT) Message-Id: <200307210630.h6L6UJA7036060@freefall.freebsd.org> To: freebsd-bugs@FreeBSD.org From: Bruce Evans 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 Reply-To: Bruce Evans List-Id: Bug reports List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 21 Jul 2003 06:30:20 -0000 The following reply was made to PR bin/54672; it has been noted by GNATS. From: Bruce Evans To: Lukas Ertl Cc: FreeBSD-gnats-submit@freebsd.org, freebsd-bugs@freebsd.org Subject: Re: bin/54672: [PATCH] fix gcc 3.3 compiler warning for ifconfig(8) Date: Mon, 21 Jul 2003 16:28:02 +1000 (EST) 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