]> pd.if.org Git - pdclib.old/blobdiff - functions/_PDCLIB/strtox_main.c
Temporary proof-of-concept for printf() output conversions.
[pdclib.old] / functions / _PDCLIB / strtox_main.c
index 9f82cdb33c61ebd2061493b56e0fb1c098a7d2e9..bc14811335c736c73eab4597f9f704559b0aefba 100644 (file)
@@ -18,19 +18,20 @@ _PDCLIB_uintmax_t _PDCLIB_strtox_main( const char ** p, unsigned int base, uintm
     _PDCLIB_uintmax_t rc = 0;
     int digit = -1;
     const char * x;
-    while ( ( x = memchr( _PDCLIB_digits, toupper(**p), base ) ) != NULL )
+    while ( ( x = memchr( _PDCLIB_digits, tolower(**p), base ) ) != NULL )
     {
         digit = x - _PDCLIB_digits;
         if ( ( rc < limval ) || ( ( rc == limval ) && ( digit <= limdigit ) ) )
         {
-            rc = rc * base + ( x - _PDCLIB_digits );
+            rc = rc * base + digit;
             ++(*p);
         }
         else
         {
             errno = ERANGE;
             /* TODO: Only if endptr != NULL - but do we really want *another* parameter? */
-            while ( memchr( _PDCLIB_digits, **p, base ) != NULL ) ++(*p);
+            /* TODO: Earlier version was missing tolower() here but was not caught by tests */
+            while ( memchr( _PDCLIB_digits, tolower(**p), base ) != NULL ) ++(*p);
             /* TODO: This is ugly, but keeps caller from negating the error value */
             *sign = '+';
             return error;