Fix: #2942 (segmentation fault of cppcheck ( #elif (){ ))
http://sourceforge.net/apps/trac/cppcheck/ticket/2942
This commit is contained in:
parent
6dc7554310
commit
ee7b8d53c6
|
@ -1451,7 +1451,12 @@ void Preprocessor::simplifyCondition(const std::map<std::string, std::string> &c
|
|||
Settings settings;
|
||||
Tokenizer tokenizer(&settings, NULL);
|
||||
std::istringstream istr(("(" + condition + ")").c_str());
|
||||
tokenizer.tokenize(istr, "", "", true);
|
||||
if (!tokenizer.tokenize(istr, "", "", true))
|
||||
{
|
||||
// If tokenize returns false, then there is syntax error in the
|
||||
// code which we can't handle. So stop here.
|
||||
return;
|
||||
}
|
||||
|
||||
if (Token::Match(tokenizer.tokens(), "( %var% )"))
|
||||
{
|
||||
|
|
|
@ -230,6 +230,7 @@ private:
|
|||
|
||||
// Test Preprocessor::simplifyCondition
|
||||
TEST_CASE(simplifyCondition);
|
||||
TEST_CASE(invalidElIf); // #2942 segfault
|
||||
}
|
||||
|
||||
|
||||
|
@ -2925,6 +2926,15 @@ private:
|
|||
Preprocessor::simplifyCondition(cfg, condition, true);
|
||||
ASSERT_EQUALS("1", condition);
|
||||
}
|
||||
|
||||
void invalidElIf()
|
||||
{
|
||||
// #2942 - segfault
|
||||
const char code[] = "#elif (){\n";
|
||||
const Settings settings;
|
||||
const std::string actual = Preprocessor::getcode(code, "TEST", "test.c", &settings, this);
|
||||
ASSERT_EQUALS("\n", actual);
|
||||
}
|
||||
};
|
||||
|
||||
REGISTER_TEST(TestPreprocessor)
|
||||
|
|
Loading…
Reference in New Issue