Fix issue 9945: FP: containerOutOfBounds (#2845)
This commit is contained in:
parent
47914b9960
commit
64638d82bb
|
@ -4662,6 +4662,8 @@ static void valueFlowAfterCondition(TokenList *tokenlist,
|
||||||
ValueFlow::Value false_value;
|
ValueFlow::Value false_value;
|
||||||
const Token *vartok = parseCompareInt(tok, true_value, false_value);
|
const Token *vartok = parseCompareInt(tok, true_value, false_value);
|
||||||
if (vartok) {
|
if (vartok) {
|
||||||
|
if (vartok->hasKnownValue())
|
||||||
|
return cond;
|
||||||
if (vartok->str() == "=" && vartok->astOperand1() && vartok->astOperand2())
|
if (vartok->str() == "=" && vartok->astOperand1() && vartok->astOperand2())
|
||||||
vartok = vartok->astOperand1();
|
vartok = vartok->astOperand1();
|
||||||
cond.true_values.push_back(true_value);
|
cond.true_values.push_back(true_value);
|
||||||
|
|
|
@ -2633,6 +2633,16 @@ private:
|
||||||
" }\n"
|
" }\n"
|
||||||
"}\n";
|
"}\n";
|
||||||
ASSERT_EQUALS(true, testValueOfXKnown(code, 7U, 0));
|
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() {
|
void valueFlowAfterConditionSeveralNot() {
|
||||||
|
|
Loading…
Reference in New Issue