From bd38c8f231d938ffdf0916809bf2a6b65e62ea61 Mon Sep 17 00:00:00 2001 From: Cyrill Gorcunov Date: Sat, 21 Nov 2009 11:11:23 +0300 Subject: [PATCH] preproc.c: expand_smacro -- break endless loop for interminable macro recursion Frank reported: | | From the "expert questions" forum comes this: | | --------------------- | By: jasper_neumann | | How can I delegate %undef? | | In the example below the assembler (called with "nasm.exe -t -f rdf q.asm") | bemoans my code, displays | | "q.asm:19: error: interminable macro recursion" | | and hangs. | | q.asm | ----- | bits 32 | CPU P4 | | %macro my_def 2 | %xdefine %1 esp+%2 | %endmacro | | %macro my_undef 1 | %undef %1 | %endmacro | | global check_it | check_it: | my_def x,4 | mov eax,[x] | my_undef x | | my_def x,8 | add eax,[x] | my_undef x | ret | So in case of interminable macro recursion we should break the expansion procedure that way to not return back and start expand macro again. This address a part of the original problem. Nasm64developer pointed out: | | Btw, after you manage to fix this recursion problem, the code | in question still faces the same fundamental issue -- the arg | to the my_undef invocations (i.e. x) gets expanded first; thus | the %undef inside the macro sees esp+4 and esp+8 instead | of x, and fails. What you'd need is a means to prevent the ex- | pansion -- look for e.g. %# in 4.1.4 of the manual.txt which is | attached to SF #1842438; it implements exactly that -- I once | filed SF #829879 for this feature. | In turn Keith Kanios said: | | Anon is also correct in that we would need a special directive to instruct | the delay of macro expansion, although I don't see this as critical or even | high priority at the moment. The intermediate solution for this is, don't | use indirection if it is not needed... an inline %undef should be | sufficient. | Reported-by: Frank Kotler Signed-off-by: Cyrill Gorcunov Reviewed-by: Keith Kanios --- preproc.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/preproc.c b/preproc.c index 6af2ac64..45c02647 100644 --- a/preproc.c +++ b/preproc.c @@ -3783,7 +3783,7 @@ again: while (tline) { /* main token loop */ if (!--deadman) { error(ERR_NONFATAL, "interminable macro recursion"); - break; + goto err; } if ((mname = tline->text)) { @@ -4058,6 +4058,7 @@ again: goto again; } +err: if (org_tline) { if (thead) { *org_tline = *thead; -- 2.11.4.GIT