Fix 10263: FP containerOutOfBounds when container is accessed via pointer (#3265)
This commit is contained in:
parent
f0d1822a83
commit
c63aa2f2cc
|
@ -1270,9 +1270,8 @@ static void valueFlowPointerAliasDeref(TokenList *tokenlist)
|
|||
if (!var->isConst() && isVariableChanged(lifeTok->next(), tok, lifeTok->varId(), !var->isLocal(), tokenlist->getSettings(), tokenlist->isCPP()))
|
||||
continue;
|
||||
for (const ValueFlow::Value& v:lifeTok->values()) {
|
||||
// TODO: Move container size values to generic forward
|
||||
// Forward uninit values since not all values can be forwarded directly
|
||||
if (!(v.isContainerSizeValue() || v.isUninitValue()))
|
||||
if (!v.isUninitValue())
|
||||
continue;
|
||||
ValueFlow::Value value = v;
|
||||
value.errorPath.insert(value.errorPath.begin(), errorPath.begin(), errorPath.end());
|
||||
|
|
|
@ -430,6 +430,16 @@ private:
|
|||
" v[0] = 1;\n"
|
||||
"}\n");
|
||||
ASSERT_EQUALS("", errout.str());
|
||||
|
||||
checkNormal("void foo(std::vector<int>* PArr, int n) {\n"
|
||||
" std::vector<int> Arr;\n"
|
||||
" if (!PArr)\n"
|
||||
" PArr = &Arr;\n"
|
||||
" PArr->resize(n);\n"
|
||||
" for (int i = 0; i < n; ++i)\n"
|
||||
" (*PArr)[i] = 1;\n"
|
||||
"}\n");
|
||||
ASSERT_EQUALS("", errout.str());
|
||||
}
|
||||
|
||||
void outOfBoundsIndexExpression() {
|
||||
|
|
Loading…
Reference in New Issue