@@ -119,7 +119,7 @@ static long_long scanexp(FAR char **f, bool flag)
119
119
120
120
c = shgetc (s );
121
121
122
- if (c == '+' || c == '-' )
122
+ if (( c == '+' || c == '-' ) && isdigit ( * s ) )
123
123
{
124
124
neg = (c == '-' );
125
125
c = shgetc (s );
@@ -335,13 +335,6 @@ static long_double decfloat(FAR char *ptr, FAR char **endptr)
335
335
}
336
336
}
337
337
338
- if (num_digit == 0 )
339
- {
340
- shunget (f );
341
- ifexist (endptr , f );
342
- return zero ;
343
- }
344
-
345
338
if ((c | 32 ) == 'e' )
346
339
{
347
340
num_decimal = scanexp (& f , 1 ) + num_decimal ;
@@ -357,6 +350,11 @@ static long_double decfloat(FAR char *ptr, FAR char **endptr)
357
350
}
358
351
359
352
ifexist (endptr , f );
353
+ if (num_digit == 0 )
354
+ {
355
+ return zero ;
356
+ }
357
+
360
358
f = ptr ;
361
359
362
360
k = 0 ;
@@ -475,7 +473,7 @@ static long_double hexfloat(FAR char *ptr,
475
473
}
476
474
}
477
475
478
- for (; c - '0' < 10 || ( c | 32 ) - 'a' < 6 || c == '.' ; c = shgetc (f ))
476
+ for (; isxdigit ( c ) || c == '.' ; c = shgetc (f ))
479
477
{
480
478
if (c == '.' )
481
479
{
@@ -519,7 +517,6 @@ static long_double hexfloat(FAR char *ptr,
519
517
520
518
if (!gotdig )
521
519
{
522
- shunget (f );
523
520
shunget (f );
524
521
if (gotrad )
525
522
{
@@ -642,7 +639,7 @@ static long_double hexfloat(FAR char *ptr,
642
639
static long_double strtox (FAR const char * str , FAR char * * endptr , int flag )
643
640
{
644
641
FAR char * s = (FAR char * )str ;
645
- int negative = 0 ;
642
+ bool negative = 0 ;
646
643
long_double y = 0 ;
647
644
int i = 0 ;
648
645
@@ -662,6 +659,7 @@ static long_double strtox(FAR const char *str, FAR char **endptr, int flag)
662
659
case 3 :
663
660
bits = LDBL_MANT_DIG ,
664
661
emin = LDBL_MIN_EXP - bits ;
662
+ break ;
665
663
default :
666
664
return 0 ;
667
665
}
@@ -718,10 +716,15 @@ static long_double strtox(FAR const char *str, FAR char **endptr, int flag)
718
716
s += 2 ;
719
717
y = hexfloat (s , endptr , bits , emin );
720
718
}
721
- else
719
+ else if ( isdigit ( * s ) || ( * s == '.' && isdigit ( * ( s + 1 ))))
722
720
{
723
721
y = decfloat (s , endptr );
724
722
}
723
+ else
724
+ {
725
+ ifexist (endptr , (FAR char * )str );
726
+ return 0 ;
727
+ }
725
728
726
729
return negative ? - y : y ;
727
730
}
0 commit comments