libc/stdlib: If there were no digits at all, strtoul() stores the original value of nptr in *endptr (and returns 0).

Reference: STRTOUL(3)

Signed-off-by: wangjianyu3 <wangjianyu3@xiaomi.com>
This commit is contained in:
wangjianyu3 2023-12-26 11:21:43 +08:00 committed by Xiang Xiao
parent 9773fb9867
commit 02f1503f9f
2 changed files with 4 additions and 4 deletions

View File

@ -52,9 +52,10 @@
unsigned long strtoul(FAR const char *nptr, FAR char **endptr, int base)
{
FAR const char *origin = nptr;
unsigned long accum = 0;
unsigned long limit;
int value;
int value = -1;
int last_digit;
char sign = 0;
@ -79,7 +80,6 @@ unsigned long strtoul(FAR const char *nptr, FAR char **endptr, int base)
if (base < 0)
{
set_errno(EINVAL);
accum = 0;
}
else
{
@ -127,7 +127,7 @@ unsigned long strtoul(FAR const char *nptr, FAR char **endptr, int base)
}
}
*endptr = (FAR char *)nptr;
*endptr = (FAR char *)(value == -1 ? origin : nptr);
}
return accum;

View File

@ -80,7 +80,7 @@ bool lib_isbasedigit(int ch, int base, int *value)
}
}
if (value)
if (ret && value)
{
*value = tmp;
}