summaryrefslogtreecommitdiff
path: root/support/regression/tests/bug-524697.c
blob: 7c6943e5514bb5186409c4a381661a1186034f42 (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
/* Bad addition for adding a length and char[]
 */
#include <testfwk.h>

#if defined(__SDCC_mcs51)
#define SZ_SIZE 89
#else
#define SZ_SIZE 90
#endif

#if !defined(__SDCC_pdk14) && !defined(__SDCC_pic14) // Lack of memory
typedef struct _Foo
{
  char sz[SZ_SIZE];
} Foo;

typedef struct _Bar
{
  unsigned int uLen;
} Bar;

char *getOffset(Foo *pFoo, Bar *pBar)
{
  return pFoo->sz + pBar->uLen;
}
#endif

void
testOffset(void)
{
#if !defined(__SDCC_pdk14) && !defined(__SDCC_pic14) // Lack of memory
  Foo foo = {
    "Foo"
  };
  Bar bar = {
    3
  };

  ASSERT(getOffset(&foo, &bar) 
	 == (((char *)&foo) + 3));
#endif
}