[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
Re: strtonum(3) from OpenBSD?
On Fri, Jul 03, 2009 at 07:07:46PM -0400, Greg A. Woods wrote:
> To be even more pedantic, it still really doesn't matter whether errno
> contains a trap representation or not -- it's not going to change the
> ultimate outcome since either one must ensure both conditions hold
> simultaneously, or one must only check errno. Either way errno must be
> accessed so in the end it still doesn't matter which test one does
> first. The program might blow up, the terms of the expression still
In general no, because if you check first whether there was an error
condition, errno is never touched because of short-circuit evaluation.
In the specific case of strtol, where you can't unambiguously detect
if an error occurred from the return value, that was one of the
potential corner cases that spawned this thread. But this case is moot
because strtol is, as we've ascertained, not allowed to leave trash in
> Finally to paraphrase and summarise a discussion that took place on
> comp.std.c last year, ISO C99 says errno starts with the value zero
> (i.e. it is most certainly not starting with a value which is a trap
> representation) and allows (or as we've seen sometimes even requires)
> library functions to assign other values to errno. ISO C99 also says
> that assigning a "value" cannot ever produce a trap representation.
> Therefore even on platforms with "int" values that can be trap
> representations, during normal execution errno cannot ever come to
> contain a trap representation.
That, however, is a good point.
David A. Holland
Main Index |
Thread Index |