Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 21 Jul 2003 16:28:02 +1000 (EST)
From:      Bruce Evans <bde@zeta.org.au>
To:        Lukas Ertl <l.ertl@univie.ac.at>
Cc:        FreeBSD-gnats-submit@freebsd.org
Subject:   Re: bin/54672: [PATCH] fix gcc 3.3 compiler warning for ifconfig(8)
Message-ID:  <20030721161710.Q3367@gamplex.bde.org>
In-Reply-To: <200307202006.h6KK62li015250@korben.in.tern>
References:  <200307202006.h6KK62li015250@korben.in.tern>

next in thread | previous in thread | raw e-mail | index | archive | help
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



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20030721161710.Q3367>