fix some bug of strtold

with the test of sim:lua ,I have fixed some bug of error output
  1.input: "  " and error output string is "NULL"
  2.input: "1.2e+", error output string is "NULL"
  3.input: "."      error output string is "NULL"
This commit is contained in:
lilei19 2023-02-10 17:39:13 +08:00 committed by Xiang Xiao
parent 807d59632c
commit 23344846f6

View File

@ -119,7 +119,7 @@ static long_long scanexp(FAR char **f, bool flag)
c = shgetc(s);
if (c == '+' || c == '-')
if ((c == '+' || c == '-') && isdigit(*s))
{
neg = (c == '-');
c = shgetc(s);
@ -335,13 +335,6 @@ static long_double decfloat(FAR char *ptr, FAR char **endptr)
}
}
if (num_digit == 0)
{
shunget(f);
ifexist(endptr, f);
return zero;
}
if ((c | 32) == 'e')
{
num_decimal = scanexp(&f, 1) + num_decimal;
@ -357,6 +350,11 @@ static long_double decfloat(FAR char *ptr, FAR char **endptr)
}
ifexist(endptr, f);
if (num_digit == 0)
{
return zero;
}
f = ptr;
k = 0;
@ -475,7 +473,7 @@ static long_double hexfloat(FAR char *ptr,
}
}
for (; c - '0' < 10 || (c | 32) - 'a' < 6 || c == '.'; c = shgetc(f))
for (; isxdigit(c) || c == '.'; c = shgetc(f))
{
if (c == '.')
{
@ -519,7 +517,6 @@ static long_double hexfloat(FAR char *ptr,
if (!gotdig)
{
shunget(f);
shunget(f);
if (gotrad)
{
@ -642,7 +639,7 @@ static long_double hexfloat(FAR char *ptr,
static long_double strtox(FAR const char *str, FAR char **endptr, int flag)
{
FAR char *s = (FAR char *)str;
int negative = 0;
bool negative = 0;
long_double y = 0;
int i = 0;
@ -662,6 +659,7 @@ static long_double strtox(FAR const char *str, FAR char **endptr, int flag)
case 3:
bits = LDBL_MANT_DIG,
emin = LDBL_MIN_EXP - bits;
break;
default:
return 0;
}
@ -718,10 +716,15 @@ static long_double strtox(FAR const char *str, FAR char **endptr, int flag)
s += 2;
y = hexfloat(s, endptr, bits, emin);
}
else
else if (isdigit(*s) || (*s == '.' && isdigit(*(s + 1))))
{
y = decfloat(s, endptr);
}
else
{
ifexist(endptr, (FAR char *)str);
return 0;
}
return negative ? -y : y;
}