Skip to content

Commit b9b8e5b

Browse files
committed
Settings: added generic hasLib() and removed posix()
1 parent 6cf3981 commit b9b8e5b

File tree

3 files changed

+7
-14
lines changed

3 files changed

+7
-14
lines changed

lib/checkclass.cpp

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -102,13 +102,6 @@ static bool isVariableCopyNeeded(const Variable &var, Function::Type type)
102102
(var.valueType() && var.valueType()->type >= ValueType::Type::CHAR));
103103
}
104104

105-
static bool isVcl(const Settings *settings)
106-
{
107-
return std::any_of(settings->libraries.cbegin(), settings->libraries.cend(), [](const std::string& library) {
108-
return library == "vcl";
109-
});
110-
}
111-
112105
static bool isVclTypeInit(const Type *type)
113106
{
114107
if (!type)
@@ -141,7 +134,7 @@ void CheckClass::constructors()
141134

142135
const bool printInconclusive = mSettings->certainty.isEnabled(Certainty::inconclusive);
143136
for (const Scope * scope : mSymbolDatabase->classAndStructScopes) {
144-
if (isVcl(mSettings) && isVclTypeInit(scope->definedType))
137+
if (mSettings->hasLib("vcl") && isVclTypeInit(scope->definedType))
145138
continue;
146139

147140
const bool unusedTemplate = Token::simpleMatch(scope->classDef->previous(), ">");

lib/checkmemoryleak.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ CheckMemoryLeak::AllocType CheckMemoryLeak::getAllocationType(const Token *tok2,
116116
return New;
117117
}
118118

119-
if (mSettings_->posix()) {
119+
if (mSettings_->hasLib("posix")) {
120120
if (Token::Match(tok2, "open|openat|creat|mkstemp|mkostemp|socket (")) {
121121
// simple sanity check of function parameters..
122122
// TODO: Make such check for all these functions
@@ -237,7 +237,7 @@ CheckMemoryLeak::AllocType CheckMemoryLeak::getDeallocationType(const Token *tok
237237
if (tok->str() == "realloc" && Token::simpleMatch(vartok->next(), ", 0 )"))
238238
return Malloc;
239239

240-
if (mSettings_->posix()) {
240+
if (mSettings_->hasLib("posix")) {
241241
if (tok->str() == "close")
242242
return Fd;
243243
if (tok->str() == "pclose")
@@ -276,7 +276,7 @@ bool CheckMemoryLeak::isReopenStandardStream(const Token *tok) const
276276

277277
bool CheckMemoryLeak::isOpenDevNull(const Token *tok) const
278278
{
279-
if (mSettings_->posix() && tok->str() == "open" && numberOfArguments(tok) == 2) {
279+
if (mSettings_->hasLib("posix") && tok->str() == "open" && numberOfArguments(tok) == 2) {
280280
const Token* arg = getArguments(tok).at(0);
281281
if (Token::simpleMatch(arg, "\"/dev/null\""))
282282
return true;

lib/settings.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -417,9 +417,9 @@ class CPPCHECKLIB Settings : public cppcheck::Platform {
417417
*/
418418
bool isEnabled(const ValueFlow::Value *value, bool inconclusiveCheck=false) const;
419419

420-
/** Is posix library specified? */
421-
bool posix() const {
422-
return std::find(libraries.cbegin(), libraries.cend(), "posix") != libraries.cend();
420+
/** Is library specified? */
421+
bool hasLib(const std::string &lib) const {
422+
return std::find(libraries.cbegin(), libraries.cend(), lib) != libraries.cend();
423423
}
424424

425425
/** @brief Request termination of checking */

0 commit comments

Comments
 (0)