tccpp: Fix #ifdef in macro args

see testcase.  We have to "empty" the macro-stack string on
end_macro, as it may be 'tokstr_buf' which is going to be used
twice in recursive invocations of macro_subst_tok.  The uses aren't
overlapping but the first one needs to be properly finalized.
This commit is contained in:
Michael Matz 2022-07-11 15:27:51 +02:00
parent 1da92cdd93
commit 64f4b00d34
3 changed files with 15 additions and 0 deletions

View file

@ -1189,6 +1189,7 @@ ST_FUNC void end_macro(void)
macro_stack = str->prev;
macro_ptr = str->prev_ptr;
file->line_num = str->save_line_num;
str->len = 0; /* matters if str not alloced, may be tokstr_buf */
if (str->alloc != 0) {
if (str->alloc == 2)
str->str = NULL; /* don't free */

12
tests/pp/22.c Normal file
View file

@ -0,0 +1,12 @@
#define TRACE(a,b,c) X a X b X c X
#define rettrue(x) 1
A rettrue(bla) B
TRACE(
ARG_1,
#if rettrue(bla)
ARG_2,
#else
ARG_2_wrong,
#endif
ARG_3
);

2
tests/pp/22.expect Normal file
View file

@ -0,0 +1,2 @@
A 1 B
X ARG_1 X ARG_2 X ARG_3 X;