Fix issue 9945: FP: containerOutOfBounds (#2845)

This commit is contained in:
Paul Fultz II 2020-10-22 00:41:52 -05:00 committed by GitHub
parent 47914b9960
commit 64638d82bb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 12 additions and 0 deletions

View File

@ -4662,6 +4662,8 @@ static void valueFlowAfterCondition(TokenList *tokenlist,
ValueFlow::Value false_value;
const Token *vartok = parseCompareInt(tok, true_value, false_value);
if (vartok) {
if (vartok->hasKnownValue())
return cond;
if (vartok->str() == "=" && vartok->astOperand1() && vartok->astOperand2())
vartok = vartok->astOperand1();
cond.true_values.push_back(true_value);

View File

@ -2633,6 +2633,16 @@ private:
" }\n"
"}\n";
ASSERT_EQUALS(true, testValueOfXKnown(code, 7U, 0));
code = "void f(std::vector<int> v) {\n"
" if (v.size() == 3) {\n"
" if (v.size() == 1) {\n"
" int x = 1;\n"
" int a = x;\n"
" }\n"
" }\n"
"}\n";
ASSERT_EQUALS(true, testValueOfXKnown(code, 5U, 1));
}
void valueFlowAfterConditionSeveralNot() {