Fix cppcheckError with for loop (#3847)
This commit is contained in:
parent
bedde0a1df
commit
734e3ac6da
|
@ -6071,9 +6071,12 @@ static void valueFlowForLoopSimplify(Token* const bodyStart,
|
||||||
|
|
||||||
}
|
}
|
||||||
const Token* vartok = expr;
|
const Token* vartok = expr;
|
||||||
const Token* rml = nextAfterAstRightmostLeaf(expr);
|
const Token* rml = nextAfterAstRightmostLeaf(vartok);
|
||||||
if (rml)
|
if (rml)
|
||||||
vartok = rml->previous();
|
vartok = rml->str() == "]" ? rml : rml->previous();
|
||||||
|
if (vartok->str() == "]" && vartok->link()->previous())
|
||||||
|
vartok = vartok->link()->previous();
|
||||||
|
|
||||||
if ((tok2->str() == "&&" &&
|
if ((tok2->str() == "&&" &&
|
||||||
conditionIsFalse(tok2->astOperand1(),
|
conditionIsFalse(tok2->astOperand1(),
|
||||||
getProgramMemory(tok2->astTop(), expr, ValueFlow::Value(value), settings))) ||
|
getProgramMemory(tok2->astTop(), expr, ValueFlow::Value(value), settings))) ||
|
||||||
|
|
|
@ -4107,8 +4107,21 @@ private:
|
||||||
"void b(S& s) {\n"
|
"void b(S& s) {\n"
|
||||||
" for (*s.a = 1;;)\n"
|
" for (*s.a = 1;;)\n"
|
||||||
" if (0) {}\n"
|
" if (0) {}\n"
|
||||||
|
"}\n"
|
||||||
|
"struct T { S s; };\n"
|
||||||
|
"void b(T& t) {\n"
|
||||||
|
" for (*&t.s.a[0] = 1;;)\n"
|
||||||
|
" if (0) {}\n"
|
||||||
"}\n";
|
"}\n";
|
||||||
testValueOfX(code, 0, 0); // <- don't crash
|
testValueOfX(code, 0, 0); // <- don't throw
|
||||||
|
|
||||||
|
code = "void f() {\n"
|
||||||
|
" int p[2];\n"
|
||||||
|
" for (p[0] = 0; p[0] <= 2; p[0]++) {\n"
|
||||||
|
" for (p[1] = 0; p[1] <= 2 - p[0]; p[1]++) {}\n"
|
||||||
|
" }\n"
|
||||||
|
"}\n";
|
||||||
|
testValueOfX(code, 0, 0); // <- don't throw
|
||||||
}
|
}
|
||||||
|
|
||||||
void valueFlowSubFunction() {
|
void valueFlowSubFunction() {
|
||||||
|
|
Loading…
Reference in New Issue