Renamed safeClassRefMember => unsafeClassRefMember

This commit is contained in:
Daniel Marjamäki 2019-08-13 20:58:31 +02:00
parent ed7edc6d2a
commit d4549217d0
3 changed files with 15 additions and 15 deletions

View File

@ -2664,7 +2664,7 @@ void CheckClass::overrideError(const Function *funcInBase, const Function *funcI
false);
}
void CheckClass::checkSafeClassRefMember()
void CheckClass::checkUnsafeClassRefMember()
{
if (!mSettings->safeChecks.classes || !mSettings->isEnabled(Settings::WARNING))
return;
@ -2679,7 +2679,7 @@ void CheckClass::checkSafeClassRefMember()
const Variable * const memberVar = initList->next()->variable();
const Variable * const argVar = initList->tokAt(3)->variable();
if (memberVar && argVar && memberVar->isConst() && memberVar->isReference() && argVar->isArgument() && argVar->isConst() && argVar->isReference())
safeClassRefMemberError(initList->next(), classScope->className + "::" + memberVar->name());
unsafeClassRefMemberError(initList->next(), classScope->className + "::" + memberVar->name());
}
initList = initList->linkAt(2)->next();
}
@ -2687,11 +2687,11 @@ void CheckClass::checkSafeClassRefMember()
}
}
void CheckClass::safeClassRefMemberError(const Token *tok, const std::string &varname)
void CheckClass::unsafeClassRefMemberError(const Token *tok, const std::string &varname)
{
reportError(tok, Severity::warning, "safeClassRefMember",
reportError(tok, Severity::warning, "unsafeClassRefMember",
"$symbol:" + varname + "\n"
"Unsafe class: The const reference member '$symbol' is initialized by a const reference constructor argument. You need to be careful about lifetime issues.\n"
"Safe class checking: The const reference member '$symbol' is initialized by a const reference constructor argument. You need to be careful about lifetime issues. If you pass a local variable or temporary value in this constructor argument, be extra careful. If the argument is always some global object that is never destroyed then this is safe usage. However it would be defensive to make the member '$symbol' a non-reference variable or a smart pointer.",
"Unsafe class checking: The const reference member '$symbol' is initialized by a const reference constructor argument. You need to be careful about lifetime issues. If you pass a local variable or temporary value in this constructor argument, be extra careful. If the argument is always some global object that is never destroyed then this is safe usage. However it would be defensive to make the member '$symbol' a non-reference variable or a smart pointer.",
CWE(0), false);
}

View File

@ -79,7 +79,7 @@ public:
checkClass.checkExplicitConstructors();
checkClass.checkCopyCtorAndEqOperator();
checkClass.checkOverride();
checkClass.checkSafeClassRefMember();
checkClass.checkUnsafeClassRefMember();
}
/** @brief %Check that all class constructors are ok */
@ -147,8 +147,8 @@ public:
/** @brief Check that the override keyword is used when overriding virtual functions */
void checkOverride();
/** @brief Safe class check - const reference member */
void checkSafeClassRefMember();
/** @brief Unsafe class check - const reference member */
void checkUnsafeClassRefMember();
private:
const SymbolDatabase *mSymbolDatabase;
@ -187,7 +187,7 @@ private:
void copyCtorAndEqOperatorError(const Token *tok, const std::string &classname, bool isStruct, bool hasCopyCtor);
void unsafeClassDivZeroError(const Token *tok, const std::string &className, const std::string &methodName, const std::string &varName);
void overrideError(const Function *funcInBase, const Function *funcInDerived);
void safeClassRefMemberError(const Token *tok, const std::string &varname);
void unsafeClassRefMemberError(const Token *tok, const std::string &varname);
void getErrorMessages(ErrorLogger *errorLogger, const Settings *settings) const OVERRIDE {
CheckClass c(nullptr, settings, errorLogger);
@ -225,7 +225,7 @@ private:
c.pureVirtualFunctionCallInConstructorError(nullptr, std::list<const Token *>(), "f");
c.virtualFunctionCallInConstructorError(nullptr, std::list<const Token *>(), "f");
c.overrideError(nullptr, nullptr);
c.safeClassRefMemberError(nullptr, "UnsafeClass::var");
c.unsafeClassRefMemberError(nullptr, "UnsafeClass::var");
}
static std::string myName() {

View File

@ -222,7 +222,7 @@ private:
TEST_CASE(override1);
TEST_CASE(overrideCVRefQualifiers);
TEST_CASE(safeClassRefMember);
TEST_CASE(unsafeClassRefMember);
}
void checkCopyCtorAndEqOperator(const char code[]) {
@ -7163,7 +7163,7 @@ private:
ASSERT_EQUALS("", errout.str());
}
void checkSafeClassRefMember(const char code[]) {
void checkUnsafeClassRefMember(const char code[]) {
// Clear the error log
errout.str("");
Settings settings;
@ -7177,11 +7177,11 @@ private:
// Check..
CheckClass checkClass(&tokenizer, &settings, this);
checkClass.checkSafeClassRefMember();
checkClass.checkUnsafeClassRefMember();
}
void safeClassRefMember() {
checkSafeClassRefMember("class C { C(const std::string &s) : s(s) {} const std::string &s; };");
void unsafeClassRefMember() {
checkUnsafeClassRefMember("class C { C(const std::string &s) : s(s) {} const std::string &s; };");
ASSERT_EQUALS("[test.cpp:1]: (warning) Unsafe class: The const reference member 'C::s' is initialized by a const reference constructor argument. You need to be careful about lifetime issues.\n", errout.str());
}
};