mirror of
https://github.com/byteworksinc/ORCA-C.git
synced 2025-01-05 08:30:59 +00:00
Fix invalid static initialization of bitfields occupying three bytes.
An extra, fourth byte was being generated for the bitfield(s). This would cause all subsequent members of the struct and any enclosing object not to be initialized at the proper locations, which would generally corrupt their values. The following program illustrates the issue: #include <stdio.h> struct X { int a:9; int b:9; int c; } x = {123,234,12345}; int main(void) { printf("x.a = %i, x.b = %i, x.b = %i\n", x.a, x.b, x.c); }
This commit is contained in:
parent
0cfed00b52
commit
0b8d4ce3e4
17
Parser.pas
17
Parser.pas
@ -1765,12 +1765,19 @@ var
|
||||
iPtr^.bitsize := 0;
|
||||
iPtr^.isStructOrUnion := false;
|
||||
iPtr^.iVal := bitvalue;
|
||||
if bitcount > 16 then
|
||||
iPtr^.itype := cgULong
|
||||
else if bitcount > 8 then
|
||||
if bitcount <= 8 then
|
||||
iPtr^.itype := cgUByte
|
||||
else if bitcount <= 16 then
|
||||
iPtr^.itype := cgUWord
|
||||
else
|
||||
iPtr^.itype := cgUByte;
|
||||
else if bitcount > 24 then
|
||||
iPtr^.itype := cgULong
|
||||
else begin {3-byte bitfield: split into two parts}
|
||||
iPtr^.itype := cgUWord;
|
||||
iPtr^.iVal := bitvalue & $0000FFFF;
|
||||
bitcount := bitcount - 16;
|
||||
bitvalue := bitvalue >> 16;
|
||||
InitializeBitField;
|
||||
end;
|
||||
bitcount := 0; {reset the bit field values}
|
||||
bitvalue := 0;
|
||||
end; {if}
|
||||
|
Loading…
Reference in New Issue
Block a user