Merge pull request #899 from IOBYTE/master

Fixed #8044: Crash below SymbolDatabase::setValueType
This commit is contained in:
Daniel Marjamäki 2017-05-01 22:03:54 +02:00 committed by GitHub
commit 0037e9b2ec
2 changed files with 33 additions and 4 deletions

View File

@ -4743,11 +4743,14 @@ void SymbolDatabase::setValueType(Token *tok, const ValueType &valuetype)
if (isconst)
varvt.constness |= 1;
setValueType(parent->previous(), varvt);
const_cast<Variable *>(parent->previous()->variable())->setFlags(varvt);
Variable *var = const_cast<Variable *>(parent->previous()->variable());
if (var) {
var->setFlags(varvt);
if (vt2->typeScope && vt2->typeScope->definedType) {
const_cast<Variable *>(parent->previous()->variable())->type(vt2->typeScope->definedType);
var->type(vt2->typeScope->definedType);
autoToken->type(vt2->typeScope->definedType);
}
}
} else if (vt2->container) {
// TODO: Determine exact type of RHS
const Token *typeStart = parent->astOperand2();

View File

@ -330,6 +330,7 @@ private:
TEST_CASE(auto6); // #7963 (segmentation fault)
TEST_CASE(auto7);
TEST_CASE(auto8);
TEST_CASE(auto9); // #8044 (segmentation fault)
}
void array() {
@ -5159,6 +5160,31 @@ private:
}
}
void auto9() { // #8044 (segmentation fault)
GET_SYMBOL_DB("class DHTTokenTracker {\n"
" static const size_t SECRET_SIZE = 4;\n"
" unsigned char secret_[2][SECRET_SIZE];\n"
" void validateToken();\n"
"};\n"
"template <typename T> struct DerefEqual<T> derefEqual(const T& t) {\n"
" return DerefEqual<T>(t);\n"
"}\n"
"template <typename T>\n"
"struct RefLess {\n"
" bool operator()(const std::shared_ptr<T>& lhs,\n"
" const std::shared_ptr<T>& rhs)\n"
" {\n"
" return lhs.get() < rhs.get();\n"
" }\n"
"};\n"
"void DHTTokenTracker::validateToken()\n"
"{\n"
" for (auto& elem : secret_) {\n"
" }\n"
"}");
ASSERT_EQUALS(true, db != nullptr); // not null
}
};
REGISTER_TEST(TestSymbolDatabase)