Fixed #8152 (Garbage code cause crash '0|\0|0>;')

This commit is contained in:
Daniel Marjamäki 2017-08-15 23:18:46 +02:00
parent b12b232f59
commit 5c733c8f22
2 changed files with 14 additions and 3 deletions

View File

@ -8215,6 +8215,12 @@ const Token * Tokenizer::findGarbageCode() const
}
}
// Operators without operands..
for (const Token *tok = tokens(); tok; tok = tok->next()) {
if (Token::Match(tok, "%cop% %or%|%oror%|/|%"))
return tok;
}
// Code must not start with an arithmetical operand
if (Token::Match(list.front(), "%cop%"))
return list.front();

View File

@ -217,6 +217,7 @@ private:
TEST_CASE(garbageCode184); // #7699
TEST_CASE(garbageCode185); // #6011
TEST_CASE(garbageCode186); // #8151
TEST_CASE(garbageCode187);
TEST_CASE(garbageValueFlow);
TEST_CASE(garbageSymbolDatabase);
TEST_CASE(garbageAST);
@ -226,7 +227,7 @@ private:
TEST_CASE(enumTrailingComma);
}
std::string checkCode(const char code[], bool cpp = true) {
std::string checkCode(const std::string &code, bool cpp = true) {
// double the tests - run each example as C as well as C++
const char* const filename = cpp ? "test.cpp" : "test.c";
const char* const alternatefilename = cpp ? "test.c" : "test.cpp";
@ -240,7 +241,7 @@ private:
return checkCodeInternal(code, filename);
}
std::string checkCodeInternal(const char code[], const char* filename) {
std::string checkCodeInternal(const std::string &code, const char* filename) {
errout.str("");
// tokenize..
@ -833,7 +834,7 @@ private:
}
void garbageCode108() { // #6895 "segmentation fault (invalid code) in CheckCondition::isOppositeCond"
checkCode("A( ) { } bool f( ) { ( ) F; ( ) { ( == ) if ( !=< || ( !A( ) && r[2] ) ) ( !A( ) ) ( ) } }");
ASSERT_THROW(checkCode("A( ) { } bool f( ) { ( ) F; ( ) { ( == ) if ( !=< || ( !A( ) && r[2] ) ) ( !A( ) ) ( ) } }"), InternalError);
}
void garbageCode109() { // #6900 "segmentation fault (invalid code) in CheckStl::runSimplifiedChecks"
@ -1425,6 +1426,10 @@ private:
ASSERT_THROW(checkCode("A<B<><>C"), InternalError);
}
void garbageCode187() { // # 8152 - segfault in handling
const std::string inp("0|\0|0>;\n", 8);
ASSERT_THROW(checkCode(inp), InternalError);
}
void syntaxErrorFirstToken() {
ASSERT_THROW(checkCode("&operator(){[]};"), InternalError); // #7818