Imported Upstream version 2.9.0
[debian/cc1111] / support / regression / tests / bug1505811.c
1 /* bug 1505811
2  *   demonstrates an incorrect "loopreverse"
3  *   note func0, is a kind of safeguard, the incorrect code
4  *     will access indices 0 and 1 instead of 1 and 2,
5  *     and with incorrect order
6  */
7
8 #include <testfwk.h>
9
10 char glbl;
11
12 void func0() { glbl = 0; }
13 void func1() { glbl = 1; }
14 void func2() { glbl = 2; }
15
16 typedef void (*fptr)();
17
18 fptr ep_init[3] = { func0, func1, func2 };
19
20 void buggy()
21 {
22   unsigned char i;
23   for(i = 1; i <= 2; i++)
24   {
25     ep_init[i]();
26   }
27 }
28
29 void
30 testBug(void)
31 {
32   buggy();
33   ASSERT(glbl == 2);
34 }