CheckClass: Fix wrong 'public interface' warnings
This commit is contained in:
parent
5bf29fae49
commit
8a7411abdb
|
@ -2448,17 +2448,17 @@ void CheckClass::checkPublicInterfaceDivZero(bool test)
|
||||||
|
|
||||||
const std::size_t classes = symbolDatabase->classAndStructScopes.size();
|
const std::size_t classes = symbolDatabase->classAndStructScopes.size();
|
||||||
for (std::size_t i = 0; i < classes; ++i) {
|
for (std::size_t i = 0; i < classes; ++i) {
|
||||||
const Scope * scope = symbolDatabase->classAndStructScopes[i];
|
const Scope * classScope = symbolDatabase->classAndStructScopes[i];
|
||||||
if (!test && scope->classDef->fileIndex() != 1)
|
if (!test && classScope->classDef->fileIndex() != 1)
|
||||||
continue;
|
continue;
|
||||||
std::list<Function>::const_iterator func;
|
std::list<Function>::const_iterator func;
|
||||||
for (func = scope->functionList.begin(); func != scope->functionList.end(); ++func) {
|
for (func = classScope->functionList.begin(); func != classScope->functionList.end(); ++func) {
|
||||||
if (func->access != AccessControl::Public)
|
if (func->access != AccessControl::Public)
|
||||||
continue;
|
continue;
|
||||||
if (!func->hasBody())
|
if (!func->hasBody())
|
||||||
continue;
|
continue;
|
||||||
for (const Token *tok = func->functionScope->classStart; tok; tok = tok->next()) {
|
for (const Token *tok = func->functionScope->classStart; tok; tok = tok->next()) {
|
||||||
if (tok->str() == "if")
|
if (Token::Match(tok, "if|}"))
|
||||||
break;
|
break;
|
||||||
if (tok->str() != "/")
|
if (tok->str() != "/")
|
||||||
continue;
|
continue;
|
||||||
|
@ -2468,7 +2468,7 @@ void CheckClass::checkPublicInterfaceDivZero(bool test)
|
||||||
continue;
|
continue;
|
||||||
const Variable *var = tok->astOperand2()->variable();
|
const Variable *var = tok->astOperand2()->variable();
|
||||||
if (var && var->isArgument())
|
if (var && var->isArgument())
|
||||||
publicInterfaceDivZeroError(tok, scope->className + "::" + func->name());
|
publicInterfaceDivZeroError(tok, classScope->className + "::" + func->name());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -6518,6 +6518,15 @@ private:
|
||||||
"}\n"
|
"}\n"
|
||||||
"void A::dostuff(int x) { int a = 1000 / x; }");
|
"void A::dostuff(int x) { int a = 1000 / x; }");
|
||||||
ASSERT_EQUALS("[test.cpp:5]: (warning) Arbitrary usage of public method A::dostuff() could result in division by zero.\n", errout.str());
|
ASSERT_EQUALS("[test.cpp:5]: (warning) Arbitrary usage of public method A::dostuff() could result in division by zero.\n", errout.str());
|
||||||
|
|
||||||
|
checkPublicInterfaceDivZero("class A {\n"
|
||||||
|
"public:\n"
|
||||||
|
" void f1();\n"
|
||||||
|
" void f2(int x);\n"
|
||||||
|
"}\n"
|
||||||
|
"void A::f1() {}\n"
|
||||||
|
"void A::f2(int x) { int a = 1000 / x; }");
|
||||||
|
ASSERT_EQUALS("[test.cpp:7]: (warning) Arbitrary usage of public method A::f2() could result in division by zero.\n", errout.str());
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue