Fix 10955: False positive: containerOutOfBounds when using a const reference member (#4005)
This commit is contained in:
parent
00badff622
commit
61b87bcc60
|
@ -7733,7 +7733,7 @@ static void valueFlowContainerSize(TokenList* tokenlist,
|
||||||
if (size < 0)
|
if (size < 0)
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (!staticSize && !var->isConst() && nonLocal)
|
if (!staticSize && nonLocal)
|
||||||
continue;
|
continue;
|
||||||
if (var->nameToken()->hasKnownValue(ValueFlow::Value::ValueType::CONTAINER_SIZE))
|
if (var->nameToken()->hasKnownValue(ValueFlow::Value::ValueType::CONTAINER_SIZE))
|
||||||
continue;
|
continue;
|
||||||
|
|
|
@ -824,6 +824,26 @@ private:
|
||||||
"}\n");
|
"}\n");
|
||||||
ASSERT_EQUALS("test.cpp:3:error:Out of bounds access in 'array[i]', if 'array' size is 10 and 'i' is 10\n",
|
ASSERT_EQUALS("test.cpp:3:error:Out of bounds access in 'array[i]', if 'array' size is 10 and 'i' is 10\n",
|
||||||
errout.str());
|
errout.str());
|
||||||
|
|
||||||
|
checkNormal("struct A {\n"
|
||||||
|
" const std::vector<int>& v;\n"
|
||||||
|
" A(const std::vector<int>& x) : v(x)\n"
|
||||||
|
" {}\n"
|
||||||
|
" int f() const {\n"
|
||||||
|
" return v[0];\n"
|
||||||
|
" }\n"
|
||||||
|
"};\n");
|
||||||
|
ASSERT_EQUALS("", errout.str());
|
||||||
|
|
||||||
|
checkNormal("struct A {\n"
|
||||||
|
" static const std::vector<int> v;\n"
|
||||||
|
" int f() const {\n"
|
||||||
|
" return v[0];\n"
|
||||||
|
" }\n"
|
||||||
|
"};\n"
|
||||||
|
"const std::vector<int> A::v = {1, 2};\n");
|
||||||
|
ASSERT_EQUALS("", errout.str());
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void outOfBoundsSymbolic()
|
void outOfBoundsSymbolic()
|
||||||
|
|
Loading…
Reference in New Issue