Skip site navigation (1)Skip section navigation (2)
Date:      Sat, 26 Jan 2002 17:49:46 -0500
From:      "Brian F. Feldman" <green@FreeBSD.ORG>
To:        Chad David <davidc@acns.ab.ca>
Cc:        Bruce Evans <bde@zeta.org.au>, arch@FreeBSD.ORG
Subject:   Re: strtod() 
Message-ID:  <200201262249.g0QMnlU91392@green.bikeshed.org>
In-Reply-To: Message from Chad David <davidc@acns.ab.ca>  of "Sat, 26 Jan 2002 14:27:34 MST." <20020126142734.A7139@colnta.acns.ab.ca> 

next in thread | previous in thread | raw e-mail | index | archive | help
Chad David <davidc@acns.ab.ca> wrote:
> On Sun, Jan 27, 2002 at 07:44:20AM +1100, Bruce Evans wrote:
> > 
> > %%%
> > 	errno = 0;
> > 	num = strtouq(val, &expr, 0);
> > 	if (errno != 0)				/* Overflow or underflow. */
> > 		err(1, "%s", oper);
> > 
> > 	if (expr == val)			/* No valid digits. */
> > 		errx(1, "%s: illegal numeric value", oper);
> > %%%
> > 
> > The "Overflow or underflow" comment has rotted in 3 steps:
> > (1) It was changed from "Overflow" to "Overflow or underflow" when
> >     strtuol() was changed to strtoq().  This was just an obfuscation.
> >     "Underflow" must be read as "overflow towards negative infinity",
> >     but it's less confusing to just say "overflow".
> > (2) The code was wrong because strto*() may set errno, and broke when
> >     strtoq() started setting it.  The "illegal numeric value" case
> >     became unreachable.
> > (3) "Overflow or underflow" wasn't changed back to "Overflow" when
> >     strtoq() was changed to strtouq().
> 
> Code like this is what I'm dealing with.  My point is that if you set
> errno == 0, and then after the function it is != 0, an error DID occur,
> as long as the return value == 0.0 or HUGE_VAL I guess.
> 
> Am I making any sense?

Not "as long as the return value" is anything!  Why should the function be 
changing errno if it hasn't generated an error?  These are particularly 
difficult functions to use in the first place, and they really shouldn't be 
made more-so by gratuitously changing errno.  It's not hard to save errno, 
either, in the library call...

-- 
Brian Fundakowski Feldman                           \'[ FreeBSD ]''''''''''\
  <> green@FreeBSD.org  <> bfeldman@tislabs.com      \  The Power to Serve! \
 Opinions expressed are my own.                       \,,,,,,,,,,,,,,,,,,,,,,\



To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-arch" in the body of the message




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