mirror of
https://github.com/byteworksinc/ORCA-C.git
synced 2024-12-22 23:29:27 +00:00
Prevent struct/union members from having incomplete type, except for flexible array member.
ORCA/C previously allowed struct/union members to be declared with incomplete type. Because of this, it allowed C99-style flexible array members to be declared, albeit by accident rather than by design. In some basic testing, these seem to work correctly, except that they could be initialized and that would give rise to odd behavior. I have restricted it to allowing flexible array members only in the cases allowed by C99/C11, and otherwise disallowing members with incomplete type. I have also prohibited initializing flexible array members.
This commit is contained in:
parent
972b0109a4
commit
45cc0a0721
13
Parser.pas
13
Parser.pas
@ -2298,7 +2298,8 @@ var
|
|||||||
count := tp^.size;
|
count := tp^.size;
|
||||||
ip := tp^.fieldList;
|
ip := tp^.fieldList;
|
||||||
bitCount := 0;
|
bitCount := 0;
|
||||||
while (ip <> nil) and (token.kind <> rbracech) do begin
|
while (ip <> nil) and (ip^.itype^.size > 0)
|
||||||
|
and (token.kind <> rbracech) do begin
|
||||||
if ip^.isForwardDeclared then
|
if ip^.isForwardDeclared then
|
||||||
ResolveForwardReference(ip);
|
ResolveForwardReference(ip);
|
||||||
InitializeTerm(ip^.itype, ip^.bitsize, ip^.bitdisp, false);
|
InitializeTerm(ip^.itype, ip^.bitsize, ip^.bitdisp, false);
|
||||||
@ -2449,6 +2450,7 @@ var
|
|||||||
lstorageClass: tokenEnum; {storage class of the declaration}
|
lstorageClass: tokenEnum; {storage class of the declaration}
|
||||||
maxDisp: longint; {for determining union sizes}
|
maxDisp: longint; {for determining union sizes}
|
||||||
variable: identPtr; {variable being defined}
|
variable: identPtr; {variable being defined}
|
||||||
|
didFlexibleArray: boolean; {have we seen a flexible array member?}
|
||||||
|
|
||||||
begin {FieldList}
|
begin {FieldList}
|
||||||
ldoingParameters := doingParameters; {allow fields in K&R dec. area}
|
ldoingParameters := doingParameters; {allow fields in K&R dec. area}
|
||||||
@ -2459,6 +2461,7 @@ var
|
|||||||
bitDisp := 0; {start allocation from byte 0}
|
bitDisp := 0; {start allocation from byte 0}
|
||||||
disp := 0;
|
disp := 0;
|
||||||
maxDisp := 0;
|
maxDisp := 0;
|
||||||
|
didFlexibleArray := false;
|
||||||
fl := nil; {nothing in the field list, yet}
|
fl := nil; {nothing in the field list, yet}
|
||||||
{check for no declarations}
|
{check for no declarations}
|
||||||
if not (token.kind in [unsignedsy,signedsy,intsy,longsy,charsy,shortsy,
|
if not (token.kind in [unsignedsy,signedsy,intsy,longsy,charsy,shortsy,
|
||||||
@ -2473,6 +2476,8 @@ var
|
|||||||
TypeSpecifier(true,false); {get the type specifier}
|
TypeSpecifier(true,false); {get the type specifier}
|
||||||
if not skipDeclarator then
|
if not skipDeclarator then
|
||||||
repeat {declare the variables...}
|
repeat {declare the variables...}
|
||||||
|
if didFlexibleArray then
|
||||||
|
Error(118);
|
||||||
variable := nil;
|
variable := nil;
|
||||||
if token.kind <> colonch then begin
|
if token.kind <> colonch then begin
|
||||||
Declarator(typeSpec, variable, fieldListSpace, false);
|
Declarator(typeSpec, variable, fieldListSpace, false);
|
||||||
@ -2535,6 +2540,12 @@ var
|
|||||||
disp := disp + variable^.itype^.size;
|
disp := disp + variable^.itype^.size;
|
||||||
if disp > maxDisp then
|
if disp > maxDisp then
|
||||||
maxDisp := disp;
|
maxDisp := disp;
|
||||||
|
if variable^.itype^.size = 0 then
|
||||||
|
if (variable^.itype^.kind = arrayType)
|
||||||
|
and (disp > 0) then {handle flexible array member}
|
||||||
|
didFlexibleArray := true
|
||||||
|
else
|
||||||
|
Error(117);
|
||||||
end {if}
|
end {if}
|
||||||
else
|
else
|
||||||
Error(116);
|
Error(116);
|
||||||
|
@ -597,6 +597,8 @@ if list or (numErr <> 0) then begin
|
|||||||
114: msg := @'a function call was made to a non-function';
|
114: msg := @'a function call was made to a non-function';
|
||||||
115: msg := @'illegal bit field declaration';
|
115: msg := @'illegal bit field declaration';
|
||||||
116: msg := @'missing field name';
|
116: msg := @'missing field name';
|
||||||
|
117: msg := @'field cannot have incomplete type';
|
||||||
|
118: msg := @'flexible array must be last member of structure';
|
||||||
otherwise: Error(57);
|
otherwise: Error(57);
|
||||||
end; {case}
|
end; {case}
|
||||||
writeln(msg^);
|
writeln(msg^);
|
||||||
|
Loading…
Reference in New Issue
Block a user