changed id for new checker to unsafeClassDivZero

This commit is contained in:
Daniel Marjamäki 2017-10-21 21:45:04 +02:00
parent 64e61d28ba
commit 5de3c43209
3 changed files with 29 additions and 29 deletions

View File

@ -2441,7 +2441,7 @@ void CheckClass::copyCtorAndEqOperatorError(const Token *tok, const std::string
reportError(tok, Severity::warning, "copyCtorAndEqOperator", message);
}
void CheckClass::checkPublicInterfaceDivZero(bool test)
void CheckClass::checkUnsafeClassDivZero(bool test)
{
if (!_settings->isEnabled(Settings::WARNING))
return;
@ -2471,15 +2471,15 @@ void CheckClass::checkPublicInterfaceDivZero(bool test)
const Variable *var = tok->astOperand2()->variable();
if (!var || !var->isArgument())
continue;
publicInterfaceDivZeroError(tok, classScope->className, func->name(), var->name());
unsafeClassDivZeroError(tok, classScope->className, func->name(), var->name());
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 + "()";
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.");
}

View File

@ -61,7 +61,7 @@ public:
// can't be a simplified check .. the 'sizeof' is used.
checkClass.checkMemset();
checkClass.checkPublicInterfaceDivZero();
checkClass.checkUnsafeClassDivZero();
}
/** @brief Run checks on the simplified token list */
@ -153,7 +153,7 @@ public:
void checkCopyCtorAndEqOperator();
/** @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:
const SymbolDatabase *symbolDatabase;
@ -187,7 +187,7 @@ private:
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 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 {
CheckClass c(nullptr, settings, errorLogger);
@ -218,7 +218,7 @@ private:
c.selfInitializationError(nullptr, "var");
c.duplInheritedMembersError(nullptr, nullptr, "class", "class", "variable", false, false);
c.copyCtorAndEqOperatorError(nullptr, "class", false, false);
c.publicInterfaceDivZeroError(nullptr, "Class", "dostuff", "x");
c.unsafeClassDivZeroError(nullptr, "Class", "dostuff", "x");
}
static std::string myName() {

View File

@ -189,7 +189,7 @@ private:
TEST_CASE(explicitConstructors);
TEST_CASE(copyCtorAndEqOperator);
TEST_CASE(publicInterfaceDivZero);
TEST_CASE(unsafeClassDivZero);
}
void checkCopyCtorAndEqOperator(const char code[]) {
@ -6495,7 +6495,7 @@ private:
ASSERT_EQUALS("", errout.str());
}
void checkPublicInterfaceDivZero(const char code[]) {
void checkUnsafeClassDivZero(const char code[]) {
// Clear the error log
errout.str("");
Settings settings;
@ -6508,18 +6508,18 @@ private:
// Check..
CheckClass checkClass(&tokenizer, &settings, this);
checkClass.checkPublicInterfaceDivZero(true);
checkClass.checkUnsafeClassDivZero(true);
}
void publicInterfaceDivZero() {
checkPublicInterfaceDivZero("class A {\n"
void unsafeClassDivZero() {
checkUnsafeClassDivZero("class A {\n"
"public:\n"
" void dostuff(int x);\n"
"}\n"
"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());
checkPublicInterfaceDivZero("class A {\n"
checkUnsafeClassDivZero("class A {\n"
"public:\n"
" void f1();\n"
" void f2(int x);\n"
@ -6528,7 +6528,7 @@ private:
"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());
checkPublicInterfaceDivZero("class A {\n"
checkUnsafeClassDivZero("class A {\n"
"public:\n"
" void operator/(int x);\n"
"}\n"