Fix 10263: FP containerOutOfBounds when container is accessed via pointer (#3265)

This commit is contained in:
Paul Fultz II 2021-05-22 01:36:51 -05:00 committed by GitHub
parent f0d1822a83
commit c63aa2f2cc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 11 additions and 2 deletions

View File

@ -1270,9 +1270,8 @@ static void valueFlowPointerAliasDeref(TokenList *tokenlist)
if (!var->isConst() && isVariableChanged(lifeTok->next(), tok, lifeTok->varId(), !var->isLocal(), tokenlist->getSettings(), tokenlist->isCPP())) if (!var->isConst() && isVariableChanged(lifeTok->next(), tok, lifeTok->varId(), !var->isLocal(), tokenlist->getSettings(), tokenlist->isCPP()))
continue; continue;
for (const ValueFlow::Value& v:lifeTok->values()) { 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 // Forward uninit values since not all values can be forwarded directly
if (!(v.isContainerSizeValue() || v.isUninitValue())) if (!v.isUninitValue())
continue; continue;
ValueFlow::Value value = v; ValueFlow::Value value = v;
value.errorPath.insert(value.errorPath.begin(), errorPath.begin(), errorPath.end()); value.errorPath.insert(value.errorPath.begin(), errorPath.begin(), errorPath.end());

View File

@ -430,6 +430,16 @@ private:
" v[0] = 1;\n" " v[0] = 1;\n"
"}\n"); "}\n");
ASSERT_EQUALS("", errout.str()); 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() { void outOfBoundsIndexExpression() {