bin/54672: [PATCH] fix gcc 3.3 compiler warning for ifconfig(8)
Lukas Ertl
l.ertl at univie.ac.at
Mon Jul 21 05:00:41 PDT 2003
The following reply was made to PR bin/54672; it has been noted by GNATS.
From: Lukas Ertl <l.ertl at univie.ac.at>
To: Bruce Evans <bde at zeta.org.au>
Cc: FreeBSD-gnats-submit at freebsd.org, freebsd-bugs at freebsd.org
Subject: Re: bin/54672: [PATCH] fix gcc 3.3 compiler warning for ifconfig(8)
Date: Mon, 21 Jul 2003 13:51:23 +0200 (CEST)
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 at 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/
More information about the freebsd-bugs
mailing list