summaryrefslogtreecommitdiff
path: root/support/regression/tests/bug1505811.c
blob: ddb4e0ab864150cbb717ea6d9996eac552e0828f (plain) (blame)
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
/* bug 1505811
 *   demonstrates an incorrect "loopreverse"
 *   note func0, is a kind of safeguard, the incorrect code
 *     will access indices 0 and 1 instead of 1 and 2,
 *     and with incorrect order
 */

#include <testfwk.h>

char glbl;

void func0() { glbl = 0; }
void func1() { glbl = 1; }
void func2() { glbl = 2; }

typedef void (*fptr)();

fptr ep_init[3] = { func0, func1, func2 };

void buggy()
{
  unsigned char i;
  for(i = 1; i <= 2; i++)
  {
    ep_init[i]();
  }
}

void
testBug(void)
{
  buggy();
  ASSERT(glbl == 2);
}