4 The wrong location is used for a local variable; observable effects vary by backend.
5 For stm8, this results in overwriting other local variables.
6 For z80, it results in use of location below the stack.
14 #pragma disable_warning 88
20 static volatile uint8_t* f(const uint8_t id
)
22 volatile uint8_t* result
= 0; // Bug: For stm8, this variable is accessed at stack at sp+255, overwriting part of buffer.
26 result
= (volatile uint8_t *)0x5000;
29 result
= (volatile uint8_t *)0x5005;
32 result
= (volatile uint8_t *)0x500a;
35 g(); // This call overwrites result by the return address for z80.
39 #if defined (__SDCC_pdk14) || defined (__SDCC_pdk15) || defined (__SDCC_mcs51) || defined (__SDCC_STACK_AUTO) // Lack of memory
42 #define BUFFERSIZE 300
47 unsigned char buffer
[BUFFERSIZE
]; // Bug: Overwritten in f() on stm8.
49 memset(buffer
, 0xa5, BUFFERSIZE
);
51 ASSERT(f(0) == (volatile uint8_t *)0x5000);
52 ASSERT(f(1) == (volatile uint8_t *)0x5005);
53 ASSERT(f(2) == (volatile uint8_t *)0x500a);
55 for(size_t i
= 0; i
< BUFFERSIZE
; i
++)
56 ASSERT (buffer
[i
] == 0xa5);