From bfdcec65ec90ff8c667ee1dde56ed48bf190e2aa Mon Sep 17 00:00:00 2001 From: rosenrost <52100845+rosenrost@users.noreply.github.com> Date: Sun, 15 Nov 2026 12:31:26 +0100 Subject: [PATCH 1/2] Fix incomplete whitespace skipping The `strto...()` functions are intended to skip all whitespace characters at the beginning of the string being converted. Previously, this only accounted for spaces (`' '`) and tabs (`'\t'`). With this bug fix, `'\n'`, `'\r'`, and `'\v'` are now also skipped. This solves #153. --- sources/strtod.c | 2 +- sources/strtoul_int.c | 18 +++++++++--------- sources/strtoull_int.c | 18 +++++++++--------- 3 files changed, 19 insertions(+), 19 deletions(-) diff --git a/sources/strtod.c b/sources/strtod.c index 52c988b..012000f 100644 --- a/sources/strtod.c +++ b/sources/strtod.c @@ -70,7 +70,7 @@ #endif -#define ISSPACE(c) ((c) == ' ' || (c) == '\t') +#define ISSPACE(c) (((c) == ' ') || ((c) == '\t') || ((c == '\n')) || ((c) == '\r') || ((c) == '\v')) #define ISDIGIT(c) ((c) >= '0' && (c) <= '9') diff --git a/sources/strtoul_int.c b/sources/strtoul_int.c index ba56e6d..1c134be 100644 --- a/sources/strtoul_int.c +++ b/sources/strtoul_int.c @@ -2,7 +2,7 @@ #include #include "lib.h" -#define ISSPACE(c) ((c) == ' '||(c) == '\t') +#define ISSPACE(c) (((c) == ' ') || ((c) == '\t') || ((c == '\n')) || ((c) == '\r') || ((c) == '\v')) #define ISDIGIT(c) ((c) >= '0' && (c) <= '9') static inline @@ -14,7 +14,7 @@ unsigned long __mul32 (long in, long mul, char *overflow) { ".loop: \n" /* } */ " lsr.l #1, %3 \n" /* mul >>= 1 */ " beq .end \n" /* if (mul == 0) goto end; */ - + " add.l %2, %2 \n" /* in <<= 1; */ " bcs .overfl \n" /* overflow? goto overfl; */ ".start: \n" @@ -50,18 +50,18 @@ unsigned long __strtoul_internal(const char *nptr, char **endptr, int base, int int val; short ret_ok=0; char overflow=0; - + if(base!=0 && 2 > base && base > 36) goto error; while(*ptr && ISSPACE(*ptr)) ptr++; /* skip spaces */ - + if( (*sign = (*ptr == '-')) ) ptr++; if(!*ptr) goto error; - + if(*ptr == '0') { ret_ok = 1; switch (*++ptr&~0x20) { @@ -76,19 +76,19 @@ unsigned long __strtoul_internal(const char *nptr, char **endptr, int base, int ptr++; break; default: - if(base == 0) + if(base == 0) base = 8; break; } } else if(base == 0) base = 10; - + for( ;*ptr; ptr++) { - if(ISDIGIT(*ptr)) + if(ISDIGIT(*ptr)) val = *ptr - '0'; else { val = 10 + (*ptr&~0x20 /*TOUPPER*/) - 'A'; - if(val < 10) val = 37; + if(val < 10) val = 37; } ret_ok = 1; if(val >= base) break; diff --git a/sources/strtoull_int.c b/sources/strtoull_int.c index 5f705e7..220994d 100644 --- a/sources/strtoull_int.c +++ b/sources/strtoull_int.c @@ -13,7 +13,7 @@ # endif -#define ISSPACE(c) ((c) == ' '||(c) == '\t') +#define ISSPACE(c) (((c) == ' ') || ((c) == '\t') || ((c == '\n')) || ((c) == '\r') || ((c) == '\v')) #define ISDIGIT(c) ((c) >= '0' && (c) <= '9') static inline @@ -29,7 +29,7 @@ unsigned long long __mul64 (long long in, long mul, char *overflow) { ".loop: \n" /* } */ " lsr.l #1, %5 \n" /* mul >>= 1 */ " beq .end \n" /* if (mul == 0) goto end; */ - + " add.l %3, %3 \n" /* in <<= 1; */ " addx.l %4, %4 \n" " bcs .overfl \n" /* overflow? goto overfl; */ @@ -70,18 +70,18 @@ unsigned long long __strtoull_internal(const char *nptr, char **endptr, int base int val; short ret_ok=0; char overflow=0; - + if(base!=0 && 2 > base && base > 36) goto error; while(*ptr && ISSPACE(*ptr)) ptr++; /* skip spaces */ - + if( (*sign = (*ptr == '-')) ) ptr++; if(!*ptr) goto error; - + if(*ptr == '0') { ret_ok = 1; ptr++; @@ -97,19 +97,19 @@ unsigned long long __strtoull_internal(const char *nptr, char **endptr, int base ptr++; break; default: - if(base == 0) + if(base == 0) base = 8; break; } } else if(base == 0) base = 10; - + for( ;*ptr; ptr++) { - if(ISDIGIT(*ptr)) + if(ISDIGIT(*ptr)) val = *ptr - '0'; else { val = 10 + (*ptr&~0x20 /*TOUPPER*/) - 'A'; - if(val < 10) val = 37; + if(val < 10) val = 37; } ret_ok = 1; From 9eba7b7490053f899319003529cd6a77a38da7d3 Mon Sep 17 00:00:00 2001 From: rosenrost <52100845+rosenrost@users.noreply.github.com> Date: Sun, 15 Nov 2026 12:31:26 +0100 Subject: [PATCH 2/2] Fix incomplete whitespace skipping The strto...() functions are intended to skip all whitespace characters at the beginning of the string being converted. Previously, this only accounted for spaces (' ') and tabs ('\t'). With this bug fix, '\n', '\r', and '\v' are now also skipped. This solves #153. --- sources/strtod.c | 2 +- sources/strtoul_int.c | 18 +++++++++--------- sources/strtoull_int.c | 18 +++++++++--------- 3 files changed, 19 insertions(+), 19 deletions(-) diff --git a/sources/strtod.c b/sources/strtod.c index 52c988b..012000f 100644 --- a/sources/strtod.c +++ b/sources/strtod.c @@ -70,7 +70,7 @@ #endif -#define ISSPACE(c) ((c) == ' ' || (c) == '\t') +#define ISSPACE(c) (((c) == ' ') || ((c) == '\t') || ((c == '\n')) || ((c) == '\r') || ((c) == '\v')) #define ISDIGIT(c) ((c) >= '0' && (c) <= '9') diff --git a/sources/strtoul_int.c b/sources/strtoul_int.c index ba56e6d..1c134be 100644 --- a/sources/strtoul_int.c +++ b/sources/strtoul_int.c @@ -2,7 +2,7 @@ #include #include "lib.h" -#define ISSPACE(c) ((c) == ' '||(c) == '\t') +#define ISSPACE(c) (((c) == ' ') || ((c) == '\t') || ((c == '\n')) || ((c) == '\r') || ((c) == '\v')) #define ISDIGIT(c) ((c) >= '0' && (c) <= '9') static inline @@ -14,7 +14,7 @@ unsigned long __mul32 (long in, long mul, char *overflow) { ".loop: \n" /* } */ " lsr.l #1, %3 \n" /* mul >>= 1 */ " beq .end \n" /* if (mul == 0) goto end; */ - + " add.l %2, %2 \n" /* in <<= 1; */ " bcs .overfl \n" /* overflow? goto overfl; */ ".start: \n" @@ -50,18 +50,18 @@ unsigned long __strtoul_internal(const char *nptr, char **endptr, int base, int int val; short ret_ok=0; char overflow=0; - + if(base!=0 && 2 > base && base > 36) goto error; while(*ptr && ISSPACE(*ptr)) ptr++; /* skip spaces */ - + if( (*sign = (*ptr == '-')) ) ptr++; if(!*ptr) goto error; - + if(*ptr == '0') { ret_ok = 1; switch (*++ptr&~0x20) { @@ -76,19 +76,19 @@ unsigned long __strtoul_internal(const char *nptr, char **endptr, int base, int ptr++; break; default: - if(base == 0) + if(base == 0) base = 8; break; } } else if(base == 0) base = 10; - + for( ;*ptr; ptr++) { - if(ISDIGIT(*ptr)) + if(ISDIGIT(*ptr)) val = *ptr - '0'; else { val = 10 + (*ptr&~0x20 /*TOUPPER*/) - 'A'; - if(val < 10) val = 37; + if(val < 10) val = 37; } ret_ok = 1; if(val >= base) break; diff --git a/sources/strtoull_int.c b/sources/strtoull_int.c index 5f705e7..220994d 100644 --- a/sources/strtoull_int.c +++ b/sources/strtoull_int.c @@ -13,7 +13,7 @@ # endif -#define ISSPACE(c) ((c) == ' '||(c) == '\t') +#define ISSPACE(c) (((c) == ' ') || ((c) == '\t') || ((c == '\n')) || ((c) == '\r') || ((c) == '\v')) #define ISDIGIT(c) ((c) >= '0' && (c) <= '9') static inline @@ -29,7 +29,7 @@ unsigned long long __mul64 (long long in, long mul, char *overflow) { ".loop: \n" /* } */ " lsr.l #1, %5 \n" /* mul >>= 1 */ " beq .end \n" /* if (mul == 0) goto end; */ - + " add.l %3, %3 \n" /* in <<= 1; */ " addx.l %4, %4 \n" " bcs .overfl \n" /* overflow? goto overfl; */ @@ -70,18 +70,18 @@ unsigned long long __strtoull_internal(const char *nptr, char **endptr, int base int val; short ret_ok=0; char overflow=0; - + if(base!=0 && 2 > base && base > 36) goto error; while(*ptr && ISSPACE(*ptr)) ptr++; /* skip spaces */ - + if( (*sign = (*ptr == '-')) ) ptr++; if(!*ptr) goto error; - + if(*ptr == '0') { ret_ok = 1; ptr++; @@ -97,19 +97,19 @@ unsigned long long __strtoull_internal(const char *nptr, char **endptr, int base ptr++; break; default: - if(base == 0) + if(base == 0) base = 8; break; } } else if(base == 0) base = 10; - + for( ;*ptr; ptr++) { - if(ISDIGIT(*ptr)) + if(ISDIGIT(*ptr)) val = *ptr - '0'; else { val = 10 + (*ptr&~0x20 /*TOUPPER*/) - 'A'; - if(val < 10) val = 37; + if(val < 10) val = 37; } ret_ok = 1;