From 740468f75c5c2b60ffeb029c02f4c3afd99992c6 Mon Sep 17 00:00:00 2001 From: Stephen Heumann Date: Sat, 26 Nov 2022 14:20:58 -0600 Subject: [PATCH] Avoid generating invalid .sym files if header ends with a partial prototyped function decl. This could happen because the nested calls to DoDeclaration for the parameters would set inhibitHeader to false. --- Parser.pas | 10 ++++++---- cc.notes | 2 +- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/Parser.pas b/Parser.pas index 5099be6..d1dc492 100644 --- a/Parser.pas +++ b/Parser.pas @@ -3496,6 +3496,7 @@ var isPascal: boolean; {has the pascal modifier been used?} alignmentSpecified: boolean; {was an alignment explicitly specified?} lDoingParameters: boolean; {local copy of doingParameters} + lInhibitHeader: boolean; {local copy of inhibitHeader} lp,tlp,tlp2: identPtr; {for tracing parameter list} lUseGlobalPool: boolean; {local copy of useGlobalPool} nextPdisp: integer; {for calculating parameter disps} @@ -3699,6 +3700,7 @@ var begin {DoDeclaration} +lInhibitHeader:= inhibitHeader; inhibitHeader := true; {block imbedded includes in headers} if token.kind = _Static_assertsy then begin DoStaticAssert; @@ -3734,7 +3736,7 @@ isFunction := false; {assume it's not a function} variable := nil; Declarator(declSpecifiers, variable, variableSpace, doingPrototypes); if variable = nil then begin - inhibitHeader := false; + inhibitHeader := lInhibitHeader; if token.kind = semicolonch then begin if not first then Error(176); @@ -3830,7 +3832,7 @@ if isFunction then begin end; {with} doingParameters := doingPrototypes; {not doing parms any more} if token.kind = semicolonch then begin - inhibitHeader := false; + inhibitHeader := lInhibitHeader; NextToken; {skip the trailing semicolon} end {if} else if (token.kind = commach) and (not doingPrototypes) then begin @@ -4085,7 +4087,7 @@ else {if not isFunction then} begin protoType := protoVariable^.iType; end {if} else begin - inhibitHeader := false; + inhibitHeader := lInhibitHeader; if token.kind = semicolonch then {must end with a semicolon} NextToken else begin @@ -4098,7 +4100,7 @@ else {if not isFunction then} begin doingParameters := lDoingParameters; {restore the status} useGlobalPool := lUseGlobalPool; 4: -inhibitHeader := false; +inhibitHeader := lInhibitHeader; end; {DoDeclaration} diff --git a/cc.notes b/cc.notes index d6188b4..4ec4255 100644 --- a/cc.notes +++ b/cc.notes @@ -1974,7 +1974,7 @@ int foo(int[42]); 219. If a function is first declared as "static" and then subsequently redeclared or defined as "extern" or with no storage-class specifier, it should be private to the source file, the same as if it was just declared "static". -220. A header that ended with a partial declaration would not be represented correctly in the .sym file. This could cause errors or misbehavior on subsequent compiles. +220. In certain cases where a header starts or ends in the middle of a declaration, it would not be represented correctly in the .sym file. This could cause errors or misbehavior on subsequent compiles. -- Bugs from C 2.1.0 that have been fixed -----------------------------------