From 49b33f398ecc1068f7e0b5591b36d663238b1e8b Mon Sep 17 00:00:00 2001 From: "H. Peter Anvin" Date: Sun, 19 Oct 2008 22:22:05 -0700 Subject: [PATCH] preproc: fix terminal token pasting in indirect sequences Fix the case where the terminal token pastes with the first token of the unmodified sequence. This is a really ugly version; we need to merge the two instances plus the one in expand_mmac_params(). Signed-off-by: H. Peter Anvin --- preproc.c | 30 +++++++++++++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) diff --git a/preproc.c b/preproc.c index 253244ca..3010d3ef 100644 --- a/preproc.c +++ b/preproc.c @@ -3915,6 +3915,8 @@ static Token *expand_id(Token * tline) /* * Expand indirect tokens, %[...]. Just like expand_smacro(), * the input is considered destroyed. + * + * XXX: fix duplicated code in this function and in expand_mmac_params() */ static Token *expand_indirect(Token * tline, int level) { @@ -3962,7 +3964,33 @@ static Token *expand_indirect(Token * tline, int level) it = it->next; } } - *tp = thead = t->next; + + skip = false; + it = t->next; + if (it) { + switch (thead ? thead->type : TOK_NONE) { + case TOK_WHITESPACE: + skip = (it->type == TOK_WHITESPACE); + break; + case TOK_ID: + case TOK_NUMBER: + if (it->type == thead->type || it->type == TOK_NUMBER) { + char *tmp = nasm_strcat(thead->text, it->text); + nasm_free(thead->text); + thead->text = tmp; + skip = true; + } + break; + default: + break; + } + } + if (skip) { + *tp = thead = it->next; + t = delete_Token(t); + } else { + *tp = thead = it; + } t = delete_Token(t); } } -- 2.11.4.GIT