fix various bugs in new integer parser framework
1. my interpretation of subject sequence definition was wrong. adjust parser to conform to the standard. 2. some code for handling tail overflow case was missing (forgot to finish writing it). 3. typo (= instead of ==) caused ERANGE to wrongly behave like EINVAL
This commit is contained in:
@@ -25,7 +25,7 @@ intmax_t strtoimax(const char *s1, char **p, int base)
|
||||
|
||||
if (ip.err) {
|
||||
errno = ip.err;
|
||||
if (ip.err = EINVAL) return 0;
|
||||
if (ip.err == EINVAL) return 0;
|
||||
return ip.neg ? INTMAX_MIN : INTMAX_MAX;
|
||||
}
|
||||
|
||||
|
||||
@@ -26,7 +26,7 @@ uintmax_t strtoumax(const char *s1, char **p, int base)
|
||||
|
||||
if (ip.err) {
|
||||
errno = ip.err;
|
||||
if (ip.err = EINVAL) return 0;
|
||||
if (ip.err == EINVAL) return 0;
|
||||
return UINTMAX_MAX;
|
||||
}
|
||||
|
||||
|
||||
@@ -6,6 +6,7 @@
|
||||
|
||||
intmax_t wcstoimax(const wchar_t *s, wchar_t **p, int base)
|
||||
{
|
||||
const wchar_t *s1 = s;
|
||||
struct intparse ip = {0};
|
||||
|
||||
if (p) *p = (wchar_t *)s;
|
||||
@@ -21,11 +22,11 @@ intmax_t wcstoimax(const wchar_t *s, wchar_t **p, int base)
|
||||
for (; __intparse(&ip, (char[]){(*s&-(*s<128U))}, 1); s++);
|
||||
|
||||
if (p && ip.err != EINVAL)
|
||||
*p = (wchar_t *)s;
|
||||
*p = (wchar_t *)s1 + ip.cnt;
|
||||
|
||||
if (ip.err) {
|
||||
errno = ip.err;
|
||||
if (ip.err = EINVAL) return 0;
|
||||
if (ip.err == EINVAL) return 0;
|
||||
return ip.neg ? INTMAX_MIN : INTMAX_MAX;
|
||||
}
|
||||
|
||||
|
||||
@@ -7,6 +7,7 @@
|
||||
|
||||
uintmax_t wcstoumax(const wchar_t *s, wchar_t **p, int base)
|
||||
{
|
||||
const wchar_t *s1 = s;
|
||||
struct intparse ip = {0};
|
||||
|
||||
if (p) *p = (wchar_t *)s;
|
||||
@@ -22,11 +23,11 @@ uintmax_t wcstoumax(const wchar_t *s, wchar_t **p, int base)
|
||||
for (; __intparse(&ip, (char[]){(*s&-(*s<128U))}, 1); s++);
|
||||
|
||||
if (p && ip.err != EINVAL)
|
||||
*p = (wchar_t *)s;
|
||||
*p = (wchar_t *)s1 + ip.cnt;
|
||||
|
||||
if (ip.err) {
|
||||
errno = ip.err;
|
||||
if (ip.err = EINVAL) return 0;
|
||||
if (ip.err == EINVAL) return 0;
|
||||
return UINTMAX_MAX;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user