Check for containers that modify the size using square bracket
This commit is contained in:
parent
a5b0a1c9e2
commit
71c228a01a
|
@ -2391,7 +2391,7 @@ struct ValueFlowForwardAnalyzer : ForwardAnalyzer {
|
||||||
return Action::Invalid;
|
return Action::Invalid;
|
||||||
if (match(tok)) {
|
if (match(tok)) {
|
||||||
const Token* parent = tok->astParent();
|
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;
|
return Action::Read;
|
||||||
|
|
||||||
// Action read = Action::Read;
|
// Action read = Action::Read;
|
||||||
|
|
|
@ -4471,6 +4471,14 @@ private:
|
||||||
" ints.front();\n"
|
" ints.front();\n"
|
||||||
"}";
|
"}";
|
||||||
ASSERT_EQUALS("", isKnownContainerSizeValue(tokenValues(code, "ints . front", ValueFlow::Value::CONTAINER_SIZE), 2));
|
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() {
|
void valueFlowDynamicBufferSize() {
|
||||||
|
|
Loading…
Reference in New Issue