Re: Implementation errors in strtol()

From: Joerg Wunsch <freebsd-current_at_uriah.heep.sax.de>
Date: Thu, 20 Jan 2005 22:14:49 +0100
As Andrey Chernov wrote:

> > While the standard explicitly states that empty (or
> > whitespace-only) input strings cause an empty subject sequence,
> > which will in turn cause no conversion to be performed, single
> > signs ("+" or "-") would contain a non-empty subject sequence, so
> > a conversion has to take place.  FreeBSD erroneously returns
> > EINVAL in that case.  As EINVAL is

> Just what is eye-catching:

> +- can't be compared to whitespace at all. Whitespace is not subject
> sequence (2) but initial sequence (1) according to POSIX.

That's correct, and doesn't contradict to what I wrote.  It only means
there's no difference in "   " vs. "".

> Moreover, POSIX clearly allows EINVAL for strtol():

> "If no conversion could be performed, 0 shall be returned and errno
> may be set to [EINVAL]"

Yes, I know.  Anyway, how could POSIX (or the Single UNIX
Specification, for that matter) possibly contradict to the C standard?
In reading the C standard, I get the impression that for functions
where the standard describes their possible modifications to errno, no
further modifications are permissible.  Paragraph 3 of section 7.5
»Errors <errno.h>« says:

``The value of errno is zero at program startup, but is never set to
zero by any library function.170) The value of errno may be set to
nonzero by a library function call whether or not there is an error,
provided the use of errno is not documented in the description of the
function in this International Standard.''

I read this as an explicit prohibition of setting errno to anything
else (as strtol has a documented behaviour for setting errno), and
just wondered how POSIX could get away with its (IMHO) violation of
that statement.

Still, my major point was that "0x" sequences are falsely rejected as
conversion errors, and that strings consisting solely of a plus or
minus sign should not throw an error either, as I read the C standard.

I confess that I'm operating on a prerelease version of the C
standard, in case that matters.

-- 
cheers, J"org               .-.-.   --... ...--   -.. .  DL8DTL

http://www.sax.de/~joerg/                        NIC: JW11-RIPE
Never trust an operating system you don't have sources for. ;-)
Received on Thu Jan 20 2005 - 20:20:07 UTC

This archive was generated by hypermail 2.4.0 : Wed May 19 2021 - 11:38:26 UTC