Skip to content

Commit 5de3c43

Browse files
committed
changed id for new checker to unsafeClassDivZero
1 parent 64e61d2 commit 5de3c43

3 files changed

Lines changed: 29 additions & 29 deletions

File tree

lib/checkclass.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2441,7 +2441,7 @@ void CheckClass::copyCtorAndEqOperatorError(const Token *tok, const std::string
24412441
reportError(tok, Severity::warning, "copyCtorAndEqOperator", message);
24422442
}
24432443

2444-
void CheckClass::checkPublicInterfaceDivZero(bool test)
2444+
void CheckClass::checkUnsafeClassDivZero(bool test)
24452445
{
24462446
if (!_settings->isEnabled(Settings::WARNING))
24472447
return;
@@ -2471,15 +2471,15 @@ void CheckClass::checkPublicInterfaceDivZero(bool test)
24712471
const Variable *var = tok->astOperand2()->variable();
24722472
if (!var || !var->isArgument())
24732473
continue;
2474-
publicInterfaceDivZeroError(tok, classScope->className, func->name(), var->name());
2474+
unsafeClassDivZeroError(tok, classScope->className, func->name(), var->name());
24752475
break;
24762476
}
24772477
}
24782478
}
24792479
}
24802480

2481-
void CheckClass::publicInterfaceDivZeroError(const Token *tok, const std::string &className, const std::string &methodName, const std::string &varName)
2481+
void CheckClass::unsafeClassDivZeroError(const Token *tok, const std::string &className, const std::string &methodName, const std::string &varName)
24822482
{
24832483
const std::string s = className + "::" + methodName + "()";
2484-
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.");
2484+
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.");
24852485
}

lib/checkclass.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ class CPPCHECKLIB CheckClass : public Check {
6161

6262
// can't be a simplified check .. the 'sizeof' is used.
6363
checkClass.checkMemset();
64-
checkClass.checkPublicInterfaceDivZero();
64+
checkClass.checkUnsafeClassDivZero();
6565
}
6666

6767
/** @brief Run checks on the simplified token list */
@@ -153,7 +153,7 @@ class CPPCHECKLIB CheckClass : public Check {
153153
void checkCopyCtorAndEqOperator();
154154

155155
/** @brief Check that arbitrary usage of the public interface does not result in division by zero */
156-
void checkPublicInterfaceDivZero(bool test=false);
156+
void checkUnsafeClassDivZero(bool test=false);
157157

158158
private:
159159
const SymbolDatabase *symbolDatabase;
@@ -187,7 +187,7 @@ class CPPCHECKLIB CheckClass : public Check {
187187
void callsPureVirtualFunctionError(const Function & scopeFunction, const std::list<const Token *> & tokStack, const std::string &purefuncname);
188188
void duplInheritedMembersError(const Token* tok1, const Token* tok2, const std::string &derivedname, const std::string &basename, const std::string &variablename, bool derivedIsStruct, bool baseIsStruct);
189189
void copyCtorAndEqOperatorError(const Token *tok, const std::string &classname, bool isStruct, bool hasCopyCtor);
190-
void publicInterfaceDivZeroError(const Token *tok, const std::string &className, const std::string &methodName, const std::string &varName);
190+
void unsafeClassDivZeroError(const Token *tok, const std::string &className, const std::string &methodName, const std::string &varName);
191191

192192
void getErrorMessages(ErrorLogger *errorLogger, const Settings *settings) const {
193193
CheckClass c(nullptr, settings, errorLogger);
@@ -218,7 +218,7 @@ class CPPCHECKLIB CheckClass : public Check {
218218
c.selfInitializationError(nullptr, "var");
219219
c.duplInheritedMembersError(nullptr, nullptr, "class", "class", "variable", false, false);
220220
c.copyCtorAndEqOperatorError(nullptr, "class", false, false);
221-
c.publicInterfaceDivZeroError(nullptr, "Class", "dostuff", "x");
221+
c.unsafeClassDivZeroError(nullptr, "Class", "dostuff", "x");
222222
}
223223

224224
static std::string myName() {

test/testclass.cpp

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,7 @@ class TestClass : public TestFixture {
189189
TEST_CASE(explicitConstructors);
190190
TEST_CASE(copyCtorAndEqOperator);
191191

192-
TEST_CASE(publicInterfaceDivZero);
192+
TEST_CASE(unsafeClassDivZero);
193193
}
194194

195195
void checkCopyCtorAndEqOperator(const char code[]) {
@@ -6495,7 +6495,7 @@ class TestClass : public TestFixture {
64956495
ASSERT_EQUALS("", errout.str());
64966496
}
64976497

6498-
void checkPublicInterfaceDivZero(const char code[]) {
6498+
void checkUnsafeClassDivZero(const char code[]) {
64996499
// Clear the error log
65006500
errout.str("");
65016501
Settings settings;
@@ -6508,31 +6508,31 @@ class TestClass : public TestFixture {
65086508

65096509
// Check..
65106510
CheckClass checkClass(&tokenizer, &settings, this);
6511-
checkClass.checkPublicInterfaceDivZero(true);
6511+
checkClass.checkUnsafeClassDivZero(true);
65126512
}
65136513

6514-
void publicInterfaceDivZero() {
6515-
checkPublicInterfaceDivZero("class A {\n"
6516-
"public:\n"
6517-
" void dostuff(int x);\n"
6518-
"}\n"
6519-
"void A::dostuff(int x) { int a = 1000 / x; }");
6514+
void unsafeClassDivZero() {
6515+
checkUnsafeClassDivZero("class A {\n"
6516+
"public:\n"
6517+
" void dostuff(int x);\n"
6518+
"}\n"
6519+
"void A::dostuff(int x) { int a = 1000 / x; }");
65206520
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());
65216521

6522-
checkPublicInterfaceDivZero("class A {\n"
6523-
"public:\n"
6524-
" void f1();\n"
6525-
" void f2(int x);\n"
6526-
"}\n"
6527-
"void A::f1() {}\n"
6528-
"void A::f2(int x) { int a = 1000 / x; }");
6522+
checkUnsafeClassDivZero("class A {\n"
6523+
"public:\n"
6524+
" void f1();\n"
6525+
" void f2(int x);\n"
6526+
"}\n"
6527+
"void A::f1() {}\n"
6528+
"void A::f2(int x) { int a = 1000 / x; }");
65296529
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());
65306530

6531-
checkPublicInterfaceDivZero("class A {\n"
6532-
"public:\n"
6533-
" void operator/(int x);\n"
6534-
"}\n"
6535-
"void A::operator/(int x) { int a = 1000 / x; }");
6531+
checkUnsafeClassDivZero("class A {\n"
6532+
"public:\n"
6533+
" void operator/(int x);\n"
6534+
"}\n"
6535+
"void A::operator/(int x) { int a = 1000 / x; }");
65366536
ASSERT_EQUALS("", errout.str());
65376537
}
65386538
};

0 commit comments

Comments
 (0)