From c751e86145aec99b2212321903146723e75af22a Mon Sep 17 00:00:00 2001 From: "H. Peter Anvin" Date: Mon, 9 Jun 2008 10:18:45 -0700 Subject: [PATCH] Fix %? in multi-line macros with a label The handling of %? in multi-line macros was broken when the macro name was preceeded by a label; it would expand to the label instead of the macro name. This was particularly serious since this was used in the macro implementation of INCBIN. --- preproc.c | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/preproc.c b/preproc.c index f324d1c5..b34710d1 100644 --- a/preproc.c +++ b/preproc.c @@ -393,7 +393,8 @@ static void make_tok_num(Token * tok, int64_t val); static void error(int severity, const char *fmt, ...); static void *new_Block(size_t size); static void delete_Blocks(void); -static Token *new_Token(Token * next, enum pp_token_type type, char *text, int txtlen); +static Token *new_Token(Token * next, enum pp_token_type type, + const char *text, int txtlen); static Token *delete_Token(Token * t); /* @@ -986,7 +987,7 @@ static void delete_Blocks(void) * also the mac and next elements to NULL. */ static Token *new_Token(Token * next, enum pp_token_type type, - char *text, int txtlen) + const char *text, int txtlen) { Token *t; int i; @@ -3752,6 +3753,7 @@ static int expand_mmacro(Token * tline) MMacro *m; Line *l, *ll; int i, nparam, *paramlen; + const char *mname; t = tline; skip_white_(t); @@ -3760,7 +3762,9 @@ static int expand_mmacro(Token * tline) return 0; mtok = t; m = is_mmacro(t, ¶ms); - if (!m) { + if (m) { + mname = t->text; + } else { Token *last; /* * We have an id which isn't a macro call. We'll assume @@ -3781,6 +3785,7 @@ static int expand_mmacro(Token * tline) if (!tok_type_(t, TOK_ID) || (m = is_mmacro(t, ¶ms)) == NULL) return 0; last->next = NULL; + mname = t->text; tline = t; } @@ -3859,7 +3864,7 @@ static int expand_mmacro(Token * tline) Token *x = t; switch (t->type) { case TOK_PREPROC_Q: - tt = *tail = new_Token(NULL, TOK_ID, mtok->text, 0); + tt = *tail = new_Token(NULL, TOK_ID, mname, 0); break; case TOK_PREPROC_QQ: tt = *tail = new_Token(NULL, TOK_ID, m->name, 0); -- 2.11.4.GIT