bin/54672: [PATCH] fix gcc 3.3 compiler warning for ifconfig(8)

Bruce Evans bde at zeta.org.au
Sun Jul 20 23:28:38 PDT 2003


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


More information about the freebsd-bugs mailing list