Fixed #9905 (False positive: known argument 'header.length()')

This commit is contained in:
Daniel Marjamäki 2020-09-20 20:17:10 +02:00
parent c563944fdd
commit 730b95331e
2 changed files with 16 additions and 0 deletions

View File

@ -3113,6 +3113,15 @@ void CheckOther::checkKnownArgument()
tok2 = tok2->astOperand2(); tok2 = tok2->astOperand2();
if (isVariableExpression(tok2)) if (isVariableExpression(tok2))
continue; continue;
// ensure that there is a integer variable in expression with unknown value
bool intvar = false;
visitAstNodes(tok, [&intvar](const Token *child) {
if (child->varId() && child->valueType() && child->valueType()->isIntegral() && child->values().empty())
intvar = true;
return ChildrenToVisit::op1_and_op2;
});
if (!intvar)
continue;
// ensure that function name does not contain "assert" // ensure that function name does not contain "assert"
std::string funcname = tok->astParent()->previous()->str(); std::string funcname = tok->astParent()->previous()->str();
std::transform(funcname.begin(), funcname.end(), funcname.begin(), [](int c) { std::transform(funcname.begin(), funcname.end(), funcname.begin(), [](int c) {

View File

@ -8835,6 +8835,13 @@ private:
" ASSERT((int)((x & 0x01) >> 7));\n" " ASSERT((int)((x & 0x01) >> 7));\n"
"}\n"); "}\n");
ASSERT_EQUALS("", errout.str()); ASSERT_EQUALS("", errout.str());
// #9905 - expression that does not use integer calculation at all
check("void foo() {\n"
" const std::string heading = \"Interval\";\n"
" std::cout << std::setw(heading.length());\n"
"}");
ASSERT_EQUALS("", errout.str());
} }
void checkComparePointers() { void checkComparePointers() {