diff --git a/expression.c b/expression.c index 96105dc..60de722 100644 --- a/expression.c +++ b/expression.c @@ -1264,6 +1264,7 @@ int ExpressionParse(struct ParseState *Parser, struct Value **Result) struct Value *MacroResult; ParserCopy(&MacroParser, &VariableValue->Val->MacroDef.Body); + MacroParser.Mode = Parser->Mode; if (VariableValue->Val->MacroDef.NumParams != 0) ProgramFail(&MacroParser, "macro arguments missing"); @@ -1422,6 +1423,7 @@ void ExpressionParseMacroCall(struct ParseState *Parser, struct ExpressionStack ProgramFail(Parser, "'%s' is undefined", MacroName); ParserCopy(&MacroParser, &MDef->Body); + MacroParser.Mode = Parser->Mode; VariableStackFrameAdd(Parser, MacroName, 0); Parser->pc->TopStackFrame->NumParams = ArgCount; Parser->pc->TopStackFrame->ReturnValue = ReturnValue; diff --git a/tests/67_macro_crash.c b/tests/67_macro_crash.c new file mode 100644 index 0000000..0195f79 --- /dev/null +++ b/tests/67_macro_crash.c @@ -0,0 +1,12 @@ +#include + +void printArray(void) { +#define SIZE 10 + int array[SIZE] = {5, 4, 3, 9, 1, 8, 6, 7, 5, 2}; + printf("4: %d\n", array[4]); +} + +void main() +{ + printArray(); +} diff --git a/tests/67_macro_crash.expect b/tests/67_macro_crash.expect new file mode 100644 index 0000000..aec711b --- /dev/null +++ b/tests/67_macro_crash.expect @@ -0,0 +1 @@ +4: 1 diff --git a/tests/Makefile b/tests/Makefile index 4448bf9..f3a5894 100644 --- a/tests/Makefile +++ b/tests/Makefile @@ -60,6 +60,7 @@ TESTS= 00_assignment.test \ 63_typedef.test \ 64_double_prefix_op.test \ 66_printf_undefined.test \ + 67_macro_crash.test \ include csmith/Makefile