tech-userlevel archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

Re: strtonum(3) from OpenBSD?

On Fri, 26 Jun 2009, David Holland wrote:

> If it *can* set errno on success, which is the usual convention for
> library functions,

Nonsense, that is no usual convention. Please read errno(2) and see what
it says (try the second paragraph in the DIAGNOSTICS section)

> there's no fully safe way to distinguish an overflow from a valid return
> of LONG_MAX or LONG_MIN. But if one's going to try, one should properly
> test the return value before errno, unlike the example in strtol(3).

I think so too, but it doesn't actually matter in practice as both
conditions need to be met anyway. Note also that if the range of valid
values does not include LONG_MIN and LONG_MAX then the ERANGE check is not
required. (and I guess that they did it that way on purpose for just that

> IMO, for anything trivial one might as well just call atoi(), and for
> anything nontrivial it's easier to reimplement strto* than call it
> correctly. :-/

The former might be so but the latter clearly isn't.


Home | Main Index | Thread Index | Old Index