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
17 changes: 15 additions & 2 deletions simplecpp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3341,8 +3341,21 @@ void simplecpp::preprocess(simplecpp::TokenList &output, const simplecpp::TokenL
continue;
const std::string lhs(macrostr.substr(0,eq));
const std::string rhs(eq==std::string::npos ? std::string("1") : macrostr.substr(eq+1));
const Macro macro(lhs, rhs, dummy);
macros.insert(std::pair<TokenString,Macro>(macro.name(), macro));
try {
const Macro macro(lhs, rhs, dummy);
macros.insert(std::pair<TokenString,Macro>(macro.name(), macro));
Copy link
Owner

Choose a reason for hiding this comment

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

Can we use macros.emplace(macro.name(), macro); syntax nowadays or is a newer C++ needed for that?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

See #596.

} catch (const std::runtime_error& e) {
if (outputList) {
simplecpp::Output err = {
Copy link
Owner

Choose a reason for hiding this comment

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

I prefer that the = is removed here. We just want that the constructor is called. No initializer list + assignment stuff..

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Will clean up as a whole in a follow-up.

Output::DUI_ERROR,
{},
e.what()
};
outputList->push_back(std::move(err));
Copy link
Owner

Choose a reason for hiding this comment

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

we can't emplace_back ?

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 only adjusted those when Clang-Tidy told us to.

Will adjust as a whole in a follow-up.

}
output.clear();
return;
}
}

const bool strictAnsiUndefined = dui.undefined.find("__STRICT_ANSI__") != dui.undefined.cend();
Expand Down
14 changes: 14 additions & 0 deletions test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3442,6 +3442,18 @@ static void tokenlist_api()
#endif // __cpp_lib_span
}

static void bad_macro_syntax() // #616
{
simplecpp::DUI dui;
dui.defines.emplace_back("\"");

simplecpp::OutputList outputList;
ASSERT_EQUALS("", preprocess("", dui, &outputList));
ASSERT_EQUALS(1, outputList.size());
ASSERT_EQUALS(simplecpp::Output::Type::DUI_ERROR, outputList.cbegin()->type);
ASSERT_EQUALS("bad macro syntax. macroname=\" value=1", outputList.cbegin()->msg);
}

static void isAbsolutePath() {
#ifdef _WIN32
ASSERT_EQUALS(true, simplecpp::isAbsolutePath("C:\\foo\\bar"));
Expand Down Expand Up @@ -3769,6 +3781,8 @@ int main(int argc, char **argv)

TEST_CASE(isAbsolutePath);

TEST_CASE(bad_macro_syntax);

TEST_CASE(fuzz_crash);

TEST_CASE(leak);
Expand Down