#6900 segmentation fault (invalid code) in CheckStl::runSimplifiedChecks.

This commit is contained in:
Alexander Mai 2015-07-31 20:24:06 +02:00
parent 7422366ebc
commit 4400f2ac85
3 changed files with 26 additions and 4 deletions

View File

@ -3777,10 +3777,7 @@ bool Tokenizer::simplifyTokenList2()
// Create symbol database and then remove const keywords
createSymbolDatabase();
for (Token *tok = list.front(); tok; tok = tok->next()) {
if (Token::simpleMatch(tok, "* const"))
tok->deleteNext();
}
simplifyPointerConst();
list.createAst();
@ -3794,6 +3791,14 @@ bool Tokenizer::simplifyTokenList2()
return true;
}
//---------------------------------------------------------------------------
void Tokenizer::simplifyPointerConst()
{
for (Token *tok = list.front(); tok; tok = tok->next()) {
if (Token::Match(tok, "* const %name%|*"))
tok->deleteNext();
}
}
//---------------------------------------------------------------------------
void Tokenizer::printDebugOutput(unsigned int simplification) const
{

View File

@ -277,6 +277,12 @@ public:
*/
void simplifyCompoundAssignment();
/**
* Simplify "* const" to "*"
*/
void simplifyPointerConst();
/**
* Simplify the location of "static" and "const" qualifiers in
* a variable declaration or definition.

View File

@ -148,6 +148,8 @@ private:
TEST_CASE(garbageCode106);
TEST_CASE(garbageCode107);
TEST_CASE(garbageCode108);
TEST_CASE(garbageCode109);
TEST_CASE(garbageCode110);
TEST_CASE(garbageValueFlow);
TEST_CASE(garbageSymbolDatabase);
@ -834,6 +836,15 @@ private:
checkCode("A( ) { } bool f( ) { ( ) F; ( ) { ( == ) if ( !=< || ( !A( ) && r[2] ) ) ( !A( ) ) ( ) } }");
}
void garbageCode109() { // #6900 "segmentation fault (invalid code) in CheckStl::runSimplifiedChecks"
checkCode("( *const<> (( ) ) { } ( *const ( ) ( ) ) { } ( * const<> ( size_t )) ) { } ( * const ( ) ( ) ) { }");
}
void garbageCode110() { // #6902 "segmentation fault (invalid code) in CheckStl::string_c_str"
checkCode("( *const<> ( size_t ) ; foo ) { } * ( *const ( size_t ) ( ) ;> foo )< { }");
}
void garbageValueFlow() {
// #6089