Fixed #3334 (Test for same expression on both sides of '&' reports false positive)
This commit is contained in:
parent
767413adad
commit
31b576de3b
|
@ -2544,6 +2544,34 @@ void CheckOther::checkExpressionRange(const std::list<Function> &constFunctions,
|
|||
std::map<std::string,ExpressionTokens>::const_iterator it = expressions.getMap().begin();
|
||||
const SymbolDatabase *symbolDatabase = _tokenizer->getSymbolDatabase();
|
||||
for (; it != expressions.getMap().end(); ++it) {
|
||||
// check expression..
|
||||
bool valid = true;
|
||||
unsigned int parantheses = 0; // ()
|
||||
unsigned int brackets = 0; // []
|
||||
const std::string &expr = it->first;
|
||||
for (std::string::size_type pos = 0; pos < expr.size(); ++pos) {
|
||||
if (expr[pos] == '(') {
|
||||
++parantheses;
|
||||
} else if (expr[pos] == ')') {
|
||||
if (parantheses == 0) {
|
||||
valid = false;
|
||||
break;
|
||||
}
|
||||
--parantheses;
|
||||
} else if (expr[pos] == '[') {
|
||||
++brackets;
|
||||
} else if (expr[pos] == ']') {
|
||||
if (brackets == 0) {
|
||||
valid = false;
|
||||
break;
|
||||
}
|
||||
--brackets;
|
||||
}
|
||||
}
|
||||
|
||||
if (!valid || parantheses!=0 || brackets!=0)
|
||||
continue;
|
||||
|
||||
if (it->second.count > 1 &&
|
||||
(it->first.find("(") == std::string::npos ||
|
||||
!inconclusiveFunctionCall(symbolDatabase, constFunctions, it->second))) {
|
||||
|
|
|
@ -3672,6 +3672,11 @@ private:
|
|||
"}");
|
||||
ASSERT_EQUALS("[test.cpp:2] -> [test.cpp:2]: (style) Same expression on both sides of '&'.\n", errout.str());
|
||||
|
||||
check("void foo() {\n"
|
||||
" if (a1[a2[c & 0xff] & 0xff]) {}\n"
|
||||
"}");
|
||||
ASSERT_EQUALS("", errout.str());
|
||||
|
||||
check("void d(const char f, int o, int v)\n"
|
||||
"{\n"
|
||||
" if (((f=='R') && (o == 1) && ((v < 2) || (v > 99))) ||\n"
|
||||
|
|
Loading…
Reference in New Issue