Fix issue 8253: False negative: Comparison is always true (early return) (#3043)

This commit is contained in:
Paul Fultz II 2021-01-13 05:35:43 -06:00 committed by GitHub
parent 1858465bca
commit b469da1069
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 10 additions and 2 deletions

View File

@ -386,8 +386,6 @@ struct ForwardTraversal {
Token* endBlock = endCond->next()->link();
Token* condTok = getCondTok(tok);
Token* initTok = getInitTok(tok);
if (!condTok)
return Progress::Break;
if (initTok && updateRecursive(initTok) == Progress::Break)
return Progress::Break;
if (Token::Match(tok, "for|while (")) {

View File

@ -4270,6 +4270,16 @@ private:
"}\n";
ASSERT_EQUALS(false, testValueOfXKnown(code, 10U, 0));
ASSERT_EQUALS(false, testValueOfXKnown(code, 10U, 1));
code = "void f() {\n"
" const int size = arrayInfo.num(0);\n"
" if (size <= 0)\n"
" return;\n"
" for (;;)\n"
" if (size > 0) {}\n"
"}\n";
ASSERT_EQUALS(true, valueOfTok(code, "> 0").isKnown());
ASSERT_EQUALS(true, valueOfTok(code, "> 0").intvalue == 1);
}
static std::string isPossibleContainerSizeValue(const std::list<ValueFlow::Value> &values, MathLib::bigint i) {