[Nasm-commits] [nasm:nasm-2.15.xx] BR 3392668: preproc: test for macro in TOK_LOCAL_SYMBOL

nasm-bot for H. Peter Anvin (Intel) hpa at zytor.com
Thu Jun 4 19:56:56 PDT 2020


Commit-ID:  a762cd4e5402a3605c4962567c47c36c2bd3accf
Gitweb:     http://repo.or.cz/w/nasm.git?a=commitdiff;h=a762cd4e5402a3605c4962567c47c36c2bd3accf
Author:     H. Peter Anvin (Intel) <hpa at zytor.com>
AuthorDate: Mon, 1 Jun 2020 11:49:08 -0700
Committer:  H. Peter Anvin (Intel) <hpa at zytor.com>
CommitDate: Mon, 1 Jun 2020 11:49:08 -0700

BR 3392668: preproc: test for macro in TOK_LOCAL_SYMBOL

TOK_LOCAL_SYMBOL is only applicable inside a macro; otherwise error
out just like we do for TOK_MMACRO_PARAM.

This *partially* addresses BR 3392668.

Reported-by: <puppet at zju.edu.cn>
Signed-off-by: H. Peter Anvin (Intel) <hpa at zytor.com>


---
 asm/preproc.c        |  18 +++++++++++++++---
 test/br3392668-3.asm | Bin 0 -> 130926 bytes
 2 files changed, 15 insertions(+), 3 deletions(-)

diff --git a/asm/preproc.c b/asm/preproc.c
index 9ab05765..c7b2e7d4 100644
--- a/asm/preproc.c
+++ b/asm/preproc.c
@@ -4756,6 +4756,7 @@ static Token *expand_mmac_params(Token * tline)
 
     while (tline) {
         bool change;
+        bool err_not_mac = false;
         Token *t = tline;
         const char *text = tok_text(t);
         int type = t->type;
@@ -4765,9 +4766,15 @@ static Token *expand_mmac_params(Token * tline)
 
         switch (type) {
         case TOK_LOCAL_SYMBOL:
+            change = true;
+
+            if (!mac) {
+                err_not_mac = true;
+                break;
+            }
+
             type = TOK_ID;
             text = nasm_asprintf("..@%"PRIu64".%s", mac->unique, text+2);
-            change = true;
             break;
         case TOK_MMACRO_PARAM:
         {
@@ -4776,8 +4783,7 @@ static Token *expand_mmac_params(Token * tline)
             change = true;
 
             if (!mac) {
-                nasm_nonfatal("`%s': not in a macro call", text);
-                text = NULL;
+                err_not_mac = true;
                 break;
             }
 
@@ -4910,6 +4916,12 @@ static Token *expand_mmac_params(Token * tline)
             break;
         }
 
+        if (err_not_mac) {
+            nasm_nonfatal("`%s': not in a macro call", text);
+            text = NULL;
+            change = true;
+        }
+
         if (change) {
             if (!text) {
                 delete_Token(t);
diff --git a/test/br3392668-3.asm b/test/br3392668-3.asm
new file mode 100644
index 00000000..c662cb7d
Binary files /dev/null and b/test/br3392668-3.asm differ


More information about the Nasm-commits mailing list