Recognize designated initializers enough to give an error and skip them.

Previously, the designated initializer syntax could confuse the parser enough to cause null pointer dereferences. This avoids that, and also gives a more meaningful error message to the user.
This commit is contained in:
Stephen Heumann 2020-01-28 12:48:09 -06:00
parent 58630dedc1
commit f5cd1e3e3a
2 changed files with 20 additions and 0 deletions

View File

@ -1896,6 +1896,25 @@ var
begin {GetInitializerValue}
if token.kind in [dotch,lbrackch] then begin
{designated initializer: give error and skip over it}
Error(150);
while token.kind in [dotch,lbrackch] do begin
if token.kind = lbrackch then begin
NextToken;
Expression(arrayExpression, [rbrackch]);
if token.kind = rbrackch then
NextToken;
end {if}
else {if token.kind = dotch then} begin
NextToken;
if token.kind in [ident,typedef] then
NextToken;
end {if}
end; {while}
if token.kind = eqch then
NextToken;
end; {if}
if variable^.storage = stackFrame then
Expression(autoInitializerExpression, [commach,rparench,rbracech])
else

View File

@ -672,6 +672,7 @@ if list or (numErr <> 0) then begin
147: msg := @'lint: not all parameters were declared with a type';
148: msg := @'all parameters must have a complete type';
149: msg := @'invalid universal character name for use in an identifier';
150: msg := @'designated initializers are not supported by ORCA/C';
otherwise: Error(57);
end; {case}
writeln(msg^);