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:
parent
9773fb9867
commit
02f1503f9f
@ -52,9 +52,10 @@
|
|||||||
|
|
||||||
unsigned long strtoul(FAR const char *nptr, FAR char **endptr, int base)
|
unsigned long strtoul(FAR const char *nptr, FAR char **endptr, int base)
|
||||||
{
|
{
|
||||||
|
FAR const char *origin = nptr;
|
||||||
unsigned long accum = 0;
|
unsigned long accum = 0;
|
||||||
unsigned long limit;
|
unsigned long limit;
|
||||||
int value;
|
int value = -1;
|
||||||
int last_digit;
|
int last_digit;
|
||||||
char sign = 0;
|
char sign = 0;
|
||||||
|
|
||||||
@ -79,7 +80,6 @@ unsigned long strtoul(FAR const char *nptr, FAR char **endptr, int base)
|
|||||||
if (base < 0)
|
if (base < 0)
|
||||||
{
|
{
|
||||||
set_errno(EINVAL);
|
set_errno(EINVAL);
|
||||||
accum = 0;
|
|
||||||
}
|
}
|
||||||
else
|
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;
|
return accum;
|
||||||
|
@ -80,7 +80,7 @@ bool lib_isbasedigit(int ch, int base, int *value)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (value)
|
if (ret && value)
|
||||||
{
|
{
|
||||||
*value = tmp;
|
*value = tmp;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user