Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 15 additions & 12 deletions libs/libc/stdlib/lib_strtold.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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 == '.')
{
Expand Down Expand Up @@ -519,7 +517,6 @@ static long_double hexfloat(FAR char *ptr,

if (!gotdig)
{
shunget(f);
shunget(f);
if (gotrad)
{
Expand Down Expand Up @@ -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;

Expand All @@ -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;
}
Expand Down Expand Up @@ -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;
}
Expand Down