From 3943dc1216fbc0b9e14c7bb706ecbc867f3b4029 Mon Sep 17 00:00:00 2001 From: mrdudz Date: Mon, 9 May 2022 21:26:45 +0200 Subject: [PATCH] Fix endless loop on expanding a recursive macro, fixed issue #1678, patch by kugelfuhr --- src/ca65/macro.c | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/src/ca65/macro.c b/src/ca65/macro.c index 0bdc89b5b..d9f1f385c 100644 --- a/src/ca65/macro.c +++ b/src/ca65/macro.c @@ -801,9 +801,6 @@ static void StartExpClassic (MacExp* E) { token_t Term; - /* Skip the macro name */ - NextTok (); - /* Does this invocation have any arguments? */ if (!TokIsSep (CurTok.Tok)) { @@ -887,9 +884,6 @@ static void StartExpDefine (MacExp* E) */ unsigned Count = E->M->ParamCount; - /* Skip the current token */ - NextTok (); - /* Read the actual parameters */ while (Count--) { TokNode* Last; @@ -965,14 +959,19 @@ static void StartExpDefine (MacExp* E) void MacExpandStart (Macro* M) /* Start expanding a macro */ { + FilePos Pos; MacExp* E; /* Check the argument */ 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 */ if (M->Incomplete) { - Error ("Cannot expand an incomplete macro"); + PError (&Pos, "Cannot expand an incomplete macro"); return; } @@ -980,7 +979,7 @@ void MacExpandStart (Macro* M) ** to force an endless loop and assembler crash. */ if (MacExpansions >= MAX_MACEXPANSIONS) { - Error ("Too many nested macro expansions"); + PError (&Pos, "Too many nested macro expansions"); return; }