mirror of
https://github.com/netwide-assembler/nasm.git
synced 2024-12-21 09:19:31 +08:00
preproc: fix list iteration in the case of expand_indirect()
Linked lists where an element may be deleted or substituted during processing can be subtle to deal with. Fix the iteration conditions in this particular case. Signed-off-by: H. Peter Anvin <hpa@zytor.com>
This commit is contained in:
parent
992fe7591d
commit
c0ab1cd15a
21
preproc.c
21
preproc.c
@ -3901,7 +3901,8 @@ static Token *expand_id(Token * tline)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Expand indirect tokens, %[...].
|
* Expand indirect tokens, %[...]. Just like expand_smacro(),
|
||||||
|
* the input is considered destroyed.
|
||||||
*/
|
*/
|
||||||
static Token *expand_indirect(Token * tline, int level)
|
static Token *expand_indirect(Token * tline, int level)
|
||||||
{
|
{
|
||||||
@ -3914,9 +3915,12 @@ static Token *expand_indirect(Token * tline, int level)
|
|||||||
error(ERR_NONFATAL, "interminable indirect expansion");
|
error(ERR_NONFATAL, "interminable indirect expansion");
|
||||||
} else {
|
} else {
|
||||||
thead = NULL;
|
thead = NULL;
|
||||||
for (tp = &tline; (t = *tp); thead = t, tp = &t->next) {
|
tp = &tline;
|
||||||
if (t->type != TOK_INDIRECT)
|
while ((t = *tp)) {
|
||||||
continue;
|
if (t->type != TOK_INDIRECT) {
|
||||||
|
thead = t;
|
||||||
|
tp = &t->next;
|
||||||
|
} else {
|
||||||
it = tokenize(t->text);
|
it = tokenize(t->text);
|
||||||
it = expand_indirect(it, level+1);
|
it = expand_indirect(it, level+1);
|
||||||
it = expand_smacro(it);
|
it = expand_smacro(it);
|
||||||
@ -3926,20 +3930,18 @@ static Token *expand_indirect(Token * tline, int level)
|
|||||||
case TOK_WHITESPACE:
|
case TOK_WHITESPACE:
|
||||||
skip = (it->type == TOK_WHITESPACE);
|
skip = (it->type == TOK_WHITESPACE);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case TOK_ID:
|
case TOK_ID:
|
||||||
case TOK_NUMBER:
|
case TOK_NUMBER:
|
||||||
if (it->type == thead->type || it->type == TOK_NUMBER) {
|
if (it->type == thead->type || it->type == TOK_NUMBER) {
|
||||||
char *tmp = nasm_strcat(thead->text, it->text);
|
char *tmp = nasm_strcat(thead->text, it->text);
|
||||||
|
nasm_free(thead->text);
|
||||||
thead->text = tmp;
|
thead->text = tmp;
|
||||||
skip = true;
|
skip = true;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (skip) {
|
if (skip) {
|
||||||
it = delete_Token(it);
|
it = delete_Token(it);
|
||||||
} else {
|
} else {
|
||||||
@ -3948,8 +3950,9 @@ static Token *expand_indirect(Token * tline, int level)
|
|||||||
it = it->next;
|
it = it->next;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
*tp = t->next;
|
*tp = thead = t->next;
|
||||||
delete_Token(t);
|
t = delete_Token(t);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return tline;
|
return tline;
|
||||||
|
Loading…
Reference in New Issue
Block a user