summaryrefslogtreecommitdiff
path: root/libc/misc
diff options
context:
space:
mode:
Diffstat (limited to 'libc/misc')
-rw-r--r--libc/misc/ctype.c3
-rw-r--r--libc/misc/strtol.c15
2 files changed, 12 insertions, 6 deletions
diff --git a/libc/misc/ctype.c b/libc/misc/ctype.c
index 6b6cd3d..0425f00 100644
--- a/libc/misc/ctype.c
+++ b/libc/misc/ctype.c
@@ -12,8 +12,9 @@
#undef toupper
#undef tolower
-unsigned char __ctype[128] =
+unsigned char __ctype[257] =
{
+ 0, /* -1 */
__CT_c, __CT_c, __CT_c, __CT_c, /* 0x00..0x03 */
__CT_c, __CT_c, __CT_c, __CT_c, /* 0x04..0x07 */
__CT_c, __CT_c|__CT_s, __CT_c|__CT_s, __CT_c|__CT_s, /* 0x08..0x0B */
diff --git a/libc/misc/strtol.c b/libc/misc/strtol.c
index bcd3334..d8d62ea 100644
--- a/libc/misc/strtol.c
+++ b/libc/misc/strtol.c
@@ -18,6 +18,8 @@
*
*/
+/* TODO: This needs range clamping and setting errno when it's done. */
+
#include <ctype.h>
#include <stdlib.h>
@@ -86,13 +88,16 @@ strtoul(const char *nptr, char **endptr, int base)
base=10;
number=0;
- while (isalnum(*nptr))
+ while (isascii(*nptr) && isalnum(*nptr))
{
- number= (number*base)+((isalpha(*nptr) ? toupper(*nptr) : *nptr)
- - (isdigit(*nptr) ? '0' : 'A' + 9));
- nptr++;
- if (*nptr>'0'+base)
+ int ch = *nptr;
+ if (islower(ch)) ch = toupper(ch);
+ ch -= (ch<='9' ? '0' : 'A'-10);
+ if (ch>base)
break;
+
+ number= (number*base)+ch;
+ nptr++;
}
/* Some code is simply _impossible_ to write with -Wcast-qual .. :-\ */