changed id for new checker to unsafeClassDivZero
This commit is contained in:
parent
64e61d28ba
commit
5de3c43209
|
@ -2441,7 +2441,7 @@ void CheckClass::copyCtorAndEqOperatorError(const Token *tok, const std::string
|
||||||
reportError(tok, Severity::warning, "copyCtorAndEqOperator", message);
|
reportError(tok, Severity::warning, "copyCtorAndEqOperator", message);
|
||||||
}
|
}
|
||||||
|
|
||||||
void CheckClass::checkPublicInterfaceDivZero(bool test)
|
void CheckClass::checkUnsafeClassDivZero(bool test)
|
||||||
{
|
{
|
||||||
if (!_settings->isEnabled(Settings::WARNING))
|
if (!_settings->isEnabled(Settings::WARNING))
|
||||||
return;
|
return;
|
||||||
|
@ -2471,15 +2471,15 @@ void CheckClass::checkPublicInterfaceDivZero(bool test)
|
||||||
const Variable *var = tok->astOperand2()->variable();
|
const Variable *var = tok->astOperand2()->variable();
|
||||||
if (!var || !var->isArgument())
|
if (!var || !var->isArgument())
|
||||||
continue;
|
continue;
|
||||||
publicInterfaceDivZeroError(tok, classScope->className, func->name(), var->name());
|
unsafeClassDivZeroError(tok, classScope->className, func->name(), var->name());
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void CheckClass::publicInterfaceDivZeroError(const Token *tok, const std::string &className, const std::string &methodName, const std::string &varName)
|
void CheckClass::unsafeClassDivZeroError(const Token *tok, const std::string &className, const std::string &methodName, const std::string &varName)
|
||||||
{
|
{
|
||||||
const std::string s = className + "::" + methodName + "()";
|
const std::string s = className + "::" + methodName + "()";
|
||||||
reportError(tok, Severity::warning, "classPublicInterfaceDivZero", "Public interface of " + className + " is not safe. When calling " + s + ", if parameter " + varName + " is 0 that leads to division by zero.");
|
reportError(tok, Severity::warning, "unsafeClassDivZero", "Public interface of " + className + " is not safe. When calling " + s + ", if parameter " + varName + " is 0 that leads to division by zero.");
|
||||||
}
|
}
|
||||||
|
|
|
@ -61,7 +61,7 @@ public:
|
||||||
|
|
||||||
// can't be a simplified check .. the 'sizeof' is used.
|
// can't be a simplified check .. the 'sizeof' is used.
|
||||||
checkClass.checkMemset();
|
checkClass.checkMemset();
|
||||||
checkClass.checkPublicInterfaceDivZero();
|
checkClass.checkUnsafeClassDivZero();
|
||||||
}
|
}
|
||||||
|
|
||||||
/** @brief Run checks on the simplified token list */
|
/** @brief Run checks on the simplified token list */
|
||||||
|
@ -153,7 +153,7 @@ public:
|
||||||
void checkCopyCtorAndEqOperator();
|
void checkCopyCtorAndEqOperator();
|
||||||
|
|
||||||
/** @brief Check that arbitrary usage of the public interface does not result in division by zero */
|
/** @brief Check that arbitrary usage of the public interface does not result in division by zero */
|
||||||
void checkPublicInterfaceDivZero(bool test=false);
|
void checkUnsafeClassDivZero(bool test=false);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
const SymbolDatabase *symbolDatabase;
|
const SymbolDatabase *symbolDatabase;
|
||||||
|
@ -187,7 +187,7 @@ private:
|
||||||
void callsPureVirtualFunctionError(const Function & scopeFunction, const std::list<const Token *> & tokStack, const std::string &purefuncname);
|
void callsPureVirtualFunctionError(const Function & scopeFunction, const std::list<const Token *> & tokStack, const std::string &purefuncname);
|
||||||
void duplInheritedMembersError(const Token* tok1, const Token* tok2, const std::string &derivedname, const std::string &basename, const std::string &variablename, bool derivedIsStruct, bool baseIsStruct);
|
void duplInheritedMembersError(const Token* tok1, const Token* tok2, const std::string &derivedname, const std::string &basename, const std::string &variablename, bool derivedIsStruct, bool baseIsStruct);
|
||||||
void copyCtorAndEqOperatorError(const Token *tok, const std::string &classname, bool isStruct, bool hasCopyCtor);
|
void copyCtorAndEqOperatorError(const Token *tok, const std::string &classname, bool isStruct, bool hasCopyCtor);
|
||||||
void publicInterfaceDivZeroError(const Token *tok, const std::string &className, const std::string &methodName, const std::string &varName);
|
void unsafeClassDivZeroError(const Token *tok, const std::string &className, const std::string &methodName, const std::string &varName);
|
||||||
|
|
||||||
void getErrorMessages(ErrorLogger *errorLogger, const Settings *settings) const {
|
void getErrorMessages(ErrorLogger *errorLogger, const Settings *settings) const {
|
||||||
CheckClass c(nullptr, settings, errorLogger);
|
CheckClass c(nullptr, settings, errorLogger);
|
||||||
|
@ -218,7 +218,7 @@ private:
|
||||||
c.selfInitializationError(nullptr, "var");
|
c.selfInitializationError(nullptr, "var");
|
||||||
c.duplInheritedMembersError(nullptr, nullptr, "class", "class", "variable", false, false);
|
c.duplInheritedMembersError(nullptr, nullptr, "class", "class", "variable", false, false);
|
||||||
c.copyCtorAndEqOperatorError(nullptr, "class", false, false);
|
c.copyCtorAndEqOperatorError(nullptr, "class", false, false);
|
||||||
c.publicInterfaceDivZeroError(nullptr, "Class", "dostuff", "x");
|
c.unsafeClassDivZeroError(nullptr, "Class", "dostuff", "x");
|
||||||
}
|
}
|
||||||
|
|
||||||
static std::string myName() {
|
static std::string myName() {
|
||||||
|
|
|
@ -189,7 +189,7 @@ private:
|
||||||
TEST_CASE(explicitConstructors);
|
TEST_CASE(explicitConstructors);
|
||||||
TEST_CASE(copyCtorAndEqOperator);
|
TEST_CASE(copyCtorAndEqOperator);
|
||||||
|
|
||||||
TEST_CASE(publicInterfaceDivZero);
|
TEST_CASE(unsafeClassDivZero);
|
||||||
}
|
}
|
||||||
|
|
||||||
void checkCopyCtorAndEqOperator(const char code[]) {
|
void checkCopyCtorAndEqOperator(const char code[]) {
|
||||||
|
@ -6495,7 +6495,7 @@ private:
|
||||||
ASSERT_EQUALS("", errout.str());
|
ASSERT_EQUALS("", errout.str());
|
||||||
}
|
}
|
||||||
|
|
||||||
void checkPublicInterfaceDivZero(const char code[]) {
|
void checkUnsafeClassDivZero(const char code[]) {
|
||||||
// Clear the error log
|
// Clear the error log
|
||||||
errout.str("");
|
errout.str("");
|
||||||
Settings settings;
|
Settings settings;
|
||||||
|
@ -6508,31 +6508,31 @@ private:
|
||||||
|
|
||||||
// Check..
|
// Check..
|
||||||
CheckClass checkClass(&tokenizer, &settings, this);
|
CheckClass checkClass(&tokenizer, &settings, this);
|
||||||
checkClass.checkPublicInterfaceDivZero(true);
|
checkClass.checkUnsafeClassDivZero(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
void publicInterfaceDivZero() {
|
void unsafeClassDivZero() {
|
||||||
checkPublicInterfaceDivZero("class A {\n"
|
checkUnsafeClassDivZero("class A {\n"
|
||||||
"public:\n"
|
"public:\n"
|
||||||
" void dostuff(int x);\n"
|
" void dostuff(int x);\n"
|
||||||
"}\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) Public interface of A is not safe. When calling A::dostuff(), if parameter x is 0 that leads to division by zero.\n", errout.str());
|
ASSERT_EQUALS("[test.cpp:5]: (warning) Public interface of A is not safe. When calling A::dostuff(), if parameter x is 0 that leads to division by zero.\n", errout.str());
|
||||||
|
|
||||||
checkPublicInterfaceDivZero("class A {\n"
|
checkUnsafeClassDivZero("class A {\n"
|
||||||
"public:\n"
|
"public:\n"
|
||||||
" void f1();\n"
|
" void f1();\n"
|
||||||
" void f2(int x);\n"
|
" void f2(int x);\n"
|
||||||
"}\n"
|
"}\n"
|
||||||
"void A::f1() {}\n"
|
"void A::f1() {}\n"
|
||||||
"void A::f2(int x) { int a = 1000 / x; }");
|
"void A::f2(int x) { int a = 1000 / x; }");
|
||||||
ASSERT_EQUALS("[test.cpp:7]: (warning) Public interface of A is not safe. When calling A::f2(), if parameter x is 0 that leads to division by zero.\n", errout.str());
|
ASSERT_EQUALS("[test.cpp:7]: (warning) Public interface of A is not safe. When calling A::f2(), if parameter x is 0 that leads to division by zero.\n", errout.str());
|
||||||
|
|
||||||
checkPublicInterfaceDivZero("class A {\n"
|
checkUnsafeClassDivZero("class A {\n"
|
||||||
"public:\n"
|
"public:\n"
|
||||||
" void operator/(int x);\n"
|
" void operator/(int x);\n"
|
||||||
"}\n"
|
"}\n"
|
||||||
"void A::operator/(int x) { int a = 1000 / x; }");
|
"void A::operator/(int x) { int a = 1000 / x; }");
|
||||||
ASSERT_EQUALS("", errout.str());
|
ASSERT_EQUALS("", errout.str());
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in New Issue