Skip to content

Commit 730b953

Browse files
committed
Fixed #9905 (False positive: known argument 'header.length()')
1 parent c563944 commit 730b953

2 files changed

Lines changed: 16 additions & 0 deletions

File tree

lib/checkother.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3113,6 +3113,15 @@ void CheckOther::checkKnownArgument()
31133113
tok2 = tok2->astOperand2();
31143114
if (isVariableExpression(tok2))
31153115
continue;
3116+
// ensure that there is a integer variable in expression with unknown value
3117+
bool intvar = false;
3118+
visitAstNodes(tok, [&intvar](const Token *child) {
3119+
if (child->varId() && child->valueType() && child->valueType()->isIntegral() && child->values().empty())
3120+
intvar = true;
3121+
return ChildrenToVisit::op1_and_op2;
3122+
});
3123+
if (!intvar)
3124+
continue;
31163125
// ensure that function name does not contain "assert"
31173126
std::string funcname = tok->astParent()->previous()->str();
31183127
std::transform(funcname.begin(), funcname.end(), funcname.begin(), [](int c) {

test/testother.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8835,6 +8835,13 @@ class TestOther : public TestFixture {
88358835
" ASSERT((int)((x & 0x01) >> 7));\n"
88368836
"}\n");
88378837
ASSERT_EQUALS("", errout.str());
8838+
8839+
// #9905 - expression that does not use integer calculation at all
8840+
check("void foo() {\n"
8841+
" const std::string heading = \"Interval\";\n"
8842+
" std::cout << std::setw(heading.length());\n"
8843+
"}");
8844+
ASSERT_EQUALS("", errout.str());
88388845
}
88398846

88408847
void checkComparePointers() {

0 commit comments

Comments
 (0)