Skip to content

Commit

Permalink
Fixed issue #192 - "Define macro inside a function block will crash p…
Browse files Browse the repository at this point in the history
…icoc".

Macros inside functions now work correctly.
  • Loading branch information
zik.saleeba committed Mar 1, 2014
1 parent 14a1bb3 commit 5b4f87a
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 0 deletions.
2 changes: 2 additions & 0 deletions expression.c
Original file line number Diff line number Diff line change
Expand Up @@ -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");

Expand Down Expand Up @@ -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;
Expand Down
12 changes: 12 additions & 0 deletions tests/67_macro_crash.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#include <stdio.h>

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();
}
1 change: 1 addition & 0 deletions tests/67_macro_crash.expect
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
4: 1
1 change: 1 addition & 0 deletions tests/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 5b4f87a

Please sign in to comment.