Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .clang-tidy
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
---
Checks: '*,-abseil-*,-altera-*,-android-*,-boost-*,-cert-*,-cppcoreguidelines-*,-darwin-*,-fuchsia-*,-google-*,-hicpp-*,-linuxkernel-*,-llvm-*,-llvmlibc-*,-mpi-*,-objc-*,-openmp-*,-zircon-*,google-explicit-constructor,-readability-braces-around-statements,-readability-magic-numbers,-bugprone-macro-parentheses,-readability-isolate-declaration,-readability-function-size,-modernize-use-trailing-return-type,-readability-implicit-bool-conversion,-readability-uppercase-literal-suffix,-modernize-use-auto,-readability-else-after-return,-modernize-use-default-member-init,-readability-redundant-member-init,-modernize-avoid-c-arrays,-modernize-use-equals-default,-readability-container-size-empty,-bugprone-branch-clone,-bugprone-narrowing-conversions,-modernize-raw-string-literal,-readability-convert-member-functions-to-static,-modernize-loop-convert,-readability-const-return-type,-modernize-return-braced-init-list,-performance-inefficient-string-concatenation,-misc-throw-by-value-catch-by-reference,-readability-avoid-const-params-in-decls,-misc-non-private-member-variables-in-classes,-clang-analyzer-*,-bugprone-signed-char-misuse,-misc-no-recursion,-readability-use-anyofallof,-performance-no-automatic-move,-readability-function-cognitive-complexity,-readability-redundant-access-specifiers,-concurrency-mt-unsafe,-bugprone-easily-swappable-parameters,-readability-suspicious-call-argument,-readability-identifier-length,-readability-container-data-pointer,-bugprone-assignment-in-if-condition,-misc-const-correctness,-portability-std-allocator-const,-modernize-deprecated-ios-base-aliases,-bugprone-unchecked-optional-access,-modernize-replace-auto-ptr,-readability-identifier-naming,-portability-simd-intrinsics,-misc-use-anonymous-namespace,cert-err34-c'
Checks: '*,-abseil-*,-altera-*,-android-*,-boost-*,-cert-*,-cppcoreguidelines-*,-darwin-*,-fuchsia-*,-google-*,-hicpp-*,-linuxkernel-*,-llvm-*,-llvmlibc-*,-mpi-*,-objc-*,-openmp-*,-zircon-*,google-explicit-constructor,-readability-braces-around-statements,-readability-magic-numbers,-bugprone-macro-parentheses,-readability-isolate-declaration,-readability-function-size,-modernize-use-trailing-return-type,-readability-implicit-bool-conversion,-readability-uppercase-literal-suffix,-modernize-use-auto,-modernize-use-default-member-init,-readability-redundant-member-init,-modernize-avoid-c-arrays,-modernize-use-equals-default,-readability-container-size-empty,-bugprone-branch-clone,-bugprone-narrowing-conversions,-modernize-raw-string-literal,-readability-convert-member-functions-to-static,-modernize-loop-convert,-readability-const-return-type,-modernize-return-braced-init-list,-performance-inefficient-string-concatenation,-misc-throw-by-value-catch-by-reference,-readability-avoid-const-params-in-decls,-misc-non-private-member-variables-in-classes,-clang-analyzer-*,-bugprone-signed-char-misuse,-misc-no-recursion,-readability-use-anyofallof,-performance-no-automatic-move,-readability-function-cognitive-complexity,-readability-redundant-access-specifiers,-concurrency-mt-unsafe,-bugprone-easily-swappable-parameters,-readability-suspicious-call-argument,-readability-identifier-length,-readability-container-data-pointer,-bugprone-assignment-in-if-condition,-misc-const-correctness,-portability-std-allocator-const,-modernize-deprecated-ios-base-aliases,-bugprone-unchecked-optional-access,-modernize-replace-auto-ptr,-readability-identifier-naming,-portability-simd-intrinsics,-misc-use-anonymous-namespace,cert-err34-c'
WarningsAsErrors: '*'
HeaderFilterRegex: '(cli|gui|lib|oss-fuzz|test|triage)\/[a-z]+\.h'
CheckOptions:
Expand Down
3 changes: 2 additions & 1 deletion cli/cppcheckexecutor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,8 @@ bool CppCheckExecutor::parseFromArgs(Settings &settings, int argc, const char* c
if (!ignored.empty())
std::cout << "cppcheck: Maybe all paths were ignored?" << std::endl;
return false;
} else if (!settings.fileFilters.empty() && settings.project.fileSettings.empty()) {
}
if (!settings.fileFilters.empty() && settings.project.fileSettings.empty()) {
std::map<std::string, std::size_t> newMap;
for (std::map<std::string, std::size_t>::const_iterator i = mFiles.cbegin(); i != mFiles.cend(); ++i)
if (matchglobs(settings.fileFilters, i->first)) {
Expand Down
3 changes: 1 addition & 2 deletions cli/cppcheckexecutorsig.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,7 @@ static bool IsAddressOnStack(const void* ptr)
char a;
if (bStackBelowHeap)
return ptr < &a;
else
return ptr > &a;
return ptr > &a;
}

/* (declare this list here, so it may be used in signal handlers in addition to main())
Expand Down
3 changes: 2 additions & 1 deletion cli/processexecutor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,8 @@ bool ProcessExecutor::checkLoadAverage(size_t nchildren)
if (getloadavg(&sample, 1) != 1) {
// disable load average checking on getloadavg error
return true;
} else if (sample < mSettings.loadAverage) {
}
if (sample < mSettings.loadAverage) {
return true;
}
return false;
Expand Down
6 changes: 2 additions & 4 deletions gui/cppchecklibrarydata.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -514,11 +514,9 @@ QString CppcheckLibraryData::open(QIODevice &file)
break;
}
}
if (xmlReader.hasError()) {
if (xmlReader.hasError())
return xmlReader.errorString();
} else {
return QString();
}
return QString();
}

static void writeContainerFunctions(QXmlStreamWriter &xmlWriter, const QString &name, int extra, const QList<struct CppcheckLibraryData::Container::Function> &functions)
Expand Down
3 changes: 1 addition & 2 deletions gui/filelist.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -99,9 +99,8 @@ QStringList FileList::getFileList() const
names << name;
}
return names;
} else {
return applyExcludeList();
}
return applyExcludeList();
}

void FileList::addExcludeList(const QStringList &paths)
Expand Down
2 changes: 1 addition & 1 deletion gui/mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2002,7 +2002,7 @@ static int getVersion(const QString& nameWithVersion) {
for (const auto c: nameWithVersion) {
if (c == '\n' || c == '\r')
break;
else if (c == ' ') {
if (c == ' ') {
if (ret > 0 && dot == 1 && nameWithVersion.endsWith(" dev"))
return ret * 1000000 + v * 1000 + 500;
dot = ret = v = 0;
Expand Down
5 changes: 1 addition & 4 deletions gui/translationhandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -182,10 +182,7 @@ int TranslationHandler::getLanguageIndexByCode(const QString &code) const
{
int index = -1;
for (int i = 0; i < mTranslations.size(); i++) {
if (mTranslations[i].mCode == code) {
index = i;
break;
} else if (mTranslations[i].mCode == code.left(2)) {
if (mTranslations[i].mCode == code || mTranslations[i].mCode == code.left(2)) {
index = i;
break;
}
Expand Down
4 changes: 2 additions & 2 deletions gui/xmlreport.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,8 @@ int XmlReport::determineVersion(const QString &filename)
if (attribs.hasAttribute(QString(VersionAttribute))) {
const int ver = attribs.value(QString(), VersionAttribute).toString().toInt();
return ver;
} else
return 1;
}
return 1;
}
break;

Expand Down
97 changes: 50 additions & 47 deletions lib/astutils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -80,11 +80,10 @@ static int findArgumentPosRecursive(const Token* tok, const Token* tokToFind, b
if (res == -1)
return -1;
return argn + res;
} else {
if (tokToFind == tok)
found = true;
return 1;
}
if (tokToFind == tok)
found = true;
return 1;
}

static int findArgumentPos(const Token* tok, const Token* tokToFind){
Expand Down Expand Up @@ -142,8 +141,7 @@ nonneg int astCount(const Token* tok, const char* op, int depth)
return 0;
if (tok->str() == op)
return astCount(tok->astOperand1(), op, depth) + astCount(tok->astOperand2(), op, depth);
else
return 1;
return 1;
}

bool astHasToken(const Token* root, const Token * tok)
Expand Down Expand Up @@ -439,16 +437,15 @@ bool isTemporary(bool cpp, const Token* tok, const Library* library, bool unknow
ftok = tok->previous();
if (!ftok)
return false;
if (const Function * f = ftok->function()) {
if (const Function * f = ftok->function())
return !Function::returnsReference(f, true);
} else if (ftok->type()) {
if (ftok->type())
return true;
} else if (library) {
if (library) {
std::string returnType = library->returnValueType(ftok);
return !returnType.empty() && returnType.back() != '&';
} else {
return unknown;
}
return unknown;
}
if (tok->isCast())
return false;
Expand Down Expand Up @@ -621,11 +618,9 @@ const Token* getParentLifetime(bool cpp, const Token* tok, const Library* librar
// Find the first local variable or temporary
auto it = std::find_if(members.crbegin(), members.crend(), [&](const Token* tok2) {
const Variable* var = tok2->variable();
if (var) {
if (var)
return var->isLocal() || var->isArgument();
} else {
return isTemporary(cpp, tok2, library);
}
return isTemporary(cpp, tok2, library);
});
if (it == members.rend())
return tok;
Expand Down Expand Up @@ -688,7 +683,8 @@ std::vector<ValueType> getParentValueTypes(const Token* tok, const Settings* set
if (tok->astParent()->astOperand1()->valueType())
return {*tok->astParent()->astOperand1()->valueType()};
return {};
} else if (Token::Match(tok->astParent(), "(|{|,")) {
}
if (Token::Match(tok->astParent(), "(|{|,")) {
int argn = -1;
const Token* ftok = getTokenArgumentFunction(tok, argn);
const Token* typeTok = nullptr;
Expand All @@ -708,7 +704,8 @@ std::vector<ValueType> getParentValueTypes(const Token* tok, const Settings* set
*parent = nameTok;
}
return result;
} else if (const Type* t = Token::typeOf(ftok, &typeTok)) {
}
if (const Type* t = Token::typeOf(ftok, &typeTok)) {
if (astIsPointer(typeTok))
return {*typeTok->valueType()};
const Scope* scope = t->classScope;
Expand Down Expand Up @@ -790,11 +787,10 @@ static T* getCondTokFromEndImpl(T* endBlock)
T* startBlock = endBlock->link();
if (!Token::simpleMatch(startBlock, "{"))
return nullptr;
if (Token::simpleMatch(startBlock->previous(), ")")) {
if (Token::simpleMatch(startBlock->previous(), ")"))
return getCondTok(startBlock->previous()->link());
} else if (Token::simpleMatch(startBlock->tokAt(-2), "} else {")) {
if (Token::simpleMatch(startBlock->tokAt(-2), "} else {"))
return getCondTokFromEnd(startBlock->tokAt(-2));
}
return nullptr;
}

Expand Down Expand Up @@ -1058,7 +1054,8 @@ bool exprDependsOnThis(const Token* expr, bool onVar, nonneg int depth)
if (classScope && classScope->isClassOrStruct())
return contains(classScope->findAssociatedScopes(), expr->function()->nestedIn);
return false;
} else if (onVar && expr->variable()) {
}
if (onVar && expr->variable()) {
const Variable* var = expr->variable();
return ((var->isPrivate() || var->isPublic() || var->isProtected()) && !var->isStatic());
}
Expand Down Expand Up @@ -1186,7 +1183,8 @@ SmallVector<ReferenceToken> followAllReferences(const Token* tok,
if (var->nameToken() == tok || isStructuredBindingVariable(var)) {
refs_result.push_back({tok, std::move(errors)});
return refs_result;
} else if (var->isReference() || var->isRValueReference()) {
}
if (var->isReference() || var->isRValueReference()) {
const Token * const varDeclEndToken = var->declEndToken();
if (!varDeclEndToken) {
refs_result.push_back({tok, std::move(errors)});
Expand All @@ -1196,7 +1194,8 @@ SmallVector<ReferenceToken> followAllReferences(const Token* tok,
errors.emplace_back(varDeclEndToken, "Passed to reference.");
refs_result.push_back({tok, std::move(errors)});
return refs_result;
} else if (Token::simpleMatch(varDeclEndToken, "=")) {
}
if (Token::simpleMatch(varDeclEndToken, "=")) {
if (astHasToken(varDeclEndToken, tok))
return refs_result;
errors.emplace_back(varDeclEndToken, "Assigned to reference.");
Expand Down Expand Up @@ -1826,7 +1825,7 @@ bool isOppositeCond(bool isNot, bool cpp, const Token * const cond1, const Token

if (op1 == "<" || op1 == "<=")
return (op2 == "==" || op2 == ">" || op2 == ">=") && (rhsValue1.intvalue < rhsValue2.intvalue);
else if (op1 == ">=" || op1 == ">")
if (op1 == ">=" || op1 == ">")
return (op2 == "==" || op2 == "<" || op2 == "<=") && (rhsValue1.intvalue > rhsValue2.intvalue);

return false;
Expand Down Expand Up @@ -1903,9 +1902,9 @@ bool isConstFunctionCall(const Token* ftok, const Library& library)
return true;
}
return false;
} else if (f->argumentList.empty()) {
return f->isConstexpr();
}
if (f->argumentList.empty())
return f->isConstexpr();
} else if (Token::Match(ftok->previous(), ". %name% (") && ftok->previous()->originalName() != "->" &&
astIsSmartPointer(ftok->previous()->astOperand1())) {
return Token::Match(ftok, "get|get_deleter ( )");
Expand Down Expand Up @@ -2040,8 +2039,7 @@ static bool isEscaped(const Token* tok, bool functionsScope, const Library* libr
return true;
if (functionsScope)
return Token::simpleMatch(tok, "throw");
else
return Token::Match(tok, "return|throw");
return Token::Match(tok, "return|throw");
}

static bool isEscapedOrJump(const Token* tok, bool functionsScope, const Library* library)
Expand All @@ -2050,8 +2048,7 @@ static bool isEscapedOrJump(const Token* tok, bool functionsScope, const Library
return true;
if (functionsScope)
return Token::simpleMatch(tok, "throw");
else
return Token::Match(tok, "return|goto|throw|continue|break");
return Token::Match(tok, "return|goto|throw|continue|break");
}

bool isEscapeFunction(const Token* ftok, const Library* library)
Expand Down Expand Up @@ -2093,7 +2090,8 @@ static bool hasNoreturnFunction(const Token* tok, const Library* library, const
if (unknownFunc && !function && library && library->functions.count(library->getFunctionName(ftok)) == 0)
*unknownFunc = ftok;
return false;
} else if (tok->isConstOp()) {
}
if (tok->isConstOp()) {
return hasNoreturnFunction(tok->astOperand1(), library, unknownFunc) || hasNoreturnFunction(tok->astOperand2(), library, unknownFunc);
}

Expand Down Expand Up @@ -2273,8 +2271,7 @@ std::vector<const Variable*> getArgumentVars(const Token* tok, int argnr)
const Variable* argvar = tok->function()->getArgumentVar(argnr);
if (argvar)
return {argvar};
else
return result;
return result;
}
if (tok->variable() || Token::simpleMatch(tok, "{") || Token::Match(tok->previous(), "%type% (|{")) {
const Type* type = Token::typeOf(tok);
Expand Down Expand Up @@ -2526,18 +2523,20 @@ bool isVariableChanged(const Token *tok, int indirect, const Settings *settings,
return true;
const Library::Container::Yield yield = c->getYield(ftok->str());
// If accessing element check if the element is changed
if (contains({Library::Container::Yield::ITEM, Library::Container::Yield::AT_INDEX}, yield)) {
if (contains({Library::Container::Yield::ITEM, Library::Container::Yield::AT_INDEX}, yield))
return isVariableChanged(ftok->next(), indirect, settings, cpp, depth - 1);
} else if (contains({Library::Container::Yield::BUFFER,
Library::Container::Yield::BUFFER_NT,
Library::Container::Yield::START_ITERATOR,
Library::Container::Yield::ITERATOR},
yield)) {

if (contains({Library::Container::Yield::BUFFER,
Library::Container::Yield::BUFFER_NT,
Library::Container::Yield::START_ITERATOR,
Library::Container::Yield::ITERATOR},
yield)) {
return isVariableChanged(ftok->next(), indirect + 1, settings, cpp, depth - 1);
} else if (contains({Library::Container::Yield::SIZE,
Library::Container::Yield::EMPTY,
Library::Container::Yield::END_ITERATOR},
yield)) {
}
if (contains({Library::Container::Yield::SIZE,
Library::Container::Yield::EMPTY,
Library::Container::Yield::END_ITERATOR},
yield)) {
return false;
}
}
Expand Down Expand Up @@ -2789,7 +2788,8 @@ bool isThisChanged(const Token* tok, int indirect, const Settings* settings, boo
Token::Match(tok->tokAt(-3), "this . %name% (")) {
if (tok->previous()->function()) {
return (!tok->previous()->function()->isConst() && !tok->previous()->function()->isStatic());
} else if (!tok->previous()->isKeyword()) {
}
if (!tok->previous()->isKeyword()) {
return true;
}
}
Expand Down Expand Up @@ -3276,17 +3276,20 @@ bool isGlobalData(const Token *expr, bool cpp)
// TODO check if pointer points at local data
globalData = true;
return ChildrenToVisit::none;
} else if (Token::Match(tok, "[*[]") && tok->astOperand1() && tok->astOperand1()->variable()) {
}
if (Token::Match(tok, "[*[]") && tok->astOperand1() && tok->astOperand1()->variable()) {
// TODO check if pointer points at local data
const Variable *lhsvar = tok->astOperand1()->variable();
const ValueType *lhstype = tok->astOperand1()->valueType();
if (lhsvar->isPointer()) {
globalData = true;
return ChildrenToVisit::none;
} else if (lhsvar->isArgument() && lhsvar->isArray()) {
}
if (lhsvar->isArgument() && lhsvar->isArray()) {
globalData = true;
return ChildrenToVisit::none;
} else if (lhsvar->isArgument() && (!lhstype || (lhstype->type <= ValueType::Type::VOID && !lhstype->container))) {
}
if (lhsvar->isArgument() && (!lhstype || (lhstype->type <= ValueType::Type::VOID && !lhstype->container))) {
globalData = true;
return ChildrenToVisit::none;
}
Expand Down
3 changes: 2 additions & 1 deletion lib/checkautovariables.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -555,7 +555,8 @@ void CheckAutoVariables::checkVarLifetimeScope(const Token * start, const Token
isInScope(var->nameToken(), tok->scope())) {
errorReturnReference(tok, lt.errorPath, lt.inconclusive);
break;
} else if (isDeadTemporary(mTokenizer->isCPP(), lt.token, nullptr, &mSettings->library)) {
}
if (isDeadTemporary(mTokenizer->isCPP(), lt.token, nullptr, &mSettings->library)) {
errorReturnTempReference(tok, lt.errorPath, lt.inconclusive);
break;
}
Expand Down
3 changes: 1 addition & 2 deletions lib/checkbufferoverrun.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1074,8 +1074,7 @@ void CheckBufferOverrun::objectIndex()
if (std::any_of(idxValues.cbegin(), idxValues.cend(), [&](const ValueFlow::Value& vidx) {
if (vidx.isImpossible())
return (vidx.intvalue == 0);
else
return (vidx.intvalue != 0);
return (vidx.intvalue != 0);
})) {
objectIndexError(tok, &v, idx->hasKnownIntValue());
}
Expand Down
Loading