Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 20 Jan 2005 20:23:24 +0100
From:      Joerg Wunsch <freebsd-current@uriah.heep.sax.de>
To:        current@freebsd.org
Cc:        bde@freebsd.org
Subject:   Implementation errors in strtol()
Message-ID:  <20050120192324.GA30862@uriah.heep.sax.de>
Resent-Message-ID: <200501202038.j0KKcZ9K033024@uriah.heep.sax.de>

next in thread | raw e-mail | index | archive | help
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. ;-)



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20050120192324.GA30862>