Bug report: strtol conversion

Daniel Dunbar daniel at zuster.org
Sat Apr 19 14:03:09 UTC 2008


var YAHOO = {'Shortcuts' : {}};
YAHOO.Shortcuts.hasSensitiveText = false;
YAHOO.Shortcuts.sensitivityType = [];
YAHOO.Shortcuts.doUlt = false;
YAHOO.Shortcuts.location = "us";
YAHOO.Shortcuts.document_id = 0;
YAHOO.Shortcuts.document_type = "";
YAHOO.Shortcuts.document_title = "Bug report: strtol conversion";
YAHOO.Shortcuts.document_publish_date = "";
YAHOO.Shortcuts.document_author = "daniel at zuster.org";
YAHOO.Shortcuts.document_url = "";
YAHOO.Shortcuts.document_tags = "";
YAHOO.Shortcuts.annotationSet = {

};
<!-- DIV {margin:0px;}-->Hi,

I believe I have found a bug in the current uclibc implementation
of strtol (and friends).

An example failing program is:
assert(strtol("+2``2`4", 0, 10) == 2);

The problem is that uclibc is treating the characters '`' as the digit 9. The bug 
is in the vicinity of stdlib.c:561 (and 712), in the digit computation:

--
            digit = (((Wuchar)(*str - '0')) <= 9)
                ? (*str - '0')
                : (((*str) >= 'A')
                   ? (((0x20|(*str)) - 'a' + 10)) /* WARNING: assumes ascii. */
                      : 40);
--

I do not know what the preferred fix is, but I have verified that the following code at
least correctly computes digits for base 10.

--
            digit = (((Wuchar)(*str - '0')) <= 9)
                ? (*str - '0')
                : (((0x20|(*str)) >= 'A')
                   ? (((0x20|(*str)) - 'a' + 10)) /* WARNING: assumes ascii. */
                      : 40);
--

 - Daniel








-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.busybox.net/pipermail/uclibc/attachments/20080419/0995f0e8/attachment-0001.htm 


More information about the uClibc mailing list