Always set ErrorMessage::file0 to ensure that the source file that cppcheck is checking when an error occurs can be identified
Removed unused function and unused includes from preprocessor.h/cpp
This commit is contained in:
parent
560e7d618d
commit
9a6569fde1
|
@ -790,7 +790,7 @@ int CppCheckExecutor::check_internal(CppCheck& cppcheck, int /*argc*/, const cha
|
||||||
"std.cfg should be available in " + cfgfolder + " or the CFGDIR "
|
"std.cfg should be available in " + cfgfolder + " or the CFGDIR "
|
||||||
"should be configured.");
|
"should be configured.");
|
||||||
#endif
|
#endif
|
||||||
ErrorLogger::ErrorMessage errmsg(callstack, Severity::information, msg+" "+details, "failedToLoadCfg", false);
|
ErrorLogger::ErrorMessage errmsg(callstack, emptyString, Severity::information, msg+" "+details, "failedToLoadCfg", false);
|
||||||
reportErr(errmsg);
|
reportErr(errmsg);
|
||||||
return EXIT_FAILURE;
|
return EXIT_FAILURE;
|
||||||
}
|
}
|
||||||
|
@ -863,6 +863,7 @@ int CppCheckExecutor::check_internal(CppCheck& cppcheck, int /*argc*/, const cha
|
||||||
if (settings.isEnabled("missingInclude") && (Preprocessor::missingIncludeFlag || Preprocessor::missingSystemIncludeFlag)) {
|
if (settings.isEnabled("missingInclude") && (Preprocessor::missingIncludeFlag || Preprocessor::missingSystemIncludeFlag)) {
|
||||||
const std::list<ErrorLogger::ErrorMessage::FileLocation> callStack;
|
const std::list<ErrorLogger::ErrorMessage::FileLocation> callStack;
|
||||||
ErrorLogger::ErrorMessage msg(callStack,
|
ErrorLogger::ErrorMessage msg(callStack,
|
||||||
|
emptyString,
|
||||||
Severity::information,
|
Severity::information,
|
||||||
"Cppcheck cannot find all the include files (use --check-config for details)\n"
|
"Cppcheck cannot find all the include files (use --check-config for details)\n"
|
||||||
"Cppcheck cannot find all the include files. Cppcheck can check the code without the "
|
"Cppcheck cannot find all the include files. Cppcheck can check the code without the "
|
||||||
|
|
|
@ -1981,6 +1981,7 @@ void CheckBufferOverrun::analyseWholeProgram(const std::list<Check::FileInfo*> &
|
||||||
ostr << "Array " << it->first << '[' << sz->second << "] accessed at index " << it->second.index << " which is out of bounds";
|
ostr << "Array " << it->first << '[' << sz->second << "] accessed at index " << it->second.index << " which is out of bounds";
|
||||||
|
|
||||||
const ErrorLogger::ErrorMessage errmsg(locationList,
|
const ErrorLogger::ErrorMessage errmsg(locationList,
|
||||||
|
emptyString,
|
||||||
Severity::error,
|
Severity::error,
|
||||||
ostr.str(),
|
ostr.str(),
|
||||||
"arrayIndexOutOfBounds",
|
"arrayIndexOutOfBounds",
|
||||||
|
|
|
@ -252,7 +252,7 @@ void CheckUnusedFunctions::unusedFunctionError(ErrorLogger * const errorLogger,
|
||||||
locationList.push_back(fileLoc);
|
locationList.push_back(fileLoc);
|
||||||
}
|
}
|
||||||
|
|
||||||
const ErrorLogger::ErrorMessage errmsg(locationList, Severity::style, "The function '" + funcname + "' is never used.", "unusedFunction", CWE561, false);
|
const ErrorLogger::ErrorMessage errmsg(locationList, emptyString, Severity::style, "The function '" + funcname + "' is never used.", "unusedFunction", CWE561, false);
|
||||||
if (errorLogger)
|
if (errorLogger)
|
||||||
errorLogger->reportErr(errmsg);
|
errorLogger->reportErr(errmsg);
|
||||||
else
|
else
|
||||||
|
|
|
@ -308,16 +308,17 @@ unsigned int CppCheck::processFile(const std::string& filename, std::istream& fi
|
||||||
loc.setfile(fixedpath);
|
loc.setfile(fixedpath);
|
||||||
} else {
|
} else {
|
||||||
ErrorLogger::ErrorMessage::FileLocation loc2;
|
ErrorLogger::ErrorMessage::FileLocation loc2;
|
||||||
loc2.setfile(Path::toNativeSeparators(filename.c_str()));
|
loc2.setfile(Path::toNativeSeparators(filename));
|
||||||
locationList.push_back(loc2);
|
locationList.push_back(loc2);
|
||||||
loc.setfile(_tokenizer.list.getSourceFilePath());
|
loc.setfile(_tokenizer.list.getSourceFilePath());
|
||||||
}
|
}
|
||||||
locationList.push_back(loc);
|
locationList.push_back(loc);
|
||||||
const ErrorLogger::ErrorMessage errmsg(locationList,
|
ErrorLogger::ErrorMessage errmsg(locationList,
|
||||||
Severity::error,
|
_tokenizer.list.getSourceFilePath(),
|
||||||
e.errorMessage,
|
Severity::error,
|
||||||
e.id,
|
e.errorMessage,
|
||||||
false);
|
e.id,
|
||||||
|
false);
|
||||||
|
|
||||||
reportErr(errmsg);
|
reportErr(errmsg);
|
||||||
}
|
}
|
||||||
|
@ -360,6 +361,7 @@ void CppCheck::internalError(const std::string &filename, const std::string &msg
|
||||||
callstack.push_back(loc1);
|
callstack.push_back(loc1);
|
||||||
|
|
||||||
ErrorLogger::ErrorMessage errmsg(callstack,
|
ErrorLogger::ErrorMessage errmsg(callstack,
|
||||||
|
emptyString,
|
||||||
Severity::information,
|
Severity::information,
|
||||||
fullmsg,
|
fullmsg,
|
||||||
"internalError",
|
"internalError",
|
||||||
|
@ -557,6 +559,7 @@ void CppCheck::tooManyConfigsError(const std::string &file, const std::size_t nu
|
||||||
|
|
||||||
|
|
||||||
ErrorLogger::ErrorMessage errmsg(loclist,
|
ErrorLogger::ErrorMessage errmsg(loclist,
|
||||||
|
emptyString,
|
||||||
Severity::information,
|
Severity::information,
|
||||||
msg.str(),
|
msg.str(),
|
||||||
"toomanyconfigs", CWE398,
|
"toomanyconfigs", CWE398,
|
||||||
|
@ -567,7 +570,6 @@ void CppCheck::tooManyConfigsError(const std::string &file, const std::size_t nu
|
||||||
|
|
||||||
void CppCheck::purgedConfigurationMessage(const std::string &file, const std::string& configuration)
|
void CppCheck::purgedConfigurationMessage(const std::string &file, const std::string& configuration)
|
||||||
{
|
{
|
||||||
|
|
||||||
tooManyConfigs = false;
|
tooManyConfigs = false;
|
||||||
|
|
||||||
if (_settings.isEnabled("information") && file.empty())
|
if (_settings.isEnabled("information") && file.empty())
|
||||||
|
@ -581,6 +583,7 @@ void CppCheck::purgedConfigurationMessage(const std::string &file, const std::st
|
||||||
}
|
}
|
||||||
|
|
||||||
ErrorLogger::ErrorMessage errmsg(loclist,
|
ErrorLogger::ErrorMessage errmsg(loclist,
|
||||||
|
emptyString,
|
||||||
Severity::information,
|
Severity::information,
|
||||||
"The configuration '" + configuration + "' was not checked because its code equals another one.",
|
"The configuration '" + configuration + "' was not checked because its code equals another one.",
|
||||||
"purgedConfiguration",
|
"purgedConfiguration",
|
||||||
|
|
|
@ -48,9 +48,10 @@ ErrorLogger::ErrorMessage::ErrorMessage()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
ErrorLogger::ErrorMessage::ErrorMessage(const std::list<FileLocation> &callStack, Severity::SeverityType severity, const std::string &msg, const std::string &id, bool inconclusive) :
|
ErrorLogger::ErrorMessage::ErrorMessage(const std::list<FileLocation> &callStack, const std::string& file0_, Severity::SeverityType severity, const std::string &msg, const std::string &id, bool inconclusive) :
|
||||||
_callStack(callStack), // locations for this error message
|
_callStack(callStack), // locations for this error message
|
||||||
_id(id), // set the message id
|
_id(id), // set the message id
|
||||||
|
file0(file0_),
|
||||||
_severity(severity), // severity for this error message
|
_severity(severity), // severity for this error message
|
||||||
_cwe(0U),
|
_cwe(0U),
|
||||||
_inconclusive(inconclusive)
|
_inconclusive(inconclusive)
|
||||||
|
@ -61,9 +62,10 @@ ErrorLogger::ErrorMessage::ErrorMessage(const std::list<FileLocation> &callStack
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
ErrorLogger::ErrorMessage::ErrorMessage(const std::list<FileLocation> &callStack, Severity::SeverityType severity, const std::string &msg, const std::string &id, const CWE &cwe, bool inconclusive) :
|
ErrorLogger::ErrorMessage::ErrorMessage(const std::list<FileLocation> &callStack, const std::string& file0_, Severity::SeverityType severity, const std::string &msg, const std::string &id, const CWE &cwe, bool inconclusive) :
|
||||||
_callStack(callStack), // locations for this error message
|
_callStack(callStack), // locations for this error message
|
||||||
_id(id), // set the message id
|
_id(id), // set the message id
|
||||||
|
file0(file0_),
|
||||||
_severity(severity), // severity for this error message
|
_severity(severity), // severity for this error message
|
||||||
_cwe(cwe.id),
|
_cwe(cwe.id),
|
||||||
_inconclusive(inconclusive)
|
_inconclusive(inconclusive)
|
||||||
|
@ -413,7 +415,7 @@ void ErrorLogger::reportUnmatchedSuppressions(const std::list<Suppressions::Supp
|
||||||
|
|
||||||
const std::list<ErrorLogger::ErrorMessage::FileLocation> callStack = make_container< std::list<ErrorLogger::ErrorMessage::FileLocation> > ()
|
const std::list<ErrorLogger::ErrorMessage::FileLocation> callStack = make_container< std::list<ErrorLogger::ErrorMessage::FileLocation> > ()
|
||||||
<< ErrorLogger::ErrorMessage::FileLocation(i->file, i->line);
|
<< ErrorLogger::ErrorMessage::FileLocation(i->file, i->line);
|
||||||
reportErr(ErrorLogger::ErrorMessage(callStack, Severity::information, "Unmatched suppression: " + i->id, "unmatchedSuppression", false));
|
reportErr(ErrorLogger::ErrorMessage(callStack, emptyString, Severity::information, "Unmatched suppression: " + i->id, "unmatchedSuppression", false));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -208,8 +208,8 @@ public:
|
||||||
std::string _file;
|
std::string _file;
|
||||||
};
|
};
|
||||||
|
|
||||||
ErrorMessage(const std::list<FileLocation> &callStack, Severity::SeverityType severity, const std::string &msg, const std::string &id, bool inconclusive);
|
ErrorMessage(const std::list<FileLocation> &callStack, const std::string& file0, Severity::SeverityType severity, const std::string &msg, const std::string &id, bool inconclusive);
|
||||||
ErrorMessage(const std::list<FileLocation> &callStack, Severity::SeverityType severity, const std::string &msg, const std::string &id, const CWE &cwe, bool inconclusive);
|
ErrorMessage(const std::list<FileLocation> &callStack, const std::string& file0, Severity::SeverityType severity, const std::string &msg, const std::string &id, const CWE &cwe, bool inconclusive);
|
||||||
ErrorMessage(const std::list<const Token*>& callstack, const TokenList* list, Severity::SeverityType severity, const std::string& id, const std::string& msg, bool inconclusive);
|
ErrorMessage(const std::list<const Token*>& callstack, const TokenList* list, Severity::SeverityType severity, const std::string& id, const std::string& msg, bool inconclusive);
|
||||||
ErrorMessage(const std::list<const Token*>& callstack, const TokenList* list, Severity::SeverityType severity, const std::string& id, const std::string& msg, const CWE &cwe, bool inconclusive);
|
ErrorMessage(const std::list<const Token*>& callstack, const TokenList* list, Severity::SeverityType severity, const std::string& id, const std::string& msg, const CWE &cwe, bool inconclusive);
|
||||||
ErrorMessage();
|
ErrorMessage();
|
||||||
|
|
|
@ -25,12 +25,10 @@
|
||||||
|
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
#include <fstream>
|
|
||||||
#include <cstdlib>
|
#include <cstdlib>
|
||||||
#include <cctype>
|
#include <cctype>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include <set>
|
#include <set>
|
||||||
#include <stack>
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Remove heading and trailing whitespaces from the input parameter.
|
* Remove heading and trailing whitespaces from the input parameter.
|
||||||
|
@ -69,21 +67,6 @@ Preprocessor::~Preprocessor()
|
||||||
delete it->second;
|
delete it->second;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Preprocessor::writeError(const std::string &fileName, const unsigned int linenr, ErrorLogger *errorLogger, const std::string &errorType, const std::string &errorText)
|
|
||||||
{
|
|
||||||
if (!errorLogger)
|
|
||||||
return;
|
|
||||||
|
|
||||||
std::list<ErrorLogger::ErrorMessage::FileLocation> locationList;
|
|
||||||
ErrorLogger::ErrorMessage::FileLocation loc(fileName, linenr);
|
|
||||||
locationList.push_back(loc);
|
|
||||||
errorLogger->reportErr(ErrorLogger::ErrorMessage(locationList,
|
|
||||||
Severity::error,
|
|
||||||
errorText,
|
|
||||||
errorType,
|
|
||||||
false));
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
static void inlineSuppressions(const simplecpp::TokenList &tokens, Settings &_settings)
|
static void inlineSuppressions(const simplecpp::TokenList &tokens, Settings &_settings)
|
||||||
{
|
{
|
||||||
|
@ -657,6 +640,7 @@ void Preprocessor::error(const std::string &filename, unsigned int linenr, const
|
||||||
locationList.push_back(loc);
|
locationList.push_back(loc);
|
||||||
}
|
}
|
||||||
_errorLogger->reportErr(ErrorLogger::ErrorMessage(locationList,
|
_errorLogger->reportErr(ErrorLogger::ErrorMessage(locationList,
|
||||||
|
file0,
|
||||||
Severity::error,
|
Severity::error,
|
||||||
msg,
|
msg,
|
||||||
"preprocessorErrorDirective",
|
"preprocessorErrorDirective",
|
||||||
|
@ -685,13 +669,12 @@ void Preprocessor::missingInclude(const std::string &filename, unsigned int line
|
||||||
loc.setfile(Path::toNativeSeparators(filename));
|
loc.setfile(Path::toNativeSeparators(filename));
|
||||||
locationList.push_back(loc);
|
locationList.push_back(loc);
|
||||||
}
|
}
|
||||||
ErrorLogger::ErrorMessage errmsg(locationList, Severity::information,
|
ErrorLogger::ErrorMessage errmsg(locationList, file0, Severity::information,
|
||||||
(headerType==SystemHeader) ?
|
(headerType==SystemHeader) ?
|
||||||
"Include file: <" + header + "> not found. Please note: Cppcheck does not need standard library headers to get proper results." :
|
"Include file: <" + header + "> not found. Please note: Cppcheck does not need standard library headers to get proper results." :
|
||||||
"Include file: \"" + header + "\" not found.",
|
"Include file: \"" + header + "\" not found.",
|
||||||
(headerType==SystemHeader) ? "missingIncludeSystem" : "missingInclude",
|
(headerType==SystemHeader) ? "missingIncludeSystem" : "missingInclude",
|
||||||
false);
|
false);
|
||||||
errmsg.file0 = file0;
|
|
||||||
_errorLogger->reportInfo(errmsg);
|
_errorLogger->reportInfo(errmsg);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -763,7 +746,7 @@ void Preprocessor::validateCfgError(const std::string &cfg, const std::string &m
|
||||||
std::list<ErrorLogger::ErrorMessage::FileLocation> locationList;
|
std::list<ErrorLogger::ErrorMessage::FileLocation> locationList;
|
||||||
ErrorLogger::ErrorMessage::FileLocation loc(file0, 1);
|
ErrorLogger::ErrorMessage::FileLocation loc(file0, 1);
|
||||||
locationList.push_back(loc);
|
locationList.push_back(loc);
|
||||||
ErrorLogger::ErrorMessage errmsg(locationList, Severity::information, "Skipping configuration '" + cfg + "' since the value of '" + macro + "' is unknown. Use -D if you want to check it. You can use -U to skip it explicitly.", id, false);
|
ErrorLogger::ErrorMessage errmsg(locationList, file0, Severity::information, "Skipping configuration '" + cfg + "' since the value of '" + macro + "' is unknown. Use -D if you want to check it. You can use -U to skip it explicitly.", id, false);
|
||||||
_errorLogger->reportInfo(errmsg);
|
_errorLogger->reportInfo(errmsg);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -155,16 +155,6 @@ public:
|
||||||
bool validateCfg(const std::string &code, const std::string &cfg);
|
bool validateCfg(const std::string &code, const std::string &cfg);
|
||||||
void validateCfgError(const std::string &cfg, const std::string ¯o);
|
void validateCfgError(const std::string &cfg, const std::string ¯o);
|
||||||
|
|
||||||
/**
|
|
||||||
* report error
|
|
||||||
* @param fileName name of file that the error was found in
|
|
||||||
* @param linenr linenr in file
|
|
||||||
* @param errorLogger Error logger to write error to
|
|
||||||
* @param errorType id string for error
|
|
||||||
* @param errorText Plain text
|
|
||||||
*/
|
|
||||||
static void writeError(const std::string &fileName, const unsigned int linenr, ErrorLogger *errorLogger, const std::string &errorType, const std::string &errorText);
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -82,8 +82,8 @@ static void execute(const Token *expr,
|
||||||
static void bailout(TokenList *tokenlist, ErrorLogger *errorLogger, const Token *tok, const std::string &what)
|
static void bailout(TokenList *tokenlist, ErrorLogger *errorLogger, const Token *tok, const std::string &what)
|
||||||
{
|
{
|
||||||
std::list<ErrorLogger::ErrorMessage::FileLocation> callstack;
|
std::list<ErrorLogger::ErrorMessage::FileLocation> callstack;
|
||||||
callstack.push_back(ErrorLogger::ErrorMessage::FileLocation(tok,tokenlist));
|
callstack.push_back(ErrorLogger::ErrorMessage::FileLocation(tok, tokenlist));
|
||||||
ErrorLogger::ErrorMessage errmsg(callstack, Severity::debug, "ValueFlow bailout: " + what, "valueFlowBailout", false);
|
ErrorLogger::ErrorMessage errmsg(callstack, tokenlist->getSourceFilePath(), Severity::debug, "ValueFlow bailout: " + what, "valueFlowBailout", false);
|
||||||
errorLogger->reportErr(errmsg);
|
errorLogger->reportErr(errmsg);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -111,7 +111,7 @@ private:
|
||||||
|
|
||||||
void ErrorMessageConstruct() const {
|
void ErrorMessageConstruct() const {
|
||||||
std::list<ErrorLogger::ErrorMessage::FileLocation> locs(1, fooCpp5);
|
std::list<ErrorLogger::ErrorMessage::FileLocation> locs(1, fooCpp5);
|
||||||
ErrorMessage msg(locs, Severity::error, "Programming error.", "errorId", false);
|
ErrorMessage msg(locs, emptyString, Severity::error, "Programming error.", "errorId", false);
|
||||||
ASSERT_EQUALS(1, (int)msg._callStack.size());
|
ASSERT_EQUALS(1, (int)msg._callStack.size());
|
||||||
ASSERT_EQUALS("Programming error.", msg.shortMessage());
|
ASSERT_EQUALS("Programming error.", msg.shortMessage());
|
||||||
ASSERT_EQUALS("Programming error.", msg.verboseMessage());
|
ASSERT_EQUALS("Programming error.", msg.verboseMessage());
|
||||||
|
@ -123,7 +123,7 @@ private:
|
||||||
std::list<ErrorLogger::ErrorMessage::FileLocation> locs;
|
std::list<ErrorLogger::ErrorMessage::FileLocation> locs;
|
||||||
locs.push_back(fooCpp5);
|
locs.push_back(fooCpp5);
|
||||||
locs.push_back(barCpp8);
|
locs.push_back(barCpp8);
|
||||||
ErrorMessage msg(locs, Severity::error, "Programming error.", "errorId", false);
|
ErrorMessage msg(locs, emptyString, Severity::error, "Programming error.", "errorId", false);
|
||||||
ASSERT_EQUALS(2, (int)msg._callStack.size());
|
ASSERT_EQUALS(2, (int)msg._callStack.size());
|
||||||
ASSERT_EQUALS("Programming error.", msg.shortMessage());
|
ASSERT_EQUALS("Programming error.", msg.shortMessage());
|
||||||
ASSERT_EQUALS("Programming error.", msg.verboseMessage());
|
ASSERT_EQUALS("Programming error.", msg.verboseMessage());
|
||||||
|
@ -133,7 +133,7 @@ private:
|
||||||
|
|
||||||
void ErrorMessageVerbose() const {
|
void ErrorMessageVerbose() const {
|
||||||
std::list<ErrorLogger::ErrorMessage::FileLocation> locs(1, fooCpp5);
|
std::list<ErrorLogger::ErrorMessage::FileLocation> locs(1, fooCpp5);
|
||||||
ErrorMessage msg(locs, Severity::error, "Programming error.\nVerbose error", "errorId", false);
|
ErrorMessage msg(locs, emptyString, Severity::error, "Programming error.\nVerbose error", "errorId", false);
|
||||||
ASSERT_EQUALS(1, (int)msg._callStack.size());
|
ASSERT_EQUALS(1, (int)msg._callStack.size());
|
||||||
ASSERT_EQUALS("Programming error.", msg.shortMessage());
|
ASSERT_EQUALS("Programming error.", msg.shortMessage());
|
||||||
ASSERT_EQUALS("Verbose error", msg.verboseMessage());
|
ASSERT_EQUALS("Verbose error", msg.verboseMessage());
|
||||||
|
@ -145,7 +145,7 @@ private:
|
||||||
std::list<ErrorLogger::ErrorMessage::FileLocation> locs;
|
std::list<ErrorLogger::ErrorMessage::FileLocation> locs;
|
||||||
locs.push_back(fooCpp5);
|
locs.push_back(fooCpp5);
|
||||||
locs.push_back(barCpp8);
|
locs.push_back(barCpp8);
|
||||||
ErrorMessage msg(locs, Severity::error, "Programming error.\nVerbose error", "errorId", false);
|
ErrorMessage msg(locs, emptyString, Severity::error, "Programming error.\nVerbose error", "errorId", false);
|
||||||
ASSERT_EQUALS(2, (int)msg._callStack.size());
|
ASSERT_EQUALS(2, (int)msg._callStack.size());
|
||||||
ASSERT_EQUALS("Programming error.", msg.shortMessage());
|
ASSERT_EQUALS("Programming error.", msg.shortMessage());
|
||||||
ASSERT_EQUALS("Verbose error", msg.verboseMessage());
|
ASSERT_EQUALS("Verbose error", msg.verboseMessage());
|
||||||
|
@ -155,7 +155,7 @@ private:
|
||||||
|
|
||||||
void CustomFormat() const {
|
void CustomFormat() const {
|
||||||
std::list<ErrorLogger::ErrorMessage::FileLocation> locs(1, fooCpp5);
|
std::list<ErrorLogger::ErrorMessage::FileLocation> locs(1, fooCpp5);
|
||||||
ErrorMessage msg(locs, Severity::error, "Programming error.\nVerbose error", "errorId", false);
|
ErrorMessage msg(locs, emptyString, Severity::error, "Programming error.\nVerbose error", "errorId", false);
|
||||||
ASSERT_EQUALS(1, (int)msg._callStack.size());
|
ASSERT_EQUALS(1, (int)msg._callStack.size());
|
||||||
ASSERT_EQUALS("Programming error.", msg.shortMessage());
|
ASSERT_EQUALS("Programming error.", msg.shortMessage());
|
||||||
ASSERT_EQUALS("Verbose error", msg.verboseMessage());
|
ASSERT_EQUALS("Verbose error", msg.verboseMessage());
|
||||||
|
@ -165,7 +165,7 @@ private:
|
||||||
|
|
||||||
void CustomFormat2() const {
|
void CustomFormat2() const {
|
||||||
std::list<ErrorLogger::ErrorMessage::FileLocation> locs(1, fooCpp5);
|
std::list<ErrorLogger::ErrorMessage::FileLocation> locs(1, fooCpp5);
|
||||||
ErrorMessage msg(locs, Severity::error, "Programming error.\nVerbose error", "errorId", false);
|
ErrorMessage msg(locs, emptyString, Severity::error, "Programming error.\nVerbose error", "errorId", false);
|
||||||
ASSERT_EQUALS(1, (int)msg._callStack.size());
|
ASSERT_EQUALS(1, (int)msg._callStack.size());
|
||||||
ASSERT_EQUALS("Programming error.", msg.shortMessage());
|
ASSERT_EQUALS("Programming error.", msg.shortMessage());
|
||||||
ASSERT_EQUALS("Verbose error", msg.verboseMessage());
|
ASSERT_EQUALS("Verbose error", msg.verboseMessage());
|
||||||
|
@ -178,7 +178,7 @@ private:
|
||||||
std::list<ErrorLogger::ErrorMessage::FileLocation> locs;
|
std::list<ErrorLogger::ErrorMessage::FileLocation> locs;
|
||||||
locs.push_back(fooCpp5);
|
locs.push_back(fooCpp5);
|
||||||
locs.push_back(barCpp8);
|
locs.push_back(barCpp8);
|
||||||
ErrorMessage msg(locs, Severity::error, "Programming error.\nVerbose error", "errorId", false);
|
ErrorMessage msg(locs, emptyString, Severity::error, "Programming error.\nVerbose error", "errorId", false);
|
||||||
ASSERT_EQUALS(2, (int)msg._callStack.size());
|
ASSERT_EQUALS(2, (int)msg._callStack.size());
|
||||||
ASSERT_EQUALS("Programming error.", msg.shortMessage());
|
ASSERT_EQUALS("Programming error.", msg.shortMessage());
|
||||||
ASSERT_EQUALS("Verbose error", msg.verboseMessage());
|
ASSERT_EQUALS("Verbose error", msg.verboseMessage());
|
||||||
|
@ -188,7 +188,7 @@ private:
|
||||||
|
|
||||||
void ToXml() const {
|
void ToXml() const {
|
||||||
std::list<ErrorLogger::ErrorMessage::FileLocation> locs(1, fooCpp5);
|
std::list<ErrorLogger::ErrorMessage::FileLocation> locs(1, fooCpp5);
|
||||||
ErrorMessage msg(locs, Severity::error, "Programming error.\nVerbose error", "errorId", false);
|
ErrorMessage msg(locs, emptyString, Severity::error, "Programming error.\nVerbose error", "errorId", false);
|
||||||
ASSERT_EQUALS("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<results>", ErrorLogger::ErrorMessage::getXMLHeader(1));
|
ASSERT_EQUALS("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<results>", ErrorLogger::ErrorMessage::getXMLHeader(1));
|
||||||
ASSERT_EQUALS("</results>", ErrorLogger::ErrorMessage::getXMLFooter(1));
|
ASSERT_EQUALS("</results>", ErrorLogger::ErrorMessage::getXMLFooter(1));
|
||||||
ASSERT_EQUALS(" <error file=\"foo.cpp\" line=\"5\" id=\"errorId\" severity=\"error\" msg=\"Programming error.\"/>", msg.toXML(false,1));
|
ASSERT_EQUALS(" <error file=\"foo.cpp\" line=\"5\" id=\"errorId\" severity=\"error\" msg=\"Programming error.\"/>", msg.toXML(false,1));
|
||||||
|
@ -198,7 +198,7 @@ private:
|
||||||
std::list<ErrorLogger::ErrorMessage::FileLocation> locs;
|
std::list<ErrorLogger::ErrorMessage::FileLocation> locs;
|
||||||
locs.push_back(fooCpp5);
|
locs.push_back(fooCpp5);
|
||||||
locs.push_back(barCpp8);
|
locs.push_back(barCpp8);
|
||||||
ErrorMessage msg(locs, Severity::error, "Programming error.\nVerbose error", "errorId", false);
|
ErrorMessage msg(locs, emptyString, Severity::error, "Programming error.\nVerbose error", "errorId", false);
|
||||||
ASSERT_EQUALS("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<results>", ErrorLogger::ErrorMessage::getXMLHeader(1));
|
ASSERT_EQUALS("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<results>", ErrorLogger::ErrorMessage::getXMLHeader(1));
|
||||||
ASSERT_EQUALS("</results>", ErrorLogger::ErrorMessage::getXMLFooter(1));
|
ASSERT_EQUALS("</results>", ErrorLogger::ErrorMessage::getXMLFooter(1));
|
||||||
ASSERT_EQUALS(" <error file=\"bar.cpp\" line=\"8\" id=\"errorId\" severity=\"error\" msg=\"Programming error.\"/>", msg.toXML(false,1));
|
ASSERT_EQUALS(" <error file=\"bar.cpp\" line=\"8\" id=\"errorId\" severity=\"error\" msg=\"Programming error.\"/>", msg.toXML(false,1));
|
||||||
|
@ -206,7 +206,7 @@ private:
|
||||||
|
|
||||||
void ToVerboseXml() const {
|
void ToVerboseXml() const {
|
||||||
std::list<ErrorLogger::ErrorMessage::FileLocation> locs(1, fooCpp5);
|
std::list<ErrorLogger::ErrorMessage::FileLocation> locs(1, fooCpp5);
|
||||||
ErrorMessage msg(locs, Severity::error, "Programming error.\nVerbose error", "errorId", false);
|
ErrorMessage msg(locs, emptyString, Severity::error, "Programming error.\nVerbose error", "errorId", false);
|
||||||
ASSERT_EQUALS("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<results>", ErrorLogger::ErrorMessage::getXMLHeader(1));
|
ASSERT_EQUALS("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<results>", ErrorLogger::ErrorMessage::getXMLHeader(1));
|
||||||
ASSERT_EQUALS("</results>", ErrorLogger::ErrorMessage::getXMLFooter(1));
|
ASSERT_EQUALS("</results>", ErrorLogger::ErrorMessage::getXMLFooter(1));
|
||||||
ASSERT_EQUALS(" <error file=\"foo.cpp\" line=\"5\" id=\"errorId\" severity=\"error\" msg=\"Verbose error\"/>", msg.toXML(true,1));
|
ASSERT_EQUALS(" <error file=\"foo.cpp\" line=\"5\" id=\"errorId\" severity=\"error\" msg=\"Verbose error\"/>", msg.toXML(true,1));
|
||||||
|
@ -216,7 +216,7 @@ private:
|
||||||
std::list<ErrorLogger::ErrorMessage::FileLocation> locs;
|
std::list<ErrorLogger::ErrorMessage::FileLocation> locs;
|
||||||
locs.push_back(fooCpp5);
|
locs.push_back(fooCpp5);
|
||||||
locs.push_back(barCpp8);
|
locs.push_back(barCpp8);
|
||||||
ErrorMessage msg(locs, Severity::error, "Programming error.\nVerbose error", "errorId", false);
|
ErrorMessage msg(locs, emptyString, Severity::error, "Programming error.\nVerbose error", "errorId", false);
|
||||||
ASSERT_EQUALS("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<results>", ErrorLogger::ErrorMessage::getXMLHeader(1));
|
ASSERT_EQUALS("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<results>", ErrorLogger::ErrorMessage::getXMLHeader(1));
|
||||||
ASSERT_EQUALS("</results>", ErrorLogger::ErrorMessage::getXMLFooter(1));
|
ASSERT_EQUALS("</results>", ErrorLogger::ErrorMessage::getXMLFooter(1));
|
||||||
ASSERT_EQUALS(" <error file=\"bar.cpp\" line=\"8\" id=\"errorId\" severity=\"error\" msg=\"Verbose error\"/>", msg.toXML(true,1));
|
ASSERT_EQUALS(" <error file=\"bar.cpp\" line=\"8\" id=\"errorId\" severity=\"error\" msg=\"Verbose error\"/>", msg.toXML(true,1));
|
||||||
|
@ -224,7 +224,7 @@ private:
|
||||||
|
|
||||||
void ToXmlV2() const {
|
void ToXmlV2() const {
|
||||||
std::list<ErrorLogger::ErrorMessage::FileLocation> locs(1, fooCpp5);
|
std::list<ErrorLogger::ErrorMessage::FileLocation> locs(1, fooCpp5);
|
||||||
ErrorMessage msg(locs, Severity::error, "Programming error.\nVerbose error", "errorId", false);
|
ErrorMessage msg(locs, emptyString, Severity::error, "Programming error.\nVerbose error", "errorId", false);
|
||||||
std::string header("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<results version=\"2\">\n");
|
std::string header("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<results version=\"2\">\n");
|
||||||
header += " <cppcheck version=\"";
|
header += " <cppcheck version=\"";
|
||||||
header += CppCheck::version();
|
header += CppCheck::version();
|
||||||
|
@ -241,7 +241,7 @@ private:
|
||||||
std::list<ErrorLogger::ErrorMessage::FileLocation> locs;
|
std::list<ErrorLogger::ErrorMessage::FileLocation> locs;
|
||||||
locs.push_back(fooCpp5);
|
locs.push_back(fooCpp5);
|
||||||
locs.push_back(barCpp8);
|
locs.push_back(barCpp8);
|
||||||
ErrorMessage msg(locs, Severity::error, "Programming error.\nVerbose error", "errorId", false);
|
ErrorMessage msg(locs, emptyString, Severity::error, "Programming error.\nVerbose error", "errorId", false);
|
||||||
std::string header("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<results version=\"2\">\n");
|
std::string header("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<results version=\"2\">\n");
|
||||||
header += " <cppcheck version=\"";
|
header += " <cppcheck version=\"";
|
||||||
header += CppCheck::version();
|
header += CppCheck::version();
|
||||||
|
@ -258,7 +258,7 @@ private:
|
||||||
void ToXmlV2Encoding() const {
|
void ToXmlV2Encoding() const {
|
||||||
{
|
{
|
||||||
std::list<ErrorLogger::ErrorMessage::FileLocation> locs;
|
std::list<ErrorLogger::ErrorMessage::FileLocation> locs;
|
||||||
ErrorMessage msg(locs, Severity::error, "Programming error.\nComparing \"\203\" with \"\003\"", "errorId", false);
|
ErrorMessage msg(locs, emptyString, Severity::error, "Programming error.\nComparing \"\203\" with \"\003\"", "errorId", false);
|
||||||
const std::string message(" <error id=\"errorId\" severity=\"error\" msg=\"Programming error.\" verbose=\"Comparing "\\203" with "\\003"\"/>");
|
const std::string message(" <error id=\"errorId\" severity=\"error\" msg=\"Programming error.\" verbose=\"Comparing "\\203" with "\\003"\"/>");
|
||||||
ASSERT_EQUALS(message, msg.toXML(false, 2));
|
ASSERT_EQUALS(message, msg.toXML(false, 2));
|
||||||
}
|
}
|
||||||
|
@ -266,9 +266,9 @@ private:
|
||||||
const char code1[]="äöü";
|
const char code1[]="äöü";
|
||||||
const char code2[]="\x12\x00\x00\x01";
|
const char code2[]="\x12\x00\x00\x01";
|
||||||
std::list<ErrorLogger::ErrorMessage::FileLocation> locs;
|
std::list<ErrorLogger::ErrorMessage::FileLocation> locs;
|
||||||
ErrorMessage msg1(locs, Severity::error, std::string("Programming error.\nReading \"")+code1+"\"", "errorId", false);
|
ErrorMessage msg1(locs, emptyString, Severity::error, std::string("Programming error.\nReading \"")+code1+"\"", "errorId", false);
|
||||||
ASSERT_EQUALS(" <error id=\"errorId\" severity=\"error\" msg=\"Programming error.\" verbose=\"Reading "\\303\\244\\303\\266\\303\\274"\"/>", msg1.toXML(false, 2));
|
ASSERT_EQUALS(" <error id=\"errorId\" severity=\"error\" msg=\"Programming error.\" verbose=\"Reading "\\303\\244\\303\\266\\303\\274"\"/>", msg1.toXML(false, 2));
|
||||||
ErrorMessage msg2(locs, Severity::error, std::string("Programming error.\nReading \"")+code2+"\"", "errorId", false);
|
ErrorMessage msg2(locs, emptyString, Severity::error, std::string("Programming error.\nReading \"")+code2+"\"", "errorId", false);
|
||||||
ASSERT_EQUALS(" <error id=\"errorId\" severity=\"error\" msg=\"Programming error.\" verbose=\"Reading "\\022"\"/>", msg2.toXML(false, 2));
|
ASSERT_EQUALS(" <error id=\"errorId\" severity=\"error\" msg=\"Programming error.\" verbose=\"Reading "\\022"\"/>", msg2.toXML(false, 2));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -278,7 +278,7 @@ private:
|
||||||
std::list<ErrorLogger::ErrorMessage::FileLocation> locs(1, fooCpp5);
|
std::list<ErrorLogger::ErrorMessage::FileLocation> locs(1, fooCpp5);
|
||||||
|
|
||||||
// Inconclusive error message
|
// Inconclusive error message
|
||||||
ErrorMessage msg(locs, Severity::error, "Programming error", "errorId", true);
|
ErrorMessage msg(locs, emptyString, Severity::error, "Programming error", "errorId", true);
|
||||||
|
|
||||||
// Don't save inconclusive messages if the xml version is 1
|
// Don't save inconclusive messages if the xml version is 1
|
||||||
ASSERT_EQUALS("", msg.toXML(false, 1));
|
ASSERT_EQUALS("", msg.toXML(false, 1));
|
||||||
|
@ -293,7 +293,7 @@ private:
|
||||||
void SerializeInconclusiveMessage() const {
|
void SerializeInconclusiveMessage() const {
|
||||||
// Inconclusive error message
|
// Inconclusive error message
|
||||||
std::list<ErrorLogger::ErrorMessage::FileLocation> locs;
|
std::list<ErrorLogger::ErrorMessage::FileLocation> locs;
|
||||||
ErrorMessage msg(locs, Severity::error, "Programming error", "errorId", true);
|
ErrorMessage msg(locs, emptyString, Severity::error, "Programming error", "errorId", true);
|
||||||
ASSERT_EQUALS("7 errorId"
|
ASSERT_EQUALS("7 errorId"
|
||||||
"5 error"
|
"5 error"
|
||||||
"1 0"
|
"1 0"
|
||||||
|
@ -318,7 +318,7 @@ private:
|
||||||
|
|
||||||
void SerializeSanitize() const {
|
void SerializeSanitize() const {
|
||||||
std::list<ErrorLogger::ErrorMessage::FileLocation> locs;
|
std::list<ErrorLogger::ErrorMessage::FileLocation> locs;
|
||||||
ErrorMessage msg(locs, Severity::error, std::string("Illegal character in \"foo\001bar\""), "errorId", false);
|
ErrorMessage msg(locs, emptyString, Severity::error, std::string("Illegal character in \"foo\001bar\""), "errorId", false);
|
||||||
|
|
||||||
ASSERT_EQUALS("7 errorId"
|
ASSERT_EQUALS("7 errorId"
|
||||||
"5 error"
|
"5 error"
|
||||||
|
|
|
@ -61,6 +61,7 @@ public:
|
||||||
ErrorLogger::ErrorMessage::FileLocation loc(msg.location.file(), msg.location.line);
|
ErrorLogger::ErrorMessage::FileLocation loc(msg.location.file(), msg.location.line);
|
||||||
locationList.push_back(loc);
|
locationList.push_back(loc);
|
||||||
errorLogger->reportErr(ErrorLogger::ErrorMessage(locationList,
|
errorLogger->reportErr(ErrorLogger::ErrorMessage(locationList,
|
||||||
|
emptyString,
|
||||||
Severity::error,
|
Severity::error,
|
||||||
msg.msg,
|
msg.msg,
|
||||||
"preprocessorError",
|
"preprocessorError",
|
||||||
|
|
Loading…
Reference in New Issue