Check for containers that modify the size using square bracket

This commit is contained in:
Paul 2020-08-10 22:07:22 -05:00
parent a5b0a1c9e2
commit 71c228a01a
2 changed files with 9 additions and 1 deletions

View File

@ -2391,7 +2391,7 @@ struct ValueFlowForwardAnalyzer : ForwardAnalyzer {
return Action::Invalid;
if (match(tok)) {
const Token* parent = tok->astParent();
if ((Token::Match(parent, "*|[") || (parent && parent->originalName() == "->")) && getIndirect(tok) <= 0)
if (astIsPointer(tok) && (Token::Match(parent, "*|[") || (parent && parent->originalName() == "->")) && getIndirect(tok) <= 0)
return Action::Read;
// Action read = Action::Read;

View File

@ -4471,6 +4471,14 @@ private:
" ints.front();\n"
"}";
ASSERT_EQUALS("", isKnownContainerSizeValue(tokenValues(code, "ints . front", ValueFlow::Value::CONTAINER_SIZE), 2));
code = "int f(bool b) {\n"
" std::map<int, int> m;\n"
" if (b)\n"
" m[0] = 1;\n"
" return m.at(0);\n"
"}\n";
ASSERT_EQUALS("", isPossibleContainerSizeValue(tokenValues(code, "m . at", ValueFlow::Value::CONTAINER_SIZE), 0));
}
void valueFlowDynamicBufferSize() {