Skip to content

Commit 0037e9b

Browse files
authored
Merge pull request danmar#899 from IOBYTE/master
Fixed danmar#8044: Crash below SymbolDatabase::setValueType
2 parents 40a5f78 + e2bfe1c commit 0037e9b

File tree

2 files changed

+33
-4
lines changed

2 files changed

+33
-4
lines changed

lib/symboldatabase.cpp

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4743,10 +4743,13 @@ void SymbolDatabase::setValueType(Token *tok, const ValueType &valuetype)
47434743
if (isconst)
47444744
varvt.constness |= 1;
47454745
setValueType(parent->previous(), varvt);
4746-
const_cast<Variable *>(parent->previous()->variable())->setFlags(varvt);
4747-
if (vt2->typeScope && vt2->typeScope->definedType) {
4748-
const_cast<Variable *>(parent->previous()->variable())->type(vt2->typeScope->definedType);
4749-
autoToken->type(vt2->typeScope->definedType);
4746+
Variable *var = const_cast<Variable *>(parent->previous()->variable());
4747+
if (var) {
4748+
var->setFlags(varvt);
4749+
if (vt2->typeScope && vt2->typeScope->definedType) {
4750+
var->type(vt2->typeScope->definedType);
4751+
autoToken->type(vt2->typeScope->definedType);
4752+
}
47504753
}
47514754
} else if (vt2->container) {
47524755
// TODO: Determine exact type of RHS

test/testsymboldatabase.cpp

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -330,6 +330,7 @@ class TestSymbolDatabase: public TestFixture {
330330
TEST_CASE(auto6); // #7963 (segmentation fault)
331331
TEST_CASE(auto7);
332332
TEST_CASE(auto8);
333+
TEST_CASE(auto9); // #8044 (segmentation fault)
333334
}
334335

335336
void array() {
@@ -5159,6 +5160,31 @@ class TestSymbolDatabase: public TestFixture {
51595160
}
51605161
}
51615162

5163+
void auto9() { // #8044 (segmentation fault)
5164+
GET_SYMBOL_DB("class DHTTokenTracker {\n"
5165+
" static const size_t SECRET_SIZE = 4;\n"
5166+
" unsigned char secret_[2][SECRET_SIZE];\n"
5167+
" void validateToken();\n"
5168+
"};\n"
5169+
"template <typename T> struct DerefEqual<T> derefEqual(const T& t) {\n"
5170+
" return DerefEqual<T>(t);\n"
5171+
"}\n"
5172+
"template <typename T>\n"
5173+
"struct RefLess {\n"
5174+
" bool operator()(const std::shared_ptr<T>& lhs,\n"
5175+
" const std::shared_ptr<T>& rhs)\n"
5176+
" {\n"
5177+
" return lhs.get() < rhs.get();\n"
5178+
" }\n"
5179+
"};\n"
5180+
"void DHTTokenTracker::validateToken()\n"
5181+
"{\n"
5182+
" for (auto& elem : secret_) {\n"
5183+
" }\n"
5184+
"}");
5185+
ASSERT_EQUALS(true, db != nullptr); // not null
5186+
}
5187+
51625188
};
51635189

51645190
REGISTER_TEST(TestSymbolDatabase)

0 commit comments

Comments
 (0)