fixed some CLion inspection warnings (#4688)

* fixed some CLion "Unused global declaration" warnings

* fixed some CLion "Not implemented function" warnings

* fixed some CLion "Unused struct" warnings

* added TODO

* removed unused parameter reported by CLion

* fixed some CLion "Unused macro" warnings

* fixed some CLion "Condition is always true" warnings and a CLion "The value is never used" warning
This commit is contained in:
Oliver Stöneberg 2023-04-28 16:02:41 +02:00 committed by GitHub
parent c249cc9098
commit b3016f01a1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
27 changed files with 21 additions and 122 deletions

View File

@ -120,7 +120,6 @@ static void CppcheckSignalHandler(int signo, siginfo_t * info, void * context)
const Signalmap_t::const_iterator it=listofsignals.find(signo);
const char * const signame = (it==listofsignals.end()) ? "unknown" : it->second.c_str();
bool printCallstack=true; // try to print a callstack?
bool lowMem=false; // was low-memory condition detected? Be careful then! Avoid allocating much more memory then.
bool unexpectedSignal=true; // unexpected indicates program failure
bool terminate=true; // exit process/thread
@ -241,7 +240,6 @@ static void CppcheckSignalHandler(int signo, siginfo_t * info, void * context)
unexpectedSignal=false; // legal usage: interrupt application via CTRL-C
fputs("cppcheck received signal ", output);
fputs(signame, output);
printCallstack=true;
fputs(".\n", output);
break;
case SIGSEGV:
@ -277,11 +275,9 @@ static void CppcheckSignalHandler(int signo, siginfo_t * info, void * context)
fputs(".\n", output);
break;
}
if (printCallstack) {
#ifdef USE_UNIX_BACKTRACE_SUPPORT
print_stacktrace(output, true, -1, lowMem);
#endif
}
if (unexpectedSignal) {
fputs("\nPlease report this to the cppcheck developers!\n", output);
}

View File

