valueFlowContainerSize: empty container variables
This commit is contained in:
parent
cfd5460670
commit
189ea5003a
|
@ -3494,6 +3494,21 @@ static void valueFlowContainerForward(const Token *tok, unsigned int containerId
|
||||||
|
|
||||||
static void valueFlowContainerSize(TokenList *tokenlist, SymbolDatabase* symboldatabase, ErrorLogger * /*errorLogger*/, const Settings *settings)
|
static void valueFlowContainerSize(TokenList *tokenlist, SymbolDatabase* symboldatabase, ErrorLogger * /*errorLogger*/, const Settings *settings)
|
||||||
{
|
{
|
||||||
|
// declaration
|
||||||
|
for (const Variable *var : symboldatabase->variableList()) {
|
||||||
|
if (!var || !var->isLocal() || var->isPointer() || var->isReference())
|
||||||
|
continue;
|
||||||
|
if (!var->valueType() || !var->valueType()->container)
|
||||||
|
continue;
|
||||||
|
if (!Token::Match(var->nameToken(), "%name% ;"))
|
||||||
|
continue;
|
||||||
|
ValueFlow::Value value(0);
|
||||||
|
value.valueType = ValueFlow::Value::ValueType::CONTAINER_SIZE;
|
||||||
|
value.setKnown();
|
||||||
|
valueFlowContainerForward(var->nameToken()->next(), var->declarationId(), value, settings);
|
||||||
|
}
|
||||||
|
|
||||||
|
// conditional conditionSize
|
||||||
for (const Scope &scope : symboldatabase->scopeList) {
|
for (const Scope &scope : symboldatabase->scopeList) {
|
||||||
if (scope.type != Scope::ScopeType::eIf) // TODO: while
|
if (scope.type != Scope::ScopeType::eIf) // TODO: while
|
||||||
continue;
|
continue;
|
||||||
|
|
|
@ -3325,6 +3325,12 @@ private:
|
||||||
" if (!v.empty() && v[10]==0) {}\n" // <- no container size for 'v[10]'
|
" if (!v.empty() && v[10]==0) {}\n" // <- no container size for 'v[10]'
|
||||||
"}";
|
"}";
|
||||||
ASSERT(tokenValues(code, "v [").empty());
|
ASSERT(tokenValues(code, "v [").empty());
|
||||||
|
|
||||||
|
code = "void f() {\n"
|
||||||
|
" std::list<int> ints;\n"
|
||||||
|
" ints.front();\n"
|
||||||
|
"}";
|
||||||
|
ASSERT_EQUALS("", isKnownContainerSizeValue(tokenValues(code, "ints . front"), 0));
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue