Fix problem where if a macro's name appeared inside the macro, it would be expanded repeatedly, leading to a crash.

This is a problem introduced by the scanner changes between ORCA/C 2.1.0 and ORCA/C 2.1.1 B3.

The following examples demonstrate the problem:

#define m m
m

#define f(x) f(x)
f(a)
This commit is contained in:
Stephen Heumann 2016-12-17 22:34:21 -06:00
parent 5c81d970b5
commit d0b4b75970

View File

@ -1308,7 +1308,7 @@ if macro^.parameters >= 0 then begin {find the values of the parameters}
if not gettingFileName then {put back the source stream token} if not gettingFileName then {put back the source stream token}
PutBackToken(token, true); PutBackToken(token, true);
Error(12); Error(12);
end; end; {if}
end {if} end {if}
else begin else begin
Error(13); Error(13);
@ -3552,6 +3552,7 @@ var
expandEnabled: boolean; {can a token be expanded?} expandEnabled: boolean; {can a token be expanded?}
i: 0..maxint; {loop/index counter} i: 0..maxint; {loop/index counter}
inhibit: boolean; {inhibit macro expansion?} inhibit: boolean; {inhibit macro expansion?}
lExpandMacros: boolean; {local copy of expandMacros}
lPrintMacroExpansions: boolean; {local copy of printMacroExpansions} lPrintMacroExpansions: boolean; {local copy of printMacroExpansions}
mPtr: macroRecordPtr; {for checking list of macros} mPtr: macroRecordPtr; {for checking list of macros}
setLength: boolean; {is the current string a p-string?} setLength: boolean; {is the current string a p-string?}
@ -3652,7 +3653,10 @@ if tokenList <> nil then begin {get a token put back by a macro}
token.kind := ident; token.kind := ident;
if token.kind = ident then begin if token.kind = ident then begin
CopyString(@workString, token.name); CopyString(@workString, token.name);
lExpandMacros := expandMacros;
expandMacros := false;
CheckIdentifier; CheckIdentifier;
expandMacros := lExpandMacros;
end; {if} end; {if}
{ dead code { dead code
if token.kind = ident then if token.kind = ident then