From 15ddd8fea998920e8334e0ea4e9f924bf395b58b Mon Sep 17 00:00:00 2001 From: Bill Currie Date: Fri, 13 Dec 2024 20:20:20 +0900 Subject: [PATCH] [qfcc] Do a better check for recursive macro invocations Simply checking if the macro's next pointer was set wasn't enough for when the macro was at the end of the chain (or the only macro in the chain). --- tools/qfcc/source/qc-lex.l | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/tools/qfcc/source/qc-lex.l b/tools/qfcc/source/qc-lex.l index cf6369953..626dfa18c 100644 --- a/tools/qfcc/source/qc-lex.l +++ b/tools/qfcc/source/qc-lex.l @@ -1383,6 +1383,18 @@ check_macro (rua_macro_t *macro) return true; } +static bool __attribute__((pure)) +recursive_invocation (rua_macro_t *macro, rua_extra_t *extra) +{ + while (macro && extra->macro) { + if (macro == extra->macro) { + return true; + } + macro = macro->next; + } + return false; +} + static int next_token (rua_tok_t *tok, yyscan_t scanner, rua_ctx_t *ctx) { @@ -1561,7 +1573,7 @@ rescan: if ((extra->expand || !(extra->preprocessor || extra->suppressed)) && token == -rua_id && (sym = symtab_lookup (extra->macro_tab, e.text)) - && !sym->macro->next) { + && !recursive_invocation (sym->macro, extra)) { auto macro = sym->macro; if (macro->update) { macro->update (macro, ctx);