From f5cd1e3e3adc4aeacc4f26f7fc8feb671e820316 Mon Sep 17 00:00:00 2001 From: Stephen Heumann Date: Tue, 28 Jan 2020 12:48:09 -0600 Subject: [PATCH] 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. --- Parser.pas | 19 +++++++++++++++++++ Scanner.pas | 1 + 2 files changed, 20 insertions(+) diff --git a/Parser.pas b/Parser.pas index 2553008..44b03d3 100644 --- a/Parser.pas +++ b/Parser.pas @@ -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 diff --git a/Scanner.pas b/Scanner.pas index 82403f9..844500a 100644 --- a/Scanner.pas +++ b/Scanner.pas @@ -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^);