Rephraze /Same/Identical/
This commit is contained in:
parent
97125acabd
commit
58db814d72
|
@ -580,7 +580,7 @@ void CheckCondition::multiCondition2()
|
|||
tokens2.push(secondCondition->astOperand2());
|
||||
} else if (isSameExpression(_tokenizer->isCPP(), true, cond1, secondCondition, _settings->library, true)) {
|
||||
if (!isAliased(vars))
|
||||
sameConditionAfterEarlyExitError(cond1, secondCondition);
|
||||
identicalConditionAfterEarlyExitError(cond1, secondCondition);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -663,13 +663,13 @@ void CheckCondition::oppositeInnerConditionError(const Token *tok1, const Token*
|
|||
reportError(errorPath, Severity::warning, "oppositeInnerCondition", msg, CWE398, false);
|
||||
}
|
||||
|
||||
void CheckCondition::sameConditionAfterEarlyExitError(const Token *cond1, const Token* cond2)
|
||||
void CheckCondition::identicalConditionAfterEarlyExitError(const Token *cond1, const Token* cond2)
|
||||
{
|
||||
const std::string cond(cond1 ? cond1->expressionString() : "x");
|
||||
ErrorPath errorPath;
|
||||
errorPath.push_back(ErrorPathItem(cond1, "first condition"));
|
||||
errorPath.push_back(ErrorPathItem(cond2, "second condition"));
|
||||
reportError(errorPath, Severity::warning, "sameConditionAfterEarlyExit", "Same condition '" + cond + "', second condition is always false", CWE398, false);
|
||||
reportError(errorPath, Severity::warning, "identicalConditionAfterEarlyExit", "Identical condition '" + cond + "', second condition is always false", CWE398, false);
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------
|
||||
|
|
|
@ -129,7 +129,7 @@ private:
|
|||
|
||||
void oppositeInnerConditionError(const Token *tok1, const Token* tok2);
|
||||
|
||||
void sameConditionAfterEarlyExitError(const Token *cond1, const Token *cond2);
|
||||
void identicalConditionAfterEarlyExitError(const Token *cond1, const Token *cond2);
|
||||
|
||||
void incorrectLogicOperatorError(const Token *tok, const std::string &condition, bool always, bool inconclusive);
|
||||
void redundantConditionError(const Token *tok, const std::string &text, bool inconclusive);
|
||||
|
@ -151,7 +151,7 @@ private:
|
|||
c.multiConditionError(nullptr,1);
|
||||
c.mismatchingBitAndError(nullptr, 0xf0, nullptr, 1);
|
||||
c.oppositeInnerConditionError(nullptr, nullptr);
|
||||
c.sameConditionAfterEarlyExitError(nullptr, nullptr);
|
||||
c.identicalConditionAfterEarlyExitError(nullptr, nullptr);
|
||||
c.incorrectLogicOperatorError(nullptr, "foo > 3 && foo < 4", true, false);
|
||||
c.redundantConditionError(nullptr, "If x > 11 the condition x > 10 is always true.", false);
|
||||
c.moduloAlwaysTrueFalseError(nullptr, "1");
|
||||
|
@ -172,7 +172,7 @@ private:
|
|||
"- Detect matching 'if' and 'else if' conditions\n"
|
||||
"- Mismatching bitand (a &= 0xf0; a &= 1; => a = 0)\n"
|
||||
"- Opposite inner condition is always false\n"
|
||||
"- Same condition after early exit is always false\n"
|
||||
"- Identical condition after early exit is always false\n"
|
||||
"- Condition that is always true/false\n"
|
||||
"- Mutual exclusion over || always evaluating to true\n"
|
||||
"- Comparisons of modulo results that are always true/false.\n"
|
||||
|
|
|
@ -1770,40 +1770,40 @@ private:
|
|||
" if (x > 100) { return; }\n"
|
||||
" if (x > 100) {}\n"
|
||||
"}");
|
||||
ASSERT_EQUALS("[test.cpp:2] -> [test.cpp:3]: (warning) Same condition 'x>100', second condition is always false\n", errout.str());
|
||||
ASSERT_EQUALS("[test.cpp:2] -> [test.cpp:3]: (warning) Identical condition 'x>100', second condition is always false\n", errout.str());
|
||||
|
||||
check("void f(int x) {\n"
|
||||
" if (x > 100) { return; }\n"
|
||||
" if (x > 100 || y > 100) {}\n"
|
||||
"}");
|
||||
ASSERT_EQUALS("[test.cpp:2] -> [test.cpp:3]: (warning) Same condition 'x>100', second condition is always false\n", errout.str());
|
||||
ASSERT_EQUALS("[test.cpp:2] -> [test.cpp:3]: (warning) Identical condition 'x>100', second condition is always false\n", errout.str());
|
||||
|
||||
check("void f(int x) {\n"
|
||||
" if (x > 100) { return; }\n"
|
||||
" if (x > 100 && y > 100) {}\n"
|
||||
"}");
|
||||
ASSERT_EQUALS("[test.cpp:2] -> [test.cpp:3]: (warning) Same condition 'x>100', second condition is always false\n", errout.str());
|
||||
ASSERT_EQUALS("[test.cpp:2] -> [test.cpp:3]: (warning) Identical condition 'x>100', second condition is always false\n", errout.str());
|
||||
|
||||
check("void f(int x) {\n"
|
||||
" if (x > 100) { return; }\n"
|
||||
" if (abc) {}\n"
|
||||
" if (x > 100) {}\n"
|
||||
"}");
|
||||
ASSERT_EQUALS("[test.cpp:2] -> [test.cpp:4]: (warning) Same condition 'x>100', second condition is always false\n", errout.str());
|
||||
ASSERT_EQUALS("[test.cpp:2] -> [test.cpp:4]: (warning) Identical condition 'x>100', second condition is always false\n", errout.str());
|
||||
|
||||
check("void f(int x) {\n"
|
||||
" if (x > 100) { return; }\n"
|
||||
" while (abc) { y = x; }\n"
|
||||
" if (x > 100) {}\n"
|
||||
"}");
|
||||
ASSERT_EQUALS("[test.cpp:2] -> [test.cpp:4]: (warning) Same condition 'x>100', second condition is always false\n", errout.str());
|
||||
ASSERT_EQUALS("[test.cpp:2] -> [test.cpp:4]: (warning) Identical condition 'x>100', second condition is always false\n", errout.str());
|
||||
|
||||
check("void f(const int *i) {\n"
|
||||
" if (!i) return;\n"
|
||||
" if (!num1tok) { *num1 = *num2; }\n"
|
||||
" if (!i) {}\n"
|
||||
"}");
|
||||
ASSERT_EQUALS("[test.cpp:2] -> [test.cpp:4]: (warning) Same condition '!i', second condition is always false\n", errout.str());
|
||||
ASSERT_EQUALS("[test.cpp:2] -> [test.cpp:4]: (warning) Identical condition '!i', second condition is always false\n", errout.str());
|
||||
|
||||
check("void C::f(Tree &coreTree) {\n" // daca
|
||||
" if(!coreTree.build())\n"
|
||||
|
@ -1820,7 +1820,7 @@ private:
|
|||
" coreTree.dostuff();\n"
|
||||
" if(!coreTree.build()) {}\n"
|
||||
"}\n");
|
||||
ASSERT_EQUALS("[test.cpp:3] -> [test.cpp:6]: (warning) Same condition '!coreTree.build()', second condition is always false\n", errout.str());
|
||||
ASSERT_EQUALS("[test.cpp:3] -> [test.cpp:6]: (warning) Identical condition '!coreTree.build()', second condition is always false\n", errout.str());
|
||||
|
||||
check("void f(int x) {\n" // daca: labplot
|
||||
" switch(type) {\n"
|
||||
|
|
Loading…
Reference in New Issue