Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions simplecpp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1693,7 +1693,9 @@ namespace simplecpp {
nameTokDef = nametoken;
variadic = false;
variadicOpt = false;
delete optExpandValue;
optExpandValue = nullptr;
delete optNoExpandValue;
optNoExpandValue = nullptr;
if (!nameTokDef) {
valueToken = endToken = nullptr;
Expand Down Expand Up @@ -2367,8 +2369,8 @@ namespace simplecpp {
bool variadicOpt;

/** Expansion value for varadic macros with __VA_OPT__ expanded and discarded respectively */
const TokenList *optExpandValue;
const TokenList *optNoExpandValue;
const TokenList *optExpandValue{};
const TokenList *optNoExpandValue{};

/** was the value of this macro actually defined in the code? */
bool valueDefinedInCode_;
Expand Down
13 changes: 13 additions & 0 deletions test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3217,6 +3217,7 @@ static void safe_api()
#endif
}

// crashes detected by fuzzer
static void fuzz_crash()
{
{
Expand All @@ -3231,6 +3232,16 @@ static void fuzz_crash()
}
}

// memory leaks detected by LSAN/valgrind
static void leak()
{
{ // #498
const char code[] = "#define e(...)__VA_OPT__()\n"
"#define e\n";
(void)preprocess(code, simplecpp::DUI());
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I assume this has to be executed by some valgrind or sanitizer to detect the issue? i.e. if I just compile and run then this test does not ensure there is no leak?
It feels a bit misplaced somehow but maybe writing a separate test for it is overkill.. but well a comment would be nice?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, obviously you need to run a leak checker.

I assumed the test name leak was enough. I can add a comment.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added some comments.

}
}

int main(int argc, char **argv)
{
TEST_CASE(backslash);
Expand Down Expand Up @@ -3487,5 +3498,7 @@ int main(int argc, char **argv)

TEST_CASE(fuzz_crash);

TEST_CASE(leak);

return numberOfFailedAssertions > 0 ? EXIT_FAILURE : EXIT_SUCCESS;
}