Date: Fri, 29 Oct 2004 21:30:30 GMT From: Dima Dorfman <dd@freebsd.org> To: freebsd-bugs@FreeBSD.org Subject: Re: bin/73112: change atol() to strtol() in badsect Message-ID: <200410292130.i9TLUUY8005684@freefall.freebsd.org>
next in thread | raw e-mail | index | archive | help
The following reply was made to PR bin/73112; it has been noted by GNATS. From: Dima Dorfman <dd@freebsd.org> To: Giorgos Keramidas <keramida@bytemobile.com> Cc: FreeBSD-gnats-submit@freebsd.org Subject: Re: bin/73112: change atol() to strtol() in badsect Date: Fri, 29 Oct 2004 21:20:52 +0000 Giorgos Keramidas <keramida@FreeBSD.org> wrote: > > >Number: 73112 > >Synopsis: change atol() to strtol() in badsect > > Index: badsect.c > =================================================================== > RCS file: /home/ncvs/src/sbin/badsect/badsect.c,v > retrieving revision 1.20 > diff -u -u -r1.20 badsect.c > --- badsect.c 9 Apr 2004 19:58:25 -0000 1.20 > +++ badsect.c 25 Oct 2004 12:00:37 -0000 > @@ -123,7 +124,9 @@ > err(7, "%s", name); > } > for (argc -= 2, argv += 2; argc > 0; argc--, argv++) { > - number = atol(*argv); > + number = strtol(*argv, NULL, 0); > + if (errno == EINVAL || errno == ERANGE) > + err(8, "%s", *argv); The error handling here is incorrect. strtol never clears errno, and it doesn't consider it an error if part of the string wasn't converted. Something like this is necessary: char *ep; ... errno = 0; number = strtol(*argv, &ep, 0); if (*ep != '\0' || errno != 0) ...
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200410292130.i9TLUUY8005684>