BR 1783117: Document that %+ needs a space after it, and fix crash
authorH. Peter Anvin <hpa@zytor.com>
Sun, 23 Sep 2007 00:45:45 +0000 (17:45 -0700)
committerH. Peter Anvin <hpa@zytor.com>
Sun, 23 Sep 2007 00:45:45 +0000 (17:45 -0700)
Document that %+ needs a space after it due to collision with %+1
syntax for multiline macro arguments; make it issue an error message
rather than crashing.

doc/nasmdoc.src
preproc.c

index c79cd39..79db7e5 100644 (file)
@@ -1891,6 +1891,9 @@ Individual tokens in single line macros can be concatenated, to produce
 longer tokens for later processing. This can be useful if there are
 several similar macros that perform similar functions.
 
+Please note that a space is required after \c{%+}, in order to
+disambiguate it from the syntax \c{%+1} used in multiline macros.
+
 As an example, consider the following:
 
 \c %define BDASTART 400h                ; Start of BIOS data area
index c34fa4f..b3e32d1 100644 (file)
--- a/preproc.c
+++ b/preproc.c
@@ -74,7 +74,7 @@ struct SMacro {
     SMacro *next;
     char *name;
     int casesense;
-    int nparam;
+    unsigned int nparam;
     int in_progress;
     Token *expansion;
 };
@@ -113,7 +113,8 @@ struct MMacro {
     MMacro *rep_nest;           /* used for nesting %rep */
     Token **params;             /* actual parameters */
     Token *iline;               /* invocation line */
-    int nparam, rotate, *paramlen;
+    unsigned int nparam, rotate;
+    int *paramlen;
     uint32_t unique;
     int lineno;                 /* Current line number on expansion */
 };
@@ -2148,12 +2149,13 @@ static int do_directive(Token * tline)
             error(ERR_NONFATAL,
                   "`%%rotate' invoked within macro without parameters");
         } else {
-            mmac->rotate = mmac->rotate + reloc_value(evalresult);
+           int rotate = mmac->rotate + reloc_value(evalresult);
 
-            if (mmac->rotate < 0)
-                mmac->rotate =
-                    mmac->nparam - (-mmac->rotate) % mmac->nparam;
-            mmac->rotate %= mmac->nparam;
+           rotate %= (int)mmac->nparam;
+           if (rotate < 0)
+               rotate += mmac->nparam;
+           
+           mmac->rotate = rotate;
         }
         return DIRECTIVE_FOUND;
 
@@ -2742,6 +2744,9 @@ static int find_cc(Token * t)
     Token *tt;
     int i, j, k, m;
 
+    if (!t)
+           return -1;          /* Probably a %+ without a space */
+
     skip_white_(t);
     if (t->type != TOK_ID)
         return -1;
@@ -2788,7 +2793,8 @@ static Token *expand_mmac_params(Token * tline)
             char *text = NULL;
             int type = 0, cc;   /* type = 0 to placate optimisers */
             char tmpbuf[30];
-            int n, i;
+            unsigned int n;
+           int i;
             MMacro *mac;
 
             t = tline;
@@ -2945,7 +2951,8 @@ static Token *expand_smacro(Token * tline)
     SMacro *head = NULL, *m;
     Token **params;
     int *paramsize;
-    int nparam, sparam, brackets, rescan;
+    unsigned int nparam, sparam;
+    int brackets, rescan;
     Token *org_tline = tline;
     Context *ctx;
     char *mname;