Skip to content

Commit 1e327df

Browse files
authored
Fix 9836: False negative: No invalidContainer when using vector of vectors (#3580)
* Fix 9836: False negative: No invalidContainer when using vector of vectors * Format
1 parent 143ddf2 commit 1e327df

2 files changed

Lines changed: 19 additions & 13 deletions

File tree

lib/symboldatabase.cpp

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -5698,6 +5698,7 @@ void SymbolDatabase::setValueType(Token *tok, const Variable &var)
56985698
valuetype.typeScope = var.typeScope();
56995699
if (var.valueType()) {
57005700
valuetype.container = var.valueType()->container;
5701+
valuetype.containerTypeToken = var.valueType()->containerTypeToken;
57015702
}
57025703
valuetype.smartPointerType = var.smartPointerType();
57035704
if (parsedecl(var.typeStartToken(), &valuetype, mDefaultSignedness, mSettings)) {
@@ -6548,20 +6549,13 @@ void SymbolDatabase::setValueTypeInTokenList(bool reportDebugWarnings, Token *to
65486549
const Token *typeStartToken = tok->astOperand1();
65496550
while (typeStartToken && typeStartToken->str() == "::")
65506551
typeStartToken = typeStartToken->astOperand1();
6551-
if (const Library::Container *c = mSettings->library.detectContainer(typeStartToken)) {
6552+
if (mSettings->library.detectContainer(typeStartToken) ||
6553+
mSettings->library.detectSmartPointer(typeStartToken)) {
65526554
ValueType vt;
6553-
vt.pointer = 0;
6554-
vt.container = c;
6555-
vt.type = ValueType::Type::CONTAINER;
6556-
setValueType(tok, vt);
6557-
continue;
6558-
}
6559-
if (const Library::SmartPointer* sp = mSettings->library.detectSmartPointer(typeStartToken)) {
6560-
ValueType vt;
6561-
vt.type = ValueType::Type::SMART_POINTER;
6562-
vt.smartPointer = sp;
6563-
setValueType(tok, vt);
6564-
continue;
6555+
if (parsedecl(typeStartToken, &vt, mDefaultSignedness, mSettings)) {
6556+
setValueType(tok, vt);
6557+
continue;
6558+
}
65656559
}
65666560

65676561
const std::string e = tok->astOperand1()->expressionString();

test/teststl.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4925,6 +4925,18 @@ class TestStl : public TestFixture {
49254925
" cb[i] = b[i];\n"
49264926
"}\n",true);
49274927
ASSERT_EQUALS("", errout.str());
4928+
4929+
// #9836
4930+
check("void f() {\n"
4931+
" auto v = std::vector<std::vector<std::string> >{ std::vector<std::string>{ \"hello\" } };\n"
4932+
" auto p = &(v.at(0).at(0));\n"
4933+
" v.clear();\n"
4934+
" std::cout << *p << std::endl;\n"
4935+
"}\n",
4936+
true);
4937+
ASSERT_EQUALS(
4938+
"[test.cpp:3] -> [test.cpp:3] -> [test.cpp:3] -> [test.cpp:4] -> [test.cpp:2] -> [test.cpp:5]: (error) Using pointer to local variable 'v' that may be invalid.\n",
4939+
errout.str());
49284940
}
49294941

49304942
void invalidContainerLoop() {

0 commit comments

Comments
 (0)