1 Jul 2009 20:25
Re: strtonum(3) from OpenBSD?
Greg A. Woods <woods <at> planix.com>
2009-07-01 18:25:34 GMT
2009-07-01 18:25:34 GMT
At Tue, 30 Jun 2009 03:00:17 +0000, David Holland <dholland-tech <at> netbsd.org> wrote: Subject: Re: strtonum(3) from OpenBSD? > > On Sat, Jun 27, 2009 at 10:26:49PM -0400, Greg A. Woods wrote: > > > That's the POINT. Calls that succeed may set errno anyway. You have to > > > check that an error occurred before inspecting errno. > > > > Well, with strtol(3) _both_ conditions must hold exactly -- it doesn't > > really matter which test is done first!(Continue reading)> > In all cases, not just strtol, both conditions must hold, but it does > matter which test is done first if errno might contain a trap > representation. I meant in the strict ordering of terms in the test expression(s). I.e. all of the following statements are equivalent. I.e. it does not matter which test is done first. It can be either errno first: if (errno == ERANGE && rval == LONG_MAX) err(); if (errno == ERANGE) if (rval == LONG_MAX) err(); etc., or the return value first: if (rval == LONG_MAX && errno == ERANGE) err();

>
> In all cases, not just strtol, both conditions must hold, but it does
> matter which test is done first if errno might contain a trap
> representation.
I meant in the strict ordering of terms in the test expression(s).
I.e. all of the following statements are equivalent. I.e. it does not
matter which test is done first. It can be either errno first:
if (errno == ERANGE && rval == LONG_MAX)
err();
if (errno == ERANGE)
if (rval == LONG_MAX)
err();
etc., or the return value first:
if (rval == LONG_MAX && errno == ERANGE)
err();

RSS Feed