Implementation errors in strtol()

From: Joerg Wunsch <freebsd-current_at_uriah.heep.sax.de>
Date: Thu, 20 Jan 2005 20:23:24 +0100
While analyzing an implementation of strtol() for the AVR
microcontroller (as part of the opensource C library for it), I
noticed a few violations of the C standard in FreeBSD's
implementation.

I didn't check, but I'd expect similar issues to apply to related
functions.

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
not covered by the standard at all, of course this is debatable, but I
clearly read the standard the way that "" or " " are not convertible,
while "+" and "-" are.

Second (and much more of an issue), sequences consisting solely of a
"0x" (with any permutations of leading white space and/or sign) are
*always* convertible, as the leading 0 is always a valid number, so
conversion only has to stop at the "x".  This is a clear bug in my
opinion.

Btw., what's the position of the C standard for errno values that are
not covered by the C standard itself?  I see SUSPv2 supports the
notion of EINVAL, but it's not clear to me whether the C standard
would allow non-standard extension for functions where the standard
describes the possible errno changes.

-- 
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 - 19:39:53 UTC

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