summaryrefslogtreecommitdiff
path: root/support/regression/tests/bug-2681.c
blob: 0b6b4e8194b6b349d45feed91f78228f9b3fd5f2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
/** bug-2681.c
    A bug which resulted in LLVM-compiled SDCC crashing.
*/
#include <testfwk.h>

#include <ctype.h>
#include <stdlib.h>

#if !defined(__SDCC_pdk14) && !defined(__SDCC_pdk15) // Not enough memory
float simplified_atof(const char * s)
{
    float value, fraction;
    signed char iexp;

    for (value=0.0; isdigit(*s); s++)
    {
        value=10.0*value+(*s-'0');
    }

    if (*s == '.')
    {
        s++;
        for (fraction=0.1; isdigit(*s); s++)
        {
            value+=(*s-'0')*fraction;
            fraction*=0.1;
        }
    }

    if (toupper(*s)=='E')
    {
        s++;
        iexp=(signed char)atoi(s);
        {
            while(iexp!=0)
            {
                if(iexp<0)
                {
                    value*=0.1;
                    iexp++;
                }
                else
                {
                    value*=10.0;
                    iexp--;
                }
            }
        }
    }

    return (value);
}
#endif

void testBug(void)
{
#if !defined(__SDCC_pdk14) && !defined(__SDCC_pdk15) // Not enough memory
  ASSERT(simplified_atof("0.0f") == 0.0f);
#endif
}