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.
Unified · Split
| @@ -1189,6 +1189,7 @@ ST_FUNC void end_macro(void) · 1188 unmodified lines | ||
| 1189 | 1189 | macro_stack = str->prev; |
| 1190 | 1190 | macro_ptr = str->prev_ptr; |
| 1191 | 1191 | file->line_num = str->save_line_num; |
| 1192 | + str->len = 0; /* matters if str not alloced, may be tokstr_buf */ | |
| 1192 | 1193 | if (str->alloc != 0) { |
| 1193 | 1194 | if (str->alloc == 2) |
| 1194 | 1195 | str->str = NULL; /* don't free */ |
| @@ -0,0 +1,12 @@ | ||
| 1 | +#define TRACE(a,b,c) X a X b X c X | |
| 2 | +#define rettrue(x) 1 | |
| 3 | +A rettrue(bla) B | |
| 4 | +TRACE( | |
| 5 | + ARG_1, | |
| 6 | +#if rettrue(bla) | |
| 7 | + ARG_2, | |
| 8 | +#else | |
| 9 | + ARG_2_wrong, | |
| 10 | +#endif | |
| 11 | + ARG_3 | |
| 12 | +); | |
| @@ -0,0 +1,2 @@ | ||
| 1 | +A 1 B | |
| 2 | +X ARG_1 X ARG_2 X ARG_3 X; | |