From 5de3c43209b2f6df5ba5c95b92db01c7cfd2bda6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Sat, 21 Oct 2017 21:45:04 +0200 Subject: [PATCH] changed id for new checker to unsafeClassDivZero --- lib/checkclass.cpp | 8 ++++---- lib/checkclass.h | 8 ++++---- test/testclass.cpp | 42 +++++++++++++++++++++--------------------- 3 files changed, 29 insertions(+), 29 deletions(-) diff --git a/lib/checkclass.cpp b/lib/checkclass.cpp index 6b5a7cea3..1c614c5a7 100644 --- a/lib/checkclass.cpp +++ b/lib/checkclass.cpp @@ -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."); } diff --git a/lib/checkclass.h b/lib/checkclass.h index 0633ab6f0..d0e8743ff 100644 --- a/lib/checkclass.h +++ b/lib/checkclass.h @@ -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 & 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() { diff --git a/test/testclass.cpp b/test/testclass.cpp index 2e1efafb9..a8b13c5b3 100644 --- a/test/testclass.cpp +++ b/test/testclass.cpp @@ -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,31 +6508,31 @@ private: // Check.. CheckClass checkClass(&tokenizer, &settings, this); - checkClass.checkPublicInterfaceDivZero(true); + checkClass.checkUnsafeClassDivZero(true); } - void publicInterfaceDivZero() { - checkPublicInterfaceDivZero("class A {\n" - "public:\n" - " void dostuff(int x);\n" - "}\n" - "void A::dostuff(int x) { int a = 1000 / x; }"); + 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" - "public:\n" - " void f1();\n" - " void f2(int x);\n" - "}\n" - "void A::f1() {}\n" - "void A::f2(int x) { int a = 1000 / x; }"); + checkUnsafeClassDivZero("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) 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" - "public:\n" - " void operator/(int x);\n" - "}\n" - "void A::operator/(int x) { int a = 1000 / x; }"); + checkUnsafeClassDivZero("class A {\n" + "public:\n" + " void operator/(int x);\n" + "}\n" + "void A::operator/(int x) { int a = 1000 / x; }"); ASSERT_EQUALS("", errout.str()); } };