1 /** bug-2681.c
2     A bug which resulted in LLVM-compiled SDCC crashing.
3 */
4 #include <testfwk.h>
5 
6 #include <ctype.h>
7 #include <stdlib.h>
8 
9 #if !defined(__SDCC_pdk14) && !defined(__SDCC_pdk15) // Not enough memory
simplified_atof(const char * s)10 float simplified_atof(const char * s)
11 {
12     float value, fraction;
13     signed char iexp;
14 
15     for (value=0.0; isdigit(*s); s++)
16     {
17         value=10.0*value+(*s-'0');
18     }
19 
20     if (*s == '.')
21     {
22         s++;
23         for (fraction=0.1; isdigit(*s); s++)
24         {
25             value+=(*s-'0')*fraction;
26             fraction*=0.1;
27         }
28     }
29 
30     if (toupper(*s)=='E')
31     {
32         s++;
33         iexp=(signed char)atoi(s);
34         {
35             while(iexp!=0)
36             {
37                 if(iexp<0)
38                 {
39                     value*=0.1;
40                     iexp++;
41                 }
42                 else
43                 {
44                     value*=10.0;
45                     iexp--;
46                 }
47             }
48         }
49     }
50 
51     return (value);
52 }
53 #endif
54 
testBug(void)55 void testBug(void)
56 {
57 #if !defined(__SDCC_pdk14) && !defined(__SDCC_pdk15) // Not enough memory
58   ASSERT(simplified_atof("0.0f") == 0.0f);
59 #endif
60 }
61 
62