summaryrefslogtreecommitdiff
path: root/support/regression/tests/bug3440327.c
blob: 5cf4eb9c83288ad2c6f4f45e81b06f75ef92e42f (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
62
63
64
65
66
67
68
69
70
71
/*
   bug3440327.c
 */

#include <testfwk.h>
#if !defined(__SDCC_pic14) // Unimplemented setjmp
#include <setjmp.h>
#endif

#if defined(__SDCC_mcs51) || defined(__SDCC_z80) || defined(__SDCC_z80n) || defined(__PORT_HOST)

jmp_buf b;

#define DIM 2
typedef struct
{
	char id;
	int (*f)(char c);
} fstruct;

int j;

int fnct(char c)
{
	static int i;
	i = i + c + 1;
	if (i == 4)
	{
		j = 42;
		longjmp (b, 0);
	}
	return 0;
}

fstruct tab[DIM]={{2, fnct}, {3, 0}};

int bug(void)
{
	register fstruct *dt = tab;
	char val;

	while (dt < tab+DIM)
	{
		val = 0;
		while (val < dt->id)
		{
			(dt->f)(val); /* Wrong pointer used here */
		}
		++dt;
	}

	return 0;
}

#endif

void testBug (void)
{
#if defined(__SDCC_mcs51) || defined(__SDCC_z80) || defined(__SDCC_z80n) || defined(__PORT_HOST)
	if (setjmp (b))
	{
		ASSERT (j == 42);
	}
	else
	{
		bug ();
		ASSERT (0);
	}
#endif
}