1
0
mirror of https://github.com/cc65/cc65.git synced 2024-12-24 11:31:31 +00:00

Fix endless loop on expanding a recursive macro, fixed issue #1678, patch by kugelfuhr

This commit is contained in:
mrdudz 2022-05-09 21:26:45 +02:00
parent b8d0bd7f95
commit 3943dc1216

View File

@ -801,9 +801,6 @@ static void StartExpClassic (MacExp* E)
{ {
token_t Term; token_t Term;
/* Skip the macro name */
NextTok ();
/* Does this invocation have any arguments? */ /* Does this invocation have any arguments? */
if (!TokIsSep (CurTok.Tok)) { if (!TokIsSep (CurTok.Tok)) {
@ -887,9 +884,6 @@ static void StartExpDefine (MacExp* E)
*/ */
unsigned Count = E->M->ParamCount; unsigned Count = E->M->ParamCount;
/* Skip the current token */
NextTok ();
/* Read the actual parameters */ /* Read the actual parameters */
while (Count--) { while (Count--) {
TokNode* Last; TokNode* Last;
@ -965,14 +959,19 @@ static void StartExpDefine (MacExp* E)
void MacExpandStart (Macro* M) void MacExpandStart (Macro* M)
/* Start expanding a macro */ /* Start expanding a macro */
{ {
FilePos Pos;
MacExp* E; MacExp* E;
/* Check the argument */ /* Check the argument */
PRECONDITION (M && (M->Style != MAC_STYLE_DEFINE || DisableDefines == 0)); PRECONDITION (M && (M->Style != MAC_STYLE_DEFINE || DisableDefines == 0));
/* Remember the current file position, then skip the macro name token */
Pos = CurTok.Pos;
NextTok ();
/* We cannot expand an incomplete macro */ /* We cannot expand an incomplete macro */
if (M->Incomplete) { if (M->Incomplete) {
Error ("Cannot expand an incomplete macro"); PError (&Pos, "Cannot expand an incomplete macro");
return; return;
} }
@ -980,7 +979,7 @@ void MacExpandStart (Macro* M)
** to force an endless loop and assembler crash. ** to force an endless loop and assembler crash.
*/ */
if (MacExpansions >= MAX_MACEXPANSIONS) { if (MacExpansions >= MAX_MACEXPANSIONS) {
Error ("Too many nested macro expansions"); PError (&Pos, "Too many nested macro expansions");
return; return;
} }