Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions lib/checkcondition.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1134,6 +1134,11 @@ void CheckCondition::checkIncorrectLogicOperator()
if (inconclusive && !printInconclusive)
continue;

const bool isUnknown = (expr1 && expr1->valueType() && expr1->valueType()->type == ValueType::UNKNOWN_TYPE) ||
(expr2 && expr2->valueType() && expr2->valueType()->type == ValueType::UNKNOWN_TYPE);
if (isUnknown)
continue;

const bool isfloat = astIsFloat(expr1, true) || MathLib::isFloat(value1) || astIsFloat(expr2, true) || MathLib::isFloat(value2);

ErrorPath errorPath;
Expand Down Expand Up @@ -1442,6 +1447,12 @@ void CheckCondition::alwaysTrueFalse()
if (!(constIfWhileExpression || constValExpr || compExpr || ternaryExpression || returnExpression))
continue;

const Token* expr1 = tok->astOperand1(), *expr2 = tok->astOperand2();
const bool isUnknown = (expr1 && expr1->valueType() && expr1->valueType()->type == ValueType::UNKNOWN_TYPE) ||
(expr2 && expr2->valueType() && expr2->valueType()->type == ValueType::UNKNOWN_TYPE);
if (isUnknown)
continue;

// Don't warn when there are expanded macros..
bool isExpandedMacro = false;
visitAstNodes(tok, [&](const Token * tok2) {
Expand Down
8 changes: 8 additions & 0 deletions test/testcondition.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1209,6 +1209,14 @@ class TestCondition : public TestFixture {
" if (x && x != ZERO) {}\n"
"}");
ASSERT_EQUALS("", errout.str());

check("void f(int N) {\n" // #9789
" T a[20] = { 0 };\n"
" for (int i = 0; i < N; ++i) {\n"
" if (0 < a[i] && a[i] < 1) {}\n"
" }\n"
"}\n");
ASSERT_EQUALS("", errout.str());
}

void incorrectLogicOperator5() { // complex expressions
Expand Down