-
Type:
Bug
-
Resolution: Fixed
-
Priority:
Medium
-
Code Generation Tools
-
CODEGEN-9407
-
-
-
-
default
-
Explicitly initializing the last array element's struct's members will avoid the issue.
For flexible array's of structs, if the last array element has implicitly initialized struct members, then the generated code incorrectly handles the last array element's initialization. No space is allocated for the implicitly initialized portion of the last element. Other variables may get allocated over that location.
The attached file.c has these lines ...
typedef struct {
unsigned a;
unsigned b;
} entry_t;
typedef struct {
unsigned len;
entry_t entries[];
} array_t;
const array_t array = {
.len = 3,
.entries = {
{ .a = 1,},
{ .a = 2},
{ .a = 3},
},
};
Build it ...
% cl2000 -s file.c
Inspect the resulting assembly file ...
_array:
.bits 0x3,16
; _array._len @ 0
.bits 0x1,16
; _array[0]._a @ 16
.space 16
.bits 0x2,16
; _array[1]._a @ 48
.space 16
.bits 0x3,16
; _array[2]._a @ 80
There should be one more line of ".space 16", so that array[3].b is set to 0. Instead it ends up having the value of whatever is next in memory.