Run astyle + minor refactoring
This commit is contained in:
parent
1db36c3b83
commit
0533d7bf9c
2
Makefile
2
Makefile
|
@ -383,7 +383,7 @@ $(SRCDIR)/checkvaarg.o: lib/checkvaarg.cpp lib/cxx11emu.h lib/checkvaarg.h lib/c
|
|||
$(SRCDIR)/cppcheck.o: lib/cppcheck.cpp lib/cxx11emu.h lib/cppcheck.h lib/config.h lib/settings.h lib/library.h lib/mathlib.h lib/standards.h lib/errorlogger.h lib/suppressions.h lib/timer.h lib/check.h lib/token.h lib/valueflow.h lib/tokenize.h lib/tokenlist.h lib/preprocessor.h lib/path.h lib/version.h
|
||||
$(CXX) ${INCLUDE_FOR_LIB} $(CPPFLAGS) $(CFG) $(CXXFLAGS) $(UNDEF_STRICT_ANSI) -c -o $(SRCDIR)/cppcheck.o $(SRCDIR)/cppcheck.cpp
|
||||
|
||||
$(SRCDIR)/errorlogger.o: lib/errorlogger.cpp lib/cxx11emu.h lib/errorlogger.h lib/config.h lib/suppressions.h lib/path.h lib/cppcheck.h lib/settings.h lib/library.h lib/mathlib.h lib/standards.h lib/timer.h lib/check.h lib/token.h lib/valueflow.h lib/tokenize.h lib/tokenlist.h
|
||||
$(SRCDIR)/errorlogger.o: lib/errorlogger.cpp lib/cxx11emu.h lib/errorlogger.h lib/config.h lib/suppressions.h lib/path.h lib/cppcheck.h lib/settings.h lib/library.h lib/mathlib.h lib/standards.h lib/timer.h lib/check.h lib/token.h lib/valueflow.h lib/tokenize.h lib/tokenlist.h lib/utils.h
|
||||
$(CXX) ${INCLUDE_FOR_LIB} $(CPPFLAGS) $(CFG) $(CXXFLAGS) $(UNDEF_STRICT_ANSI) -c -o $(SRCDIR)/errorlogger.o $(SRCDIR)/errorlogger.cpp
|
||||
|
||||
$(SRCDIR)/library.o: lib/library.cpp lib/cxx11emu.h lib/library.h lib/config.h lib/mathlib.h lib/standards.h lib/errorlogger.h lib/suppressions.h lib/path.h lib/tokenlist.h lib/token.h lib/valueflow.h lib/symboldatabase.h lib/astutils.h
|
||||
|
|
|
@ -118,7 +118,7 @@ protected:
|
|||
/** report an error */
|
||||
template<typename T, typename U>
|
||||
void reportError(const Token *tok, const Severity::SeverityType severity, const T id, const U msg, const CWE &cwe, bool inconclusive) {
|
||||
std::list<const Token *> callstack(1, tok);
|
||||
const std::list<const Token *> callstack(1, tok);
|
||||
reportError(callstack, severity, id, msg, cwe, inconclusive);
|
||||
}
|
||||
|
||||
|
@ -131,8 +131,7 @@ protected:
|
|||
/** report an error */
|
||||
template<typename T, typename U>
|
||||
void reportError(const std::list<const Token *> &callstack, Severity::SeverityType severity, const T id, const U msg, const CWE &cwe, bool inconclusive) {
|
||||
ErrorLogger::ErrorMessage errmsg(callstack, _tokenizer?&_tokenizer->list:0, severity, id, msg, cwe, inconclusive);
|
||||
errmsg._cwe = cwe.id;
|
||||
const ErrorLogger::ErrorMessage errmsg(callstack, _tokenizer?&_tokenizer->list:0, severity, id, msg, cwe, inconclusive);
|
||||
if (_errorLogger)
|
||||
_errorLogger->reportErr(errmsg);
|
||||
else
|
||||
|
|
|
@ -272,7 +272,7 @@ void CheckMemoryLeak::memoryLeak(const Token *tok, const std::string &varname, A
|
|||
}
|
||||
//---------------------------------------------------------------------------
|
||||
|
||||
void CheckMemoryLeak::reportErr(const Token *tok, Severity::SeverityType severity, const std::string &id, const std::string &msg, unsigned int cwe) const
|
||||
void CheckMemoryLeak::reportErr(const Token *tok, Severity::SeverityType severity, const std::string &id, const std::string &msg, const CWE &cwe) const
|
||||
{
|
||||
std::list<const Token *> callstack;
|
||||
|
||||
|
@ -282,11 +282,9 @@ void CheckMemoryLeak::reportErr(const Token *tok, Severity::SeverityType severit
|
|||
reportErr(callstack, severity, id, msg, cwe);
|
||||
}
|
||||
|
||||
void CheckMemoryLeak::reportErr(const std::list<const Token *> &callstack, Severity::SeverityType severity, const std::string &id, const std::string &msg, unsigned int cwe) const
|
||||
void CheckMemoryLeak::reportErr(const std::list<const Token *> &callstack, Severity::SeverityType severity, const std::string &id, const std::string &msg, const CWE &cwe) const
|
||||
{
|
||||
ErrorLogger::ErrorMessage errmsg(callstack, tokenizer?&tokenizer->list:0, severity, id, msg, false);
|
||||
errmsg._cwe = cwe;
|
||||
|
||||
const ErrorLogger::ErrorMessage errmsg(callstack, tokenizer?&tokenizer->list:0, severity, id, msg, cwe, false);
|
||||
if (errorLogger)
|
||||
errorLogger->reportErr(errmsg);
|
||||
else
|
||||
|
@ -295,12 +293,12 @@ void CheckMemoryLeak::reportErr(const std::list<const Token *> &callstack, Sever
|
|||
|
||||
void CheckMemoryLeak::memleakError(const Token *tok, const std::string &varname) const
|
||||
{
|
||||
reportErr(tok, Severity::error, "memleak", "Memory leak: " + varname, 401U);
|
||||
reportErr(tok, Severity::error, "memleak", "Memory leak: " + varname, CWE(401U));
|
||||
}
|
||||
|
||||
void CheckMemoryLeak::memleakUponReallocFailureError(const Token *tok, const std::string &varname) const
|
||||
{
|
||||
reportErr(tok, Severity::error, "memleakOnRealloc", "Common realloc mistake: \'" + varname + "\' nulled but not freed upon failure", 401U);
|
||||
reportErr(tok, Severity::error, "memleakOnRealloc", "Common realloc mistake: \'" + varname + "\' nulled but not freed upon failure", CWE(401U));
|
||||
}
|
||||
|
||||
void CheckMemoryLeak::resourceLeakError(const Token *tok, const std::string &varname) const
|
||||
|
@ -308,27 +306,27 @@ void CheckMemoryLeak::resourceLeakError(const Token *tok, const std::string &var
|
|||
std::string errmsg("Resource leak");
|
||||
if (!varname.empty())
|
||||
errmsg += ": " + varname;
|
||||
reportErr(tok, Severity::error, "resourceLeak", errmsg, 775U);
|
||||
reportErr(tok, Severity::error, "resourceLeak", errmsg, CWE(775U));
|
||||
}
|
||||
|
||||
void CheckMemoryLeak::deallocDeallocError(const Token *tok, const std::string &varname) const
|
||||
{
|
||||
reportErr(tok, Severity::error, "deallocDealloc", "Deallocating a deallocated pointer: " + varname, 415U);
|
||||
reportErr(tok, Severity::error, "deallocDealloc", "Deallocating a deallocated pointer: " + varname, CWE(415U));
|
||||
}
|
||||
|
||||
void CheckMemoryLeak::deallocuseError(const Token *tok, const std::string &varname) const
|
||||
{
|
||||
reportErr(tok, Severity::error, "deallocuse", "Dereferencing '" + varname + "' after it is deallocated / released", 416U);
|
||||
reportErr(tok, Severity::error, "deallocuse", "Dereferencing '" + varname + "' after it is deallocated / released", CWE(416U));
|
||||
}
|
||||
|
||||
void CheckMemoryLeak::mismatchSizeError(const Token *tok, const std::string &sz) const
|
||||
{
|
||||
reportErr(tok, Severity::error, "mismatchSize", "The allocated size " + sz + " is not a multiple of the underlying type's size.", 131U);
|
||||
reportErr(tok, Severity::error, "mismatchSize", "The allocated size " + sz + " is not a multiple of the underlying type's size.", CWE(131U));
|
||||
}
|
||||
|
||||
void CheckMemoryLeak::mismatchAllocDealloc(const std::list<const Token *> &callstack, const std::string &varname) const
|
||||
{
|
||||
reportErr(callstack, Severity::error, "mismatchAllocDealloc", "Mismatching allocation and deallocation: " + varname, 762U);
|
||||
reportErr(callstack, Severity::error, "mismatchAllocDealloc", "Mismatching allocation and deallocation: " + varname, CWE(762U));
|
||||
}
|
||||
|
||||
CheckMemoryLeak::AllocType CheckMemoryLeak::functionReturnType(const Function* func, std::list<const Function*> *callstack) const
|
||||
|
|
|
@ -75,7 +75,7 @@ private:
|
|||
* @param msg text
|
||||
* @param cwe cwe number
|
||||
*/
|
||||
void reportErr(const Token *location, Severity::SeverityType severity, const std::string &id, const std::string &msg, unsigned int cwe) const;
|
||||
void reportErr(const Token *location, Severity::SeverityType severity, const std::string &id, const std::string &msg, const CWE &cwe) const;
|
||||
|
||||
/**
|
||||
* Report error. Similar with the function Check::reportError
|
||||
|
@ -85,7 +85,7 @@ private:
|
|||
* @param msg text
|
||||
* @param cwe cwe number
|
||||
*/
|
||||
void reportErr(const std::list<const Token *> &callstack, Severity::SeverityType severity, const std::string &id, const std::string &msg, unsigned int cwe) const;
|
||||
void reportErr(const std::list<const Token *> &callstack, Severity::SeverityType severity, const std::string &id, const std::string &msg, const CWE &cwe) const;
|
||||
|
||||
public:
|
||||
CheckMemoryLeak(const Tokenizer *t, ErrorLogger *e, const Settings *s)
|
||||
|
|
|
@ -21,6 +21,7 @@
|
|||
#include "cppcheck.h"
|
||||
#include "tokenlist.h"
|
||||
#include "token.h"
|
||||
#include "utils.h"
|
||||
|
||||
#include <tinyxml2.h>
|
||||
|
||||
|
@ -136,7 +137,7 @@ std::string ErrorLogger::ErrorMessage::serialize() const
|
|||
std::ostringstream oss;
|
||||
oss << _id.length() << " " << _id;
|
||||
oss << Severity::toString(_severity).length() << " " << Severity::toString(_severity);
|
||||
oss << MathLib::toString(_cwe).length() << " " << MathLib::toString(_cwe);
|
||||
oss << MathLib::toString(_cwe.id).length() << " " << MathLib::toString(_cwe.id);
|
||||
if (_inconclusive) {
|
||||
const std::string inconclusive("inconclusive");
|
||||
oss << inconclusive.length() << " " << inconclusive;
|
||||
|
@ -193,7 +194,7 @@ bool ErrorLogger::ErrorMessage::deserialize(const std::string &data)
|
|||
_id = results[0];
|
||||
_severity = Severity::fromString(results[1]);
|
||||
std::istringstream scwe(results[2]);
|
||||
scwe >> _cwe;
|
||||
scwe >> _cwe.id;
|
||||
_shortMessage = results[3];
|
||||
_verboseMessage = results[4];
|
||||
|
||||
|
@ -209,7 +210,7 @@ bool ErrorLogger::ErrorMessage::deserialize(const std::string &data)
|
|||
iss.get();
|
||||
std::string temp;
|
||||
for (unsigned int i = 0; i < len && iss.good(); ++i) {
|
||||
char c = static_cast<char>(iss.get());
|
||||
const char c = static_cast<char>(iss.get());
|
||||
temp.append(1, c);
|
||||
}
|
||||
|
||||
|
@ -311,8 +312,8 @@ std::string ErrorLogger::ErrorMessage::toXML(bool verbose, int version) const
|
|||
printer.PushAttribute("severity", Severity::toString(_severity).c_str());
|
||||
printer.PushAttribute("msg", fixInvalidChars(_shortMessage).c_str());
|
||||
printer.PushAttribute("verbose", fixInvalidChars(_verboseMessage).c_str());
|
||||
if (_cwe)
|
||||
printer.PushAttribute("cwe", _cwe);
|
||||
if (_cwe.id)
|
||||
printer.PushAttribute("cwe", _cwe.id);
|
||||
if (_inconclusive)
|
||||
printer.PushAttribute("inconclusive", "true");
|
||||
|
||||
|
@ -410,8 +411,8 @@ void ErrorLogger::reportUnmatchedSuppressions(const std::list<Suppressions::Supp
|
|||
if (suppressed)
|
||||
continue;
|
||||
|
||||
std::list<ErrorLogger::ErrorMessage::FileLocation> callStack;
|
||||
callStack.push_back(ErrorLogger::ErrorMessage::FileLocation(i->file, i->line));
|
||||
const std::list<ErrorLogger::ErrorMessage::FileLocation> callStack = make_container< std::list<ErrorLogger::ErrorMessage::FileLocation> > ()
|
||||
<< ErrorLogger::ErrorMessage::FileLocation(i->file, i->line);
|
||||
reportErr(ErrorLogger::ErrorMessage(callStack, Severity::information, "Unmatched suppression: " + i->id, "unmatchedSuppression", false));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -27,6 +27,10 @@
|
|||
#include <list>
|
||||
#include <string>
|
||||
|
||||
/**
|
||||
* CWE id (Common Weakness Enumeration)
|
||||
* See https://cwe.mitre.org/ for further reference.
|
||||
* */
|
||||
struct CWE {
|
||||
explicit CWE(unsigned short ID) : id(ID) {}
|
||||
unsigned short id;
|
||||
|
@ -239,7 +243,7 @@ public:
|
|||
std::string file0;
|
||||
|
||||
Severity::SeverityType _severity;
|
||||
unsigned int _cwe;
|
||||
CWE _cwe;
|
||||
bool _inconclusive;
|
||||
|
||||
/** set short and verbose messages */
|
||||
|
|
Loading…
Reference in New Issue