#6771 segmentation fault (invalid code) in SymbolDatabase::SymbolDatabase

This commit is contained in:
Alexander Mai 2015-06-14 22:18:28 +02:00
parent d571d5db6f
commit a5a835b1e0
2 changed files with 11 additions and 2 deletions

View File

@ -206,7 +206,7 @@ SymbolDatabase::SymbolDatabase(const Tokenizer *tokenizer, const Settings *setti
}
// using namespace
else if (Token::Match(tok, "using namespace ::| %type% ;|::")) {
else if (_tokenizer->isCPP() && Token::Match(tok, "using namespace ::| %type% ;|::")) {
Scope::UsingInfo using_info;
using_info.start = tok; // save location
@ -622,7 +622,7 @@ SymbolDatabase::SymbolDatabase(const Tokenizer *tokenizer, const Settings *setti
}
// friend class declaration?
else if (Token::Match(tok, "friend class| ::| %any% ;|::")) {
else if (_tokenizer->isCPP() && Token::Match(tok, "friend class| ::| %any% ;|::")) {
Type::FriendInfo friendInfo;
// save the name start
@ -644,6 +644,10 @@ SymbolDatabase::SymbolDatabase(const Tokenizer *tokenizer, const Settings *setti
// fill this in after parsing is complete
friendInfo.type = 0;
if (!scope->definedType) {
_tokenizer->syntaxError(tok);
return;
}
scope->definedType->friendList.push_back(friendInfo);
}
} else if (scope->type == Scope::eNamespace || scope->type == Scope::eGlobal) {

View File

@ -121,6 +121,7 @@ private:
TEST_CASE(garbageCode80);
TEST_CASE(garbageCode81);
TEST_CASE(garbageCode82);
TEST_CASE(garbageCode83);
TEST_CASE(garbageValueFlow);
TEST_CASE(garbageSymbolDatabase);
@ -671,6 +672,10 @@ private:
ASSERT_THROW(checkCode("p(\"Hello \" 14) _yn(const size_t) typedef bool pfunk (*pfunk)(const size_t)"), InternalError);
}
void garbageCode83() { // #6771
ASSERT_THROW(checkCode("namespace A { class } class A { friend C ; } { } ;"), InternalError);
}
void garbageValueFlow() {
// #6089
const char* code = "{} int foo(struct, x1, struct x2, x3, int, x5, x6, x7)\n"