@ -71,7 +71,7 @@ ProcessExecutor::~ProcessExecutor()
class PipeWriter : public ErrorLogger {
public:
enum PipeSignal {REPORT_OUT='1',REPORT_ERROR='2', REPORT_VERIFICATION='4', CHILD_END='5'};
enum PipeSignal {REPORT_OUT='1',REPORT_ERROR='2', CHILD_END='5'};
explicit PipeWriter(int pipe) : mWpipe(pipe) {}

View File

@ -36,8 +36,6 @@
#define SETTINGS_WINDOW_MAXIMIZED "Window maximized"
#define SETTINGS_WINDOW_WIDTH "Window width"
#define SETTINGS_WINDOW_HEIGHT "Window height"
#define SETTINGS_LOG_VIEW_WIDTH "Log/View width"
#define SETTINGS_LOG_VIEW_HEIGHT "Log/View height"
#define SETTINGS_MAINWND_SPLITTER_STATE "Mainwindow/Vertical splitter state"
#define SETTINGS_CHECK_DIALOG_WIDTH "Check dialog width"
#define SETTINGS_CHECK_DIALOG_HEIGHT "Check dialog height"
@ -101,7 +99,6 @@
#define SETTINGS_LAST_PROJECT_PATH "Last project path"
#define SETTINGS_LAST_RESULT_PATH "Last result path"
#define SETTINGS_LAST_SOURCE_PATH "Last source path"
#define SETTINGS_LAST_INCLUDE_PATH "Last include path"
#define SETTINGS_LAST_APP_PATH "Last application path"
#define SETTINGS_LAST_ANALYZE_FILES_FILTER "Last analyze files filter"

View File

@ -92,7 +92,6 @@
#include <QVariant>
#include <Qt>
static const QString OnlineHelpURL("https://cppcheck.sourceforge.io/manual.html");
static const QString compile_commands_json("compile_commands.json");
static QString fromNativePath(const QString& p) {

View File

@ -402,9 +402,11 @@ public:
QStringList getCheckUnknownFunctionReturn() const {
return mCheckUnknownFunctionReturn;
}
/*
void setCheckUnknownFunctionReturn(const QStringList &s) {
mCheckUnknownFunctionReturn = s;
}
*/
/** Use Clang parser */
bool clangParser;

View File

@ -347,6 +347,7 @@ void ProjectFileDialog::loadFromProjectFile(const ProjectFile *projectFile)
mUI->mComboBoxPlatform->setCurrentText(projectFile->getPlatform());
setSuppressions(projectFile->getSuppressions());
// TODO
// Human knowledge..
/*
mUI->mListUnknownFunctionReturn->clear();

View File

@ -346,14 +346,6 @@ protected:
*/
void startApplication(QStandardItem *target, int application = -1);
/**
* @brief Helper function to copy filename/full path to the clipboard
*
* @param target Error tree item to open
* @param fullPath Are we copying full path or only filename?
*/
void copyPathToClipboard(QStandardItem *target, bool fullPath);
/**
* @brief Helper function returning the filename/full path of the error tree item \a target.
*

View File

@ -90,7 +90,7 @@ bool TranslationHandler::setLanguage(const QString &code)
failure = true;
} else {
// Make sure there is a translator
if (!mTranslator && !failure)
if (!mTranslator)
mTranslator = new QTranslator(this);
//Load the new language
@ -108,20 +108,21 @@ bool TranslationHandler::setLanguage(const QString &code)
else
translationFile = appPath + "/" + mTranslations[index].mFilename + ".qm";
if (!mTranslator->load(translationFile) && !failure) {
if (!mTranslator->load(translationFile)) {
failure = true;
//If it failed, lets check if the default file exists
if (!QFile::exists(translationFile)) {
error = QObject::tr("Language file %1 not found!");
error = error.arg(translationFile);
failure = true;
}
else {
//If file exists, there's something wrong with it
error = QObject::tr("Failed to load translation for language %1 from file %2");
error = error.arg(mTranslations[index].mName);
error = error.arg(translationFile);
}
}
}
if (failure) {
const QString msg(tr("Failed to change the user interface language:"

View File

@ -64,7 +64,6 @@ static const struct CWE CWE571(571U); // Expression is Always True
static const struct CWE CWE672(672U); // Operation on a Resource after Expiration or Release
static const struct CWE CWE628(628U); // Function Call with Incorrectly Specified Arguments
static const struct CWE CWE683(683U); // Function Call With Incorrect Order of Arguments
static const struct CWE CWE686(686U); // Function Call With Incorrect Argument Type
static const struct CWE CWE704(704U); // Incorrect Type Conversion or Cast
static const struct CWE CWE758(758U); // Reliance on Undefined, Unspecified, or Implementation-Defined Behavior
static const struct CWE CWE768(768U); // Incorrect Short Circuit Evaluation

View File

@ -451,11 +451,6 @@ static std::string getContainerName(const Token *containerToken)
return ret;
}
enum OperandPosition {
Left,
Right
};
static bool isVector(const Token* tok)
{
if (!tok)

View File

@ -133,7 +133,6 @@ public:
private:
std::set<const Token*> mUninitDiags;
Check::FileInfo* getFileInfo() const;
bool isUnsafeFunction(const Scope* scope, int argnr, const Token** tok) const;
void getErrorMessages(ErrorLogger* errorLogger, const Settings* settings) const override
{

View File

@ -32,11 +32,7 @@ enum class Color {
FgGreen = 32,
FgBlue = 34,
FgMagenta = 35,
FgDefault = 39,
BgRed = 41,
BgGreen = 42,
BgBlue = 44,
BgDefault = 49
FgDefault = 39
};
CPPCHECKLIB std::ostream& operator<<(std::ostream& os, const Color& c);

View File

@ -121,10 +121,6 @@ public:
void tooManyConfigsError(const std::string &file, const int numberOfConfigurations);
void purgedConfigurationMessage(const std::string &file, const std::string& configuration);
void dontSimplify() {
mSimplify = false;
}
/** Analyse whole program, run this after all TUs has been scanned.
* This is deprecated and the plan is to remove this when
* .analyzeinfo is good enough.

View File

@ -49,7 +49,7 @@ struct OnExit {
struct ForwardTraversal {
enum class Progress { Continue, Break, Skip };
enum class Terminate { None, Bail, Escape, Modified, Inconclusive, Conditional };
enum class Terminate { None, Bail, Inconclusive };
ForwardTraversal(const ValuePtr<Analyzer>& analyzer, const Settings& settings)
: analyzer(analyzer), settings(settings), actions(Analyzer::Action::None), analyzeOnly(false), analyzeTerminate(false)
{}
@ -333,8 +333,6 @@ struct ForwardTraversal {
enum class Status {
None,
Escaped,
Modified,
Inconclusive,
};

View File

@ -254,7 +254,7 @@ public:
};
struct RangeItemRecordTypeItem {
std::string name;
int templateParameter;
int templateParameter; // TODO: use this
};
std::string startPattern, startPattern2, endPattern, itEndPattern;
std::map<std::string, Function> functions;
@ -407,15 +407,6 @@ public:
return arg ? arg->valid : emptyString;
}
struct InvalidArgValue {
enum class Type {le, lt, eq, ge, gt, range} type;
std::string op1;
std::string op2;
bool isInt() const {
return MathLib::isInt(op1);
}
};
const ArgumentChecks::IteratorInfo *getArgIteratorInfo(const Token *ftok, int argnr) const {
const ArgumentChecks *arg = getarg(ftok, argnr);
return arg && arg->iteratorInfo.it ? &arg->iteratorInfo : nullptr;

View File

@ -80,8 +80,7 @@ public:
* Include file types.
*/
enum HeaderTypes {
NoHeader = 0,
UserHeader,
UserHeader = 1,
SystemHeader
};
@ -169,10 +168,6 @@ public:
static void getErrorMessages(ErrorLogger *errorLogger, const Settings *settings);
void setFile0(const std::string &f) {
mFile0 = f;
}
/**
* dump all directives present in source file
*/

View File

@ -171,8 +171,6 @@ bool conditionIsTrue(const Token* condition, ProgramMemory pm, const Settings* s
*/
ProgramMemory getProgramMemory(const Token* tok, const Token* expr, const ValueFlow::Value& value, const Settings* settings);
ProgramMemory getProgramMemory(const Token *tok, const ProgramMemory::Map& vars);
ValueFlow::Value evaluateLibraryFunction(const std::unordered_map<nonneg int, ValueFlow::Value>& args,
const std::string& returnValue,
const Settings* settings);

View File

@ -388,12 +388,6 @@ struct ReverseTraversal {
}
};
void valueFlowGenericReverse(Token* start, const ValuePtr<Analyzer>& a, const Settings& settings)
{
ReverseTraversal rt{a, settings};
rt.traverse(start);
}
void valueFlowGenericReverse(Token* start, const Token* end, const ValuePtr<Analyzer>& a, const Settings& settings)
{
ReverseTraversal rt{a, settings};

View File

@ -25,7 +25,6 @@ class Token;
template<class T>
class ValuePtr;
void valueFlowGenericReverse(Token* start, const ValuePtr<Analyzer>& a, const Settings& settings);
void valueFlowGenericReverse(Token* start, const Token* end, const ValuePtr<Analyzer>& a, const Settings& settings);
#endif

View File

@ -61,12 +61,6 @@ public:
void fill() {
mFlags = 0xFFFFFFFF;
}
void setEnabledAll(bool enabled) {
if (enabled)
fill();
else
clear();
}
bool isEnabled(T flag) const {
return (mFlags & (1U << (uint32_t)flag)) != 0;
}

View File

@ -4462,13 +4462,6 @@ Scope::Scope(const SymbolDatabase *check_, const Token *classDef_, const Scope *
className = nameTok->str();
}
bool Scope::hasDefaultConstructor() const
{
return numConstructors > 0 && std::any_of(functionList.begin(), functionList.end(), [](const Function& func) {
return func.type == Function::eConstructor && func.argCount() == 0;
});
}
AccessControl Scope::defaultAccess() const
{
switch (type) {

View File

@ -1175,8 +1175,6 @@ public:
functionMap.insert(make_pair(back->tokenDef->str(), back));
}
bool hasDefaultConstructor() const;
AccessControl defaultAccess() const;
/**

View File

@ -2516,10 +2516,6 @@ Token* findTypeEnd(Token* tok)
return tok;
}
const Token* findTypeEnd(const Token* tok) {
return findTypeEnd(const_cast<Token*>(tok));
}
Token* findLambdaEndScope(Token* tok)
{
if (!Token::simpleMatch(tok, "["))

View File

@ -1455,7 +1455,6 @@ public:
};
Token* findTypeEnd(Token* tok);
const Token* findTypeEnd(const Token* tok);
Token* findLambdaEndScope(Token* tok);
const Token* findLambdaEndScope(const Token* tok);

View File

@ -158,13 +158,6 @@ public:
nonneg int sizeOfType(const std::string& type) const;
void simplifyDebug();
/**
* Try to determine if function parameter is passed by value by looking
* at the function declaration.
* @param fpar token for function parameter in the function call
* @return true if the parameter is passed by value. if unsure, false is returned
*/
bool isFunctionParameterPassedByValue(const Token *fpar) const;
/** Simplify assignment where rhs is a block : "x=({123;});" => "{x=123;}" */
void simplifyAssignmentBlock();
@ -554,12 +547,6 @@ private:
*/
void simplifyCPPAttribute();
/**
* Replace strlen(str)
* @return true if any replacement took place, false else
* */
bool simplifyStrlen();
/**
* Convert namespace aliases
*/

View File

@ -39,7 +39,7 @@ void valid_code(boost::function<void(void)> &pf_print_hello)
pf_print_hello = boost::bind(print_hello);
}
void ignoredReturnValue(char * buf)
void ignoredReturnValue()
{
// cppcheck-suppress ignoredReturnValue
boost::math::round(1.5);

View File

@ -55,22 +55,6 @@ public:
};
class SimpleSuppressor : public ErrorLogger {
public:
SimpleSuppressor(Settings &settings, ErrorLogger *next)
: settings(settings), next(next) {}
void reportOut(const std::string &outmsg, Color /*c*/ = Color::Reset) override {
next->reportOut(outmsg);
}
void reportErr(const ErrorMessage &msg) override {
if (!msg.callStack.empty() && !settings.nomsg.isSuppressed(msg))
next->reportErr(msg);
}
private:
Settings &settings;
ErrorLogger *next;
};
class ScopedFile {
public:
ScopedFile(std::string name, const std::string &content, std::string path = "");