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: 2 additions & 0 deletions gui/applicationlist.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,7 @@ bool ApplicationList::checkAndAddApplication(const QString& appPath, const QStri
return false;
}

#ifdef _WIN32
bool ApplicationList::findDefaultWindowsEditor()
{
bool foundOne = false;
Expand Down Expand Up @@ -264,3 +265,4 @@ bool ApplicationList::findDefaultWindowsEditor()

return foundOne;
}
#endif
2 changes: 2 additions & 0 deletions gui/applicationlist.h
Original file line number Diff line number Diff line change
Expand Up @@ -108,11 +108,13 @@ class ApplicationList : public QObject {
*/
void clear();

#ifdef _WIN32
/**
* @brief Find editor used by default in Windows.
* Check if Notepad++ is installed and use it. If not, use Notepad.
*/
bool findDefaultWindowsEditor();
#endif

private:

Expand Down
2 changes: 1 addition & 1 deletion gui/mainwindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,7 @@ protected slots:
void setLanguage(const QString &code);

/** @brief Event coming when application is about to close. */
virtual void closeEvent(QCloseEvent *event);
void closeEvent(QCloseEvent *event) override;

/**
* @brief Helper function to toggle all show error menu items
Expand Down
6 changes: 3 additions & 3 deletions gui/resultstree.h
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ class ResultsTree : public QTreeView {
*/
ShowTypes mShowSeverities;

virtual void keyPressEvent(QKeyEvent *event);
void keyPressEvent(QKeyEvent *event) override;

signals:
/**
Expand Down Expand Up @@ -294,7 +294,7 @@ protected slots:
* @param current Model index to specify new selected item.
* @param previous Model index to specify previous selected item.
*/
virtual void currentChanged(const QModelIndex &current, const QModelIndex &previous);
void currentChanged(const QModelIndex &current, const QModelIndex &previous) override;

protected:

Expand Down Expand Up @@ -365,7 +365,7 @@ protected slots:
*
* @param e Event
*/
void contextMenuEvent(QContextMenuEvent * e);
void contextMenuEvent(QContextMenuEvent * e) override;

/**
* @brief Add a new error item beneath a file or a backtrace item beneath an error
Expand Down
8 changes: 0 additions & 8 deletions lib/astutils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3270,14 +3270,6 @@ bool FwdAnalysis::unusedValue(const Token *expr, const Token *startToken, const
return (result.type == FwdAnalysis::Result::Type::NONE || result.type == FwdAnalysis::Result::Type::RETURN) && !possiblyAliased(expr, startToken);
}

std::vector<FwdAnalysis::KnownAndToken> FwdAnalysis::valueFlow(const Token *expr, const Token *startToken, const Token *endToken)
{
mWhat = What::ValueFlow;
mValueFlowKnown = true;
check(expr, startToken, endToken);
return mValueFlow;
}

bool FwdAnalysis::possiblyAliased(const Token *expr, const Token *startToken) const
{
if (expr->isUnaryOp("*"))
Expand Down
2 changes: 0 additions & 2 deletions lib/astutils.h
Original file line number Diff line number Diff line change
Expand Up @@ -363,8 +363,6 @@ class FwdAnalysis {
const Token *token;
};

std::vector<KnownAndToken> valueFlow(const Token *expr, const Token *startToken, const Token *endToken);
Comment thread
danmar marked this conversation as resolved.

/** Is there some possible alias for given expression */
bool possiblyAliased(const Token *expr, const Token *startToken) const;

Expand Down
51 changes: 0 additions & 51 deletions lib/checkmemoryleak.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -408,57 +408,6 @@ CheckMemoryLeak::AllocType CheckMemoryLeak::functionReturnType(const Function* f
}


const char *CheckMemoryLeak::functionArgAlloc(const Function *func, nonneg int targetpar, AllocType &allocType) const
Comment thread
danmar marked this conversation as resolved.
{
allocType = No;

if (!func || !func->functionScope)
return "";

if (!Token::simpleMatch(func->retDef, "void"))
return "";

std::list<Variable>::const_iterator arg = func->argumentList.begin();
for (; arg != func->argumentList.end(); ++arg) {
if (arg->index() == targetpar-1)
break;
}
if (arg == func->argumentList.end())
return "";

// Is **
if (!arg->isPointer())
return "";
const Token* tok = arg->typeEndToken();
tok = tok->previous();
if (tok->str() != "*")
return "";

// Check if pointer is allocated.
bool realloc = false;
for (tok = func->functionScope->bodyStart; tok && tok != func->functionScope->bodyEnd; tok = tok->next()) {
if (tok->varId() == arg->declarationId()) {
if (Token::Match(tok->tokAt(-3), "free ( * %name% )")) {
realloc = true;
allocType = No;
} else if (Token::Match(tok->previous(), "* %name% =")) {
allocType = getAllocationType(tok->tokAt(2), arg->declarationId());
if (allocType != No) {
if (realloc)
return "realloc";
return "alloc";
}
} else {
// unhandled variable usage: bailout
return "";
}
}
}

return "";
}


static bool notvar(const Token *tok, nonneg int varid)
{
if (!tok)
Expand Down
3 changes: 0 additions & 3 deletions lib/checkmemoryleak.h
Original file line number Diff line number Diff line change
Expand Up @@ -145,9 +145,6 @@ class CPPCHECKLIB CheckMemoryLeak {

/** What type of allocated memory does the given function return? */
AllocType functionReturnType(const Function* func, std::list<const Function*> *callstack = nullptr) const;

/** Function allocates pointed-to argument (a la asprintf)? */
const char *functionArgAlloc(const Function *func, nonneg int targetpar, AllocType &allocType) const;
};

/// @}
Expand Down
25 changes: 0 additions & 25 deletions lib/checkstl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2381,31 +2381,6 @@ void CheckStl::dereferenceInvalidIteratorError(const Token* deref, const std::st
"Possible dereference of an invalid iterator: $symbol. Make sure to check that the iterator is valid before dereferencing it - not after.", CWE825, Certainty::normal);
}


void CheckStl::readingEmptyStlContainer2()
Comment thread
danmar marked this conversation as resolved.
{
for (const Scope *function : mTokenizer->getSymbolDatabase()->functionScopes) {
for (const Token *tok = function->bodyStart; tok != function->bodyEnd; tok = tok->next()) {
if (!tok->isName() || !tok->valueType())
continue;
const Library::Container *container = tok->valueType()->container;
if (!container)
continue;
const ValueFlow::Value *value = tok->getContainerSizeValue(0);
if (!value)
continue;
if (value->isInconclusive() && !mSettings->certainty.isEnabled(Certainty::inconclusive))
continue;
if (!value->errorSeverity() && !mSettings->severity.isEnabled(Severity::warning))
continue;
if (Token::Match(tok, "%name% . %name% (")) {
if (container->getYield(tok->strAt(2)) == Library::Container::Yield::ITEM)
readingEmptyStlContainerError(tok,value);
}
}
}
}

void CheckStl::readingEmptyStlContainerError(const Token *tok, const ValueFlow::Value *value)
{
const std::string varname = tok ? tok->str() : std::string("var");
Expand Down
3 changes: 0 additions & 3 deletions lib/checkstl.h
Original file line number Diff line number Diff line change
Expand Up @@ -178,9 +178,6 @@ class CPPCHECKLIB CheckStl : public Check {
*/
void dereferenceErasedError(const Token* erased, const Token* deref, const std::string& itername, bool inconclusive);

/** @brief Reading from empty stl container (using valueflow) */
void readingEmptyStlContainer2();

/** @brief Look for loops that can replaced with std algorithms */
void useStlAlgorithm();

Expand Down
10 changes: 0 additions & 10 deletions lib/importproject.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,16 +76,6 @@ void ImportProject::ignoreOtherConfigs(const std::string &cfg)
}
}

void ImportProject::ignoreOtherPlatforms(cppcheck::Platform::PlatformType platformType)
{
for (std::list<FileSettings>::iterator it = fileSettings.begin(); it != fileSettings.end();) {
if (it->platformType != cppcheck::Platform::Unspecified && it->platformType != platformType)
fileSettings.erase(it++);
else
++it;
}
}

void ImportProject::FileSettings::setDefines(std::string defs)
{
while (defs.find(";%(") != std::string::npos) {
Expand Down
1 change: 0 additions & 1 deletion lib/importproject.h
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,6 @@ class CPPCHECKLIB ImportProject {

void ignorePaths(const std::vector<std::string> &ipaths);
void ignoreOtherConfigs(const std::string &cfg);
void ignoreOtherPlatforms(cppcheck::Platform::PlatformType platformType);
Comment thread
danmar marked this conversation as resolved.

Type import(const std::string &filename, Settings *settings=nullptr);
protected:
Expand Down
30 changes: 0 additions & 30 deletions lib/preprocessor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -559,36 +559,6 @@ void Preprocessor::preprocess(std::istream &istr, std::map<std::string, std::str
}
}

std::string Preprocessor::removeSpaceNearNL(const std::string &str)
{
std::string tmp;
char prev = '\n'; // treat start of file as newline
for (std::size_t i = 0; i < str.size(); i++) {
if (str[i] == ' ' &&
(prev == '\n' ||
i + 1 >= str.size() || // treat end of file as newline
str[i+1] == '\n'
)
) {
// Ignore space that has new line in either side of it
} else {
tmp.append(1, str[i]);
prev = str[i];
}
}

return tmp;
}

void Preprocessor::preprocessWhitespaces(std::string &processedFile)
{
// Replace all tabs with spaces..
std::replace(processedFile.begin(), processedFile.end(), '\t', ' ');

// Remove space characters that are after or before new line character
processedFile = removeSpaceNearNL(processedFile);
}

void Preprocessor::preprocess(std::istream &srcCodeStream, std::string &processedFile, std::list<std::string> &resultConfigurations, const std::string &filename, const std::list<std::string> &includePaths)
{
(void)includePaths;
Expand Down
14 changes: 0 additions & 14 deletions lib/preprocessor.h
Original file line number Diff line number Diff line change
Expand Up @@ -154,12 +154,6 @@ class CPPCHECKLIB Preprocessor {
*/
std::string getcode(const std::string &filedata, const std::string &cfg, const std::string &filename);

/**
* preprocess all whitespaces
* @param processedFile The data to be processed
*/
static void preprocessWhitespaces(std::string &processedFile);
Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The usage was removed in 3432257 - leftover code from removed feature so it can be deleted.


/**
* make sure empty configuration macros are not used in code. the given code must be a single configuration
* @param cfg configuration
Expand All @@ -184,14 +178,6 @@ class CPPCHECKLIB Preprocessor {

static void simplifyPragmaAsmPrivate(simplecpp::TokenList *tokenList);

/**
* Remove space that has new line character on left or right side of it.
*
* @param str The string to be converted
* @return The string where space characters have been removed.
*/
static std::string removeSpaceNearNL(const std::string &str);

public:


Expand Down
12 changes: 1 addition & 11 deletions lib/symboldatabase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1840,6 +1840,7 @@ void SymbolDatabase::validate() const
if (mSettings->debugwarnings) {
validateExecutableScopes();
}
// TODO
//validateVariables();
}

Expand Down Expand Up @@ -5329,17 +5330,6 @@ const Scope *SymbolDatabase::findScopeByName(const std::string& name) const

//---------------------------------------------------------------------------

Scope *Scope::findInNestedList(const std::string & name)
{
for (Scope *scope: nestedList) {
if (scope->className == name)
return scope;
}
return nullptr;
}

//---------------------------------------------------------------------------

const Scope *Scope::findRecordInNestedList(const std::string & name) const
{
for (const Scope* scope: nestedList) {
Expand Down
6 changes: 0 additions & 6 deletions lib/symboldatabase.h
Original file line number Diff line number Diff line change
Expand Up @@ -1128,12 +1128,6 @@ class CPPCHECKLIB Scope {
*/
const Function *findFunction(const Token *tok, bool requireConst=false) const;

/**
* @brief find if name is in nested list
* @param name name of nested scope
*/
Scope *findInNestedList(const std::string & name);

const Scope *findRecordInNestedList(const std::string & name) const;
Scope *findRecordInNestedList(const std::string & name) {
return const_cast<Scope *>(const_cast<const Scope *>(this)->findRecordInNestedList(name));
Expand Down
40 changes: 0 additions & 40 deletions lib/token.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1915,46 +1915,6 @@ const Token *Token::getValueTokenMaxStrLength() const
return ret;
}

static const Scope *getfunctionscope(const Scope *s)
{
while (s && s->type != Scope::eFunction)
s = s->nestedIn;
return s;
}

const Token *Token::getValueTokenDeadPointer() const
{
const Scope * const functionscope = getfunctionscope(this->scope());

std::list<ValueFlow::Value>::const_iterator it;
for (it = values().begin(); it != values().end(); ++it) {
// Is this a pointer alias?
if (!it->isTokValue() || (it->tokvalue && it->tokvalue->str() != "&"))
continue;
// Get variable
const Token *vartok = it->tokvalue->astOperand1();
if (!vartok || !vartok->isName() || !vartok->variable())
continue;
const Variable * const var = vartok->variable();
if (var->isStatic() || var->isReference())
continue;
if (!var->scope())
return nullptr; // #6804
if (var->scope()->type == Scope::eUnion && var->scope()->nestedIn == this->scope())
continue;
// variable must be in same function (not in subfunction)
if (functionscope != getfunctionscope(var->scope()))
continue;
// Is variable defined in this scope or upper scope?
const Scope *s = this->scope();
while ((s != nullptr) && (s != var->scope()))
s = s->nestedIn;
if (!s)
return it->tokvalue;
}
return nullptr;
}

static bool isAdjacent(const ValueFlow::Value& x, const ValueFlow::Value& y)
{
if (x.bound != ValueFlow::Value::Bound::Point && x.bound == y.bound)
Expand Down
4 changes: 1 addition & 3 deletions lib/token.h
Original file line number Diff line number Diff line change
Expand Up @@ -863,7 +863,7 @@ class CPPCHECKLIB Token {
void printOut(const char *title, const std::vector<std::string> &fileNames) const;

/**
* print out tokens
* print out tokens - used for debugging
*/
void printLines(int lines=5) const;

Expand Down Expand Up @@ -1171,8 +1171,6 @@ class CPPCHECKLIB Token {
const Token *getValueTokenMaxStrLength() const;
const Token *getValueTokenMinStrSize(const Settings *settings) const;

const Token *getValueTokenDeadPointer() const;
Comment thread
danmar marked this conversation as resolved.

/** Add token value. Return true if value is added. */
bool addValue(const ValueFlow::Value &value);

Expand Down
Loading