#7321 segmentation fault in valueFlowSwitchVariableScope::isVariableDeclaration

This commit is contained in:
Alexander Mai 2016-02-03 22:49:57 +01:00
parent cfe9c01bf8
commit d3546ea410
3 changed files with 8 additions and 3 deletions

View File

@ -39,7 +39,7 @@ namespace {
static const struct CWE CWE676(676U);
static const struct CWE CWE908(908U);
static const struct CWE CWE825(825U);
void CheckUninitVar::check()
{

View File

@ -3027,13 +3027,13 @@ bool Scope::isVariableDeclaration(const Token* const tok, const Token*& vartok,
if (localVarTok->str() == "const")
localVarTok = localVarTok->next();
if (Token::Match(localVarTok, "%name% ;|=") || (localVarTok->varId() && localVarTok->strAt(1) == ":")) {
if (Token::Match(localVarTok, "%name% ;|=") || (localVarTok && localVarTok->varId() && localVarTok->strAt(1) == ":")) {
vartok = localVarTok;
typetok = localTypeTok;
} else if (Token::Match(localVarTok, "%name% )|[") && localVarTok->str() != "operator") {
vartok = localVarTok;
typetok = localTypeTok;
} else if (localVarTok->varId() && Token::Match(localVarTok, "%name% (|{") &&
} else if (localVarTok && localVarTok->varId() && Token::Match(localVarTok, "%name% (|{") &&
Token::Match(localVarTok->next()->link(), ")|} ;")) {
vartok = localVarTok;
typetok = localTypeTok;

View File

@ -225,6 +225,7 @@ private:
TEST_CASE(garbageCode174); // #7356
TEST_CASE(garbageCode175);
TEST_CASE(garbageCode176);
TEST_CASE(garbageCode177);
TEST_CASE(garbageValueFlow);
TEST_CASE(garbageSymbolDatabase);
TEST_CASE(garbageAST);
@ -1479,6 +1480,10 @@ private:
void garbageCode176() { // #7527
checkCode("class t { { struct } enum class f : unsigned { q } b ; operator= ( T ) { switch ( b ) { case f::q: } } { assert ( b ) ; } } { ; & ( t ) ( f::t ) ; } ;");
}
void garbageCode177() { // #7321
checkCode("{(){(())}}r&const");
}
};
REGISTER_TEST(TestGarbage)