Skip to content
Merged
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
4 changes: 4 additions & 0 deletions lib/preprocessor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -469,6 +469,8 @@ static std::string readcondition(const simplecpp::Token *iftok, const std::set<s
continue;
}
if (cond->str() == "==" || cond->str() == "<=" || cond->str() == ">=") {
if (!cond->next)
break;
if (cond->next->number) {
const simplecpp::Token *dtok = cond->previous;
if (sameline(iftok,dtok) && dtok->name && defined.find(dtok->str()) == defined.end() && undefined.find(dtok->str()) == undefined.end())
Expand All @@ -477,6 +479,8 @@ static std::string readcondition(const simplecpp::Token *iftok, const std::set<s
continue;
}
if (cond->op == '<' || cond->op == '>') {
if (!cond->next)
break;
if (cond->next->number) {
const simplecpp::Token *dtok = cond->previous;
if (sameline(iftok,dtok) && dtok->name && defined.find(dtok->str()) == defined.end() && undefined.find(dtok->str()) == undefined.end()) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
#if<
29 changes: 29 additions & 0 deletions test/testpreprocessor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -343,6 +343,8 @@ class TestPreprocessor : public TestFixture {
TEST_CASE(getConfigsAndCodeIssue14317);
TEST_CASE(getConfigsMostGeneralConfigIssue14317);

TEST_CASE(getConfigsInvalid); // #14732

TEST_CASE(if_sizeof);

TEST_CASE(invalid_ifs); // #5909
Expand Down Expand Up @@ -2715,6 +2717,33 @@ class TestPreprocessor : public TestFixture {
ASSERT_EQUALS("\nX\nY=Y\nZ\n", getConfigsStr(filedata));
}

void getConfigsInvalid() { // #14732
{
const char filedata[] = "#if<";
ASSERT_EQUALS("\n", getConfigsStr(filedata));
}
{
const char filedata[] = "#if>";
ASSERT_EQUALS("\n", getConfigsStr(filedata));
}
{
const char filedata[] = "#if==";
ASSERT_EQUALS("\n", getConfigsStr(filedata));
}
{
const char filedata[] = "#if<=";
ASSERT_EQUALS("\n", getConfigsStr(filedata));
}
{
const char filedata[] = "#if>=";
ASSERT_EQUALS("\n", getConfigsStr(filedata));
}
{
const char filedata[] = "#if!";
ASSERT_EQUALS("\n", getConfigsStr(filedata));
}
}

void if_sizeof() { // #4071
const char code[] = "#if sizeof(unsigned short) == 2\n"
"Fred & Wilma\n"
Expand Down
Loading