summaryrefslogtreecommitdiff
path: root/support/regression/tests/bug1536762.c
blob: f70b4b6073a19d17543ee405a5640716e7c5fec8 (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
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
/*
   bug1536762.c
*/

#include <testfwk.h>
#include <string.h>
#include <stdint.h>

__xdata uint8_t c = 1;

struct d {
  __xdata struct d *n;
  uint8_t f;
  uint8_t s;
  __xdata uint8_t *buffer;
  uint16_t length;
};


__xdata struct d xd = {&xd, 1, 0xab, &c, 3};


struct {
  __xdata struct d *c;
  int16_t count;
  __xdata uint8_t *bptr;
} s = {&xd, -1, &c};


void
blurb (void)
{
  if (s.count < 0)
    {
      s.c->s = 0xef;
      s.count = s.c->length - 1;
      s.bptr = s.c->buffer;
    }
  *s.bptr = 0;
  s.bptr++;
  s.count--;
}


void 
testBug (void)
{
  ASSERT (xd.s == 0xab);
  ASSERT (s.c->s == 0xab);
  
  s.c->s = 0xcd;

  ASSERT (xd.s == 0xcd);
  ASSERT (s.c->s == 0xcd);

  blurb ();

  ASSERT (xd.s == 0xef);
  ASSERT (s.c->s == 0xef);
  ASSERT (c == 0);
}