Fixed #2373 (Using XML2 in --errorlist output)
This commit is contained in:
parent
fd27be2440
commit
38e7209d26
|
@ -347,6 +347,7 @@ bool CmdLineParser::ParseFromArgs(int argc, const char* const argv[])
|
||||||
{
|
{
|
||||||
//_cppcheck->getErrorMessages();
|
//_cppcheck->getErrorMessages();
|
||||||
_showErrorMessages = true;
|
_showErrorMessages = true;
|
||||||
|
_settings->_xml = true;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -52,7 +52,7 @@ bool CppCheckExecutor::parseFromArgs(CppCheck *cppcheck, int argc, const char* c
|
||||||
if (parser.GetShowErrorMessages())
|
if (parser.GetShowErrorMessages())
|
||||||
{
|
{
|
||||||
cppcheck->getErrorMessages();
|
cppcheck->getErrorMessages();
|
||||||
return true;
|
std::exit(0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -95,7 +95,7 @@ public:
|
||||||
virtual void runSimplifiedChecks(const Tokenizer *tokenizer, const Settings *settings, ErrorLogger *errorLogger) = 0;
|
virtual void runSimplifiedChecks(const Tokenizer *tokenizer, const Settings *settings, ErrorLogger *errorLogger) = 0;
|
||||||
|
|
||||||
/** get error messages */
|
/** get error messages */
|
||||||
virtual void getErrorMessages() = 0;
|
virtual void getErrorMessages(ErrorLogger *errorLogger, const Settings *settings) = 0;
|
||||||
|
|
||||||
/** class name, used to generate documentation */
|
/** class name, used to generate documentation */
|
||||||
virtual std::string name() const = 0;
|
virtual std::string name() const = 0;
|
||||||
|
|
|
@ -87,14 +87,15 @@ private:
|
||||||
void errorReturnAutocstr(const Token *tok);
|
void errorReturnAutocstr(const Token *tok);
|
||||||
void errorReturnTempPointer(const Token *tok);
|
void errorReturnTempPointer(const Token *tok);
|
||||||
|
|
||||||
void getErrorMessages()
|
void getErrorMessages(ErrorLogger *errorLogger, const Settings *settings)
|
||||||
{
|
{
|
||||||
errorAutoVariableAssignment(0);
|
CheckAutoVariables c(0,settings,errorLogger);
|
||||||
errorReturnPointerToLocalArray(0);
|
c.errorAutoVariableAssignment(0);
|
||||||
errorReturnReference(0);
|
c.errorReturnPointerToLocalArray(0);
|
||||||
errorReturnTempReference(0);
|
c.errorReturnReference(0);
|
||||||
errorReturnAutocstr(0);
|
c.errorReturnTempReference(0);
|
||||||
errorReturnTempPointer(0);
|
c.errorReturnAutocstr(0);
|
||||||
|
c.errorReturnTempPointer(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string name() const
|
std::string name() const
|
||||||
|
|
|
@ -188,17 +188,18 @@ public:
|
||||||
void cmdLineArgsError(const Token *tok);
|
void cmdLineArgsError(const Token *tok);
|
||||||
void pointerOutOfBounds(const Token *tok); // UB when result of calculation is out of bounds
|
void pointerOutOfBounds(const Token *tok); // UB when result of calculation is out of bounds
|
||||||
|
|
||||||
void getErrorMessages()
|
void getErrorMessages(ErrorLogger *errorLogger, const Settings *settings)
|
||||||
{
|
{
|
||||||
arrayIndexOutOfBounds(0, 2, 2);
|
CheckBufferOverrun c(0, settings, errorLogger);
|
||||||
bufferOverrun(0, std::string("buffer"));
|
c.arrayIndexOutOfBounds(0, 2, 2);
|
||||||
strncatUsage(0);
|
c.bufferOverrun(0, std::string("buffer"));
|
||||||
outOfBounds(0, "index");
|
c.strncatUsage(0);
|
||||||
sizeArgumentAsChar(0);
|
c.outOfBounds(0, "index");
|
||||||
terminateStrncpyError(0);
|
c.sizeArgumentAsChar(0);
|
||||||
negativeIndexError(0, -1);
|
c.terminateStrncpyError(0);
|
||||||
cmdLineArgsError(0);
|
c.negativeIndexError(0, -1);
|
||||||
pointerOutOfBounds(0);
|
c.cmdLineArgsError(0);
|
||||||
|
c.pointerOutOfBounds(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string name() const
|
std::string name() const
|
||||||
|
|
|
@ -127,20 +127,21 @@ private:
|
||||||
void checkConstError(const Token *tok, const std::string &classname, const std::string &funcname);
|
void checkConstError(const Token *tok, const std::string &classname, const std::string &funcname);
|
||||||
void checkConstError2(const Token *tok1, const Token *tok2, const std::string &classname, const std::string &funcname);
|
void checkConstError2(const Token *tok1, const Token *tok2, const std::string &classname, const std::string &funcname);
|
||||||
|
|
||||||
void getErrorMessages()
|
void getErrorMessages(ErrorLogger *errorLogger, const Settings *settings)
|
||||||
{
|
{
|
||||||
noConstructorError(0, "classname", false);
|
CheckClass c(0, settings, errorLogger);
|
||||||
uninitVarError(0, "classname", "varname");
|
c.noConstructorError(0, "classname", false);
|
||||||
operatorEqVarError(0, "classname", "");
|
c.uninitVarError(0, "classname", "varname");
|
||||||
unusedPrivateFunctionError(0, "classname", "funcname");
|
c.operatorEqVarError(0, "classname", "");
|
||||||
memsetClassError(0, "memfunc");
|
c.unusedPrivateFunctionError(0, "classname", "funcname");
|
||||||
memsetStructError(0, "memfunc", "classname");
|
c.memsetClassError(0, "memfunc");
|
||||||
operatorEqReturnError(0);
|
c.memsetStructError(0, "memfunc", "classname");
|
||||||
//virtualDestructorError(0, "Base", "Derived");
|
c.operatorEqReturnError(0);
|
||||||
thisSubtractionError(0);
|
//c.virtualDestructorError(0, "Base", "Derived");
|
||||||
operatorEqRetRefThisError(0);
|
c.thisSubtractionError(0);
|
||||||
operatorEqToSelfError(0);
|
c.operatorEqRetRefThisError(0);
|
||||||
checkConstError(0, "class", "function");
|
c.operatorEqToSelfError(0);
|
||||||
|
c.checkConstError(0, "class", "function");
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string name() const
|
std::string name() const
|
||||||
|
|
|
@ -78,10 +78,11 @@ private:
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Generate all possible errors (for --errorlist) */
|
/** Generate all possible errors (for --errorlist) */
|
||||||
void getErrorMessages()
|
void getErrorMessages(ErrorLogger *errorLogger, const Settings *settings)
|
||||||
{
|
{
|
||||||
destructorsError(0);
|
CheckExceptionSafety c(0, settings, errorLogger);
|
||||||
deallocThrowError(0, "p");
|
c.destructorsError(0);
|
||||||
|
c.deallocThrowError(0, "p");
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Short description of class (for --doc) */
|
/** Short description of class (for --doc) */
|
||||||
|
|
|
@ -180,7 +180,10 @@ public:
|
||||||
: Check(tokenizr, settings, errLog), CheckMemoryLeak(tokenizr, errLog)
|
: Check(tokenizr, settings, errLog), CheckMemoryLeak(tokenizr, errLog)
|
||||||
{
|
{
|
||||||
// get the symbol database
|
// get the symbol database
|
||||||
symbolDatabase = tokenizr->getSymbolDatabase();
|
if (tokenizr)
|
||||||
|
symbolDatabase = tokenizr->getSymbolDatabase();
|
||||||
|
else
|
||||||
|
symbolDatabase = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** @brief run all simplified checks */
|
/** @brief run all simplified checks */
|
||||||
|
@ -307,17 +310,19 @@ public:
|
||||||
void checkScope(const Token *Tok1, const std::string &varname, unsigned int varid, bool classmember, unsigned int sz);
|
void checkScope(const Token *Tok1, const std::string &varname, unsigned int varid, bool classmember, unsigned int sz);
|
||||||
|
|
||||||
/** Report all possible errors (for the --errorlist) */
|
/** Report all possible errors (for the --errorlist) */
|
||||||
void getErrorMessages()
|
void getErrorMessages(ErrorLogger *e, const Settings *settings)
|
||||||
{
|
{
|
||||||
memleakError(0, "varname");
|
CheckMemoryLeakInFunction c(0, settings, e);
|
||||||
resourceLeakError(0, "varname");
|
|
||||||
|
|
||||||
deallocDeallocError(0, "varname");
|
c.memleakError(0, "varname");
|
||||||
deallocuseError(0, "varname");
|
c.resourceLeakError(0, "varname");
|
||||||
mismatchSizeError(0, "sz");
|
|
||||||
|
c.deallocDeallocError(0, "varname");
|
||||||
|
c.deallocuseError(0, "varname");
|
||||||
|
c.mismatchSizeError(0, "sz");
|
||||||
std::list<const Token *> callstack;
|
std::list<const Token *> callstack;
|
||||||
mismatchAllocDealloc(callstack, "varname");
|
c.mismatchAllocDealloc(callstack, "varname");
|
||||||
memleakUponReallocFailureError(0, "varname");
|
c.memleakUponReallocFailureError(0, "varname");
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -385,7 +390,7 @@ private:
|
||||||
void checkPublicFunctions(const SymbolDatabase::SpaceInfo *spaceinfo, const Token *classtok);
|
void checkPublicFunctions(const SymbolDatabase::SpaceInfo *spaceinfo, const Token *classtok);
|
||||||
void publicAllocationError(const Token *tok, const std::string &varname);
|
void publicAllocationError(const Token *tok, const std::string &varname);
|
||||||
|
|
||||||
void getErrorMessages()
|
void getErrorMessages(ErrorLogger * /*errorLogger*/, const Settings * /*settings*/)
|
||||||
{ }
|
{ }
|
||||||
|
|
||||||
std::string name() const
|
std::string name() const
|
||||||
|
@ -423,7 +428,7 @@ public:
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
void getErrorMessages()
|
void getErrorMessages(ErrorLogger * /*errorLogger*/, const Settings * /*settings*/)
|
||||||
{ }
|
{ }
|
||||||
|
|
||||||
std::string name() const
|
std::string name() const
|
||||||
|
@ -463,7 +468,7 @@ private:
|
||||||
|
|
||||||
void functionCallLeak(const Token *loc, const std::string &alloc, const std::string &functionCall);
|
void functionCallLeak(const Token *loc, const std::string &alloc, const std::string &functionCall);
|
||||||
|
|
||||||
void getErrorMessages()
|
void getErrorMessages(ErrorLogger * /*errorLogger*/, const Settings * /*settings*/)
|
||||||
{ }
|
{ }
|
||||||
|
|
||||||
std::string name() const
|
std::string name() const
|
||||||
|
|
|
@ -101,9 +101,10 @@ public:
|
||||||
void nullPointerError(const Token *tok, const std::string &varname);
|
void nullPointerError(const Token *tok, const std::string &varname);
|
||||||
void nullPointerError(const Token *tok, const std::string &varname, const unsigned int line);
|
void nullPointerError(const Token *tok, const std::string &varname, const unsigned int line);
|
||||||
|
|
||||||
void getErrorMessages()
|
void getErrorMessages(ErrorLogger *errorLogger, const Settings *settings)
|
||||||
{
|
{
|
||||||
nullPointerError(0, "pointer");
|
CheckNullPointer c(0, settings, errorLogger);
|
||||||
|
c.nullPointerError(0, "pointer");
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string name() const
|
std::string name() const
|
||||||
|
|
|
@ -112,12 +112,14 @@ private:
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void getErrorMessages()
|
void getErrorMessages(ErrorLogger *errorLogger, const Settings *settings)
|
||||||
{
|
{
|
||||||
|
CheckObsoleteFunctions c(0, settings, errorLogger);
|
||||||
|
|
||||||
std::list< std::pair<const std::string, const std::string> >::const_iterator it(_obsoleteFunctions.begin()), itend(_obsoleteFunctions.end());
|
std::list< std::pair<const std::string, const std::string> >::const_iterator it(_obsoleteFunctions.begin()), itend(_obsoleteFunctions.end());
|
||||||
for (; it!=itend; ++it)
|
for (; it!=itend; ++it)
|
||||||
{
|
{
|
||||||
reportError(0, Severity::style, "obsoleteFunctions"+it->first, it->second);
|
c.reportError(0, Severity::style, "obsoleteFunctions"+it->first, it->second);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -184,38 +184,40 @@ public:
|
||||||
void incorrectLogicOperatorError(const Token *tok);
|
void incorrectLogicOperatorError(const Token *tok);
|
||||||
void misusedScopeObjectError(const Token *tok, const std::string &varname);
|
void misusedScopeObjectError(const Token *tok, const std::string &varname);
|
||||||
|
|
||||||
void getErrorMessages()
|
void getErrorMessages(ErrorLogger *errorLogger, const Settings *settings)
|
||||||
{
|
{
|
||||||
|
CheckOther c(0, settings, errorLogger);
|
||||||
|
|
||||||
// error
|
// error
|
||||||
sprintfOverlappingDataError(0, "varname");
|
c.sprintfOverlappingDataError(0, "varname");
|
||||||
udivError(0);
|
c.udivError(0);
|
||||||
zerodivError(0);
|
c.zerodivError(0);
|
||||||
mathfunctionCallError(0);
|
c.mathfunctionCallError(0);
|
||||||
fflushOnInputStreamError(0, "stdin");
|
c.fflushOnInputStreamError(0, "stdin");
|
||||||
misusedScopeObjectError(NULL, "varname");
|
c.misusedScopeObjectError(NULL, "varname");
|
||||||
|
|
||||||
// style/warning
|
// style/warning
|
||||||
cstyleCastError(0);
|
c.cstyleCastError(0);
|
||||||
dangerousUsageStrtolError(0);
|
c.dangerousUsageStrtolError(0);
|
||||||
unusedStructMemberError(0, "structname", "variable");
|
c.unusedStructMemberError(0, "structname", "variable");
|
||||||
passedByValueError(0, "parametername");
|
c.passedByValueError(0, "parametername");
|
||||||
constStatementError(0, "type");
|
c.constStatementError(0, "type");
|
||||||
charArrayIndexError(0);
|
c.charArrayIndexError(0);
|
||||||
charBitOpError(0);
|
c.charBitOpError(0);
|
||||||
variableScopeError(0, "varname");
|
c.variableScopeError(0, "varname");
|
||||||
conditionAlwaysTrueFalse(0, "true/false");
|
c.conditionAlwaysTrueFalse(0, "true/false");
|
||||||
strPlusChar(0);
|
c.strPlusChar(0);
|
||||||
sizeofsizeofError(0);
|
c.sizeofsizeofError(0);
|
||||||
sizeofCalculationError(0);
|
c.sizeofCalculationError(0);
|
||||||
redundantAssignmentInSwitchError(0, "varname");
|
c.redundantAssignmentInSwitchError(0, "varname");
|
||||||
selfAssignmentError(0, "varname");
|
c.selfAssignmentError(0, "varname");
|
||||||
assignmentInAssertError(0, "varname");
|
c.assignmentInAssertError(0, "varname");
|
||||||
invalidScanfError(0);
|
c.invalidScanfError(0);
|
||||||
incorrectLogicOperatorError(0);
|
c.incorrectLogicOperatorError(0);
|
||||||
unusedVariableError(0, "varname");
|
c.unusedVariableError(0, "varname");
|
||||||
allocatedButUnusedVariableError(0, "varname");
|
c.allocatedButUnusedVariableError(0, "varname");
|
||||||
unreadVariableError(0, "varname");
|
c.unreadVariableError(0, "varname");
|
||||||
unassignedVariableError(0, "varname");
|
c.unassignedVariableError(0, "varname");
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string name() const
|
std::string name() const
|
||||||
|
|
|
@ -56,9 +56,10 @@ private:
|
||||||
/** Report Error */
|
/** Report Error */
|
||||||
void postfixOperatorError(const Token *tok);
|
void postfixOperatorError(const Token *tok);
|
||||||
|
|
||||||
void getErrorMessages()
|
void getErrorMessages(ErrorLogger *errorLogger, const Settings *settings)
|
||||||
{
|
{
|
||||||
postfixOperatorError(0);
|
CheckPostfixOperator c(0, settings, errorLogger);
|
||||||
|
c.postfixOperatorError(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string name() const
|
std::string name() const
|
||||||
|
|
|
@ -154,22 +154,23 @@ private:
|
||||||
void sizeError(const Token *tok);
|
void sizeError(const Token *tok);
|
||||||
void redundantIfRemoveError(const Token *tok);
|
void redundantIfRemoveError(const Token *tok);
|
||||||
|
|
||||||
void getErrorMessages()
|
void getErrorMessages(ErrorLogger *errorLogger, const Settings *settings)
|
||||||
{
|
{
|
||||||
invalidIteratorError(0, "iterator");
|
CheckStl c(0, settings, errorLogger);
|
||||||
iteratorsError(0, "container1", "container2");
|
c.invalidIteratorError(0, "iterator");
|
||||||
mismatchingContainersError(0);
|
c.iteratorsError(0, "container1", "container2");
|
||||||
dereferenceErasedError(0, "iter");
|
c.mismatchingContainersError(0);
|
||||||
stlOutOfBoundsError(0, "i", "foo");
|
c.dereferenceErasedError(0, "iter");
|
||||||
eraseError(0);
|
c.stlOutOfBoundsError(0, "i", "foo");
|
||||||
invalidIteratorError(0, "push_back|push_front|insert", "iterator");
|
c.eraseError(0);
|
||||||
invalidPointerError(0, "pointer");
|
c.invalidIteratorError(0, "push_back|push_front|insert", "iterator");
|
||||||
stlBoundriesError(0, "container");
|
c.invalidPointerError(0, "pointer");
|
||||||
if_findError(0, false);
|
c.stlBoundriesError(0, "container");
|
||||||
if_findError(0, true);
|
c.if_findError(0, false);
|
||||||
string_c_strError(0);
|
c.if_findError(0, true);
|
||||||
sizeError(0);
|
c.string_c_strError(0);
|
||||||
redundantIfRemoveError(0);
|
c.sizeError(0);
|
||||||
|
c.redundantIfRemoveError(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string name() const
|
std::string name() const
|
||||||
|
|
|
@ -77,12 +77,14 @@ public:
|
||||||
void uninitdataError(const Token *tok, const std::string &varname);
|
void uninitdataError(const Token *tok, const std::string &varname);
|
||||||
void uninitvarError(const Token *tok, const std::string &varname);
|
void uninitvarError(const Token *tok, const std::string &varname);
|
||||||
|
|
||||||
void getErrorMessages()
|
void getErrorMessages(ErrorLogger *errorLogger, const Settings *settings)
|
||||||
{
|
{
|
||||||
|
CheckUninitVar c(0, settings, errorLogger);
|
||||||
|
|
||||||
// error
|
// error
|
||||||
uninitstringError(0, "varname");
|
c.uninitstringError(0, "varname");
|
||||||
uninitdataError(0, "varname");
|
c.uninitdataError(0, "varname");
|
||||||
uninitvarError(0, "varname");
|
c.uninitvarError(0, "varname");
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string name() const
|
std::string name() const
|
||||||
|
|
|
@ -50,9 +50,10 @@ public:
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
void getErrorMessages()
|
void getErrorMessages(ErrorLogger *errorLogger, const Settings *settings)
|
||||||
{
|
{
|
||||||
unusedFunctionError(0, "", "funcName");
|
CheckUnusedFunctions c(0, settings, errorLogger);
|
||||||
|
c.unusedFunctionError(errorLogger, "", "funcName");
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -436,16 +436,14 @@ void CppCheck::reportStatus(unsigned int /*index*/, unsigned int /*max*/)
|
||||||
void CppCheck::getErrorMessages()
|
void CppCheck::getErrorMessages()
|
||||||
{
|
{
|
||||||
// call all "getErrorMessages" in all registered Check classes
|
// call all "getErrorMessages" in all registered Check classes
|
||||||
std::cout << ErrorLogger::ErrorMessage::getXMLHeader(1);
|
std::cout << ErrorLogger::ErrorMessage::getXMLHeader(_settings._xml_version);
|
||||||
for (std::list<Check *>::iterator it = Check::instances().begin(); it != Check::instances().end(); ++it)
|
for (std::list<Check *>::iterator it = Check::instances().begin(); it != Check::instances().end(); ++it)
|
||||||
{
|
(*it)->getErrorMessages(this, &_settings);
|
||||||
(*it)->getErrorMessages();
|
|
||||||
}
|
|
||||||
|
|
||||||
Tokenizer tokenizer(&_settings, 0);
|
Tokenizer tokenizer(&_settings, 0);
|
||||||
tokenizer.getErrorMessages();
|
tokenizer.getErrorMessages(this, &_settings);
|
||||||
|
|
||||||
Preprocessor::getErrorMessages(std::cout);
|
Preprocessor::getErrorMessages(this, &_settings);
|
||||||
|
|
||||||
std::cout << ErrorLogger::ErrorMessage::getXMLFooter() << std::endl;
|
std::cout << ErrorLogger::ErrorMessage::getXMLFooter() << std::endl;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1399,9 +1399,9 @@ std::string Preprocessor::getcode(const std::string &filedata, std::string cfg,
|
||||||
{
|
{
|
||||||
if (settings && !settings->userDefines.empty())
|
if (settings && !settings->userDefines.empty())
|
||||||
{
|
{
|
||||||
std::ostringstream errmsg;
|
Settings settings2(*settings);
|
||||||
errmsg << line;
|
Preprocessor preprocessor(&settings2, errorLogger);
|
||||||
writeError(filename, lineno, errorLogger, "preprocessorErrorDirective", errmsg.str());
|
preprocessor.error(filename, lineno, line);
|
||||||
}
|
}
|
||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
|
@ -1433,6 +1433,22 @@ std::string Preprocessor::getcode(const std::string &filedata, std::string cfg,
|
||||||
return expandMacros(ret.str(), filename, errorLogger);
|
return expandMacros(ret.str(), filename, errorLogger);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Preprocessor::error(const std::string &filename, unsigned int linenr, const std::string &msg)
|
||||||
|
{
|
||||||
|
std::list<ErrorLogger::ErrorMessage::FileLocation> locationList;
|
||||||
|
if (!filename.empty())
|
||||||
|
{
|
||||||
|
ErrorLogger::ErrorMessage::FileLocation loc;
|
||||||
|
loc.line = linenr;
|
||||||
|
loc.setfile(filename);
|
||||||
|
locationList.push_back(loc);
|
||||||
|
}
|
||||||
|
_errorLogger->reportErr(ErrorLogger::ErrorMessage(locationList,
|
||||||
|
Severity::error,
|
||||||
|
msg,
|
||||||
|
"preprocessorErrorDirective"));
|
||||||
|
}
|
||||||
|
|
||||||
Preprocessor::HeaderTypes Preprocessor::getHeaderFileName(std::string &str)
|
Preprocessor::HeaderTypes Preprocessor::getHeaderFileName(std::string &str)
|
||||||
{
|
{
|
||||||
std::string result;
|
std::string result;
|
||||||
|
@ -1606,24 +1622,36 @@ void Preprocessor::handleIncludes(std::string &code,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
std::list<ErrorLogger::ErrorMessage::FileLocation> locationList;
|
missingInclude(Path::toNativeSeparators(filePath),
|
||||||
ErrorLogger::ErrorMessage::FileLocation loc;
|
linenr,
|
||||||
loc.line = linenr; /** @todo set correct line */
|
filename,
|
||||||
loc.setfile(Path::toNativeSeparators(filePath));
|
headerType == UserHeader);
|
||||||
locationList.push_back(loc);
|
|
||||||
|
|
||||||
// If the missing include is a system header then this is
|
|
||||||
// currently a debug-message.
|
|
||||||
const Severity::SeverityType severity = (headerType == UserHeader) ? Severity::information : Severity::debug;
|
|
||||||
const std::string id = (headerType == UserHeader) ? "missingInclude" : "debug";
|
|
||||||
ErrorLogger::ErrorMessage errmsg(locationList, severity, "Include file: \"" + filename + "\" not found.", id);
|
|
||||||
errmsg.file0 = file0;
|
|
||||||
_errorLogger->reportErr(errmsg);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Report that include is missing
|
||||||
|
void Preprocessor::missingInclude(const std::string &filename, unsigned int linenr, const std::string &header, bool userheader)
|
||||||
|
{
|
||||||
|
std::list<ErrorLogger::ErrorMessage::FileLocation> locationList;
|
||||||
|
if (!filename.empty())
|
||||||
|
{
|
||||||
|
ErrorLogger::ErrorMessage::FileLocation loc;
|
||||||
|
loc.line = linenr;
|
||||||
|
loc.setfile(filename);
|
||||||
|
locationList.push_back(loc);
|
||||||
|
}
|
||||||
|
|
||||||
|
// If the missing include is a system header then this is
|
||||||
|
// currently a debug-message.
|
||||||
|
const Severity::SeverityType severity = userheader ? Severity::information : Severity::debug;
|
||||||
|
const std::string id = userheader ? "missingInclude" : "debug";
|
||||||
|
ErrorLogger::ErrorMessage errmsg(locationList, severity, "Include file: \"" + header + "\" not found.", id);
|
||||||
|
errmsg.file0 = file0;
|
||||||
|
_errorLogger->reportErr(errmsg);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Skip string in line. A string begins and ends with either a " or a '
|
* Skip string in line. A string begins and ends with either a " or a '
|
||||||
* @param line the string
|
* @param line the string
|
||||||
|
@ -2405,18 +2433,11 @@ std::string Preprocessor::expandMacros(const std::string &code, std::string file
|
||||||
return ostr.str();
|
return ostr.str();
|
||||||
}
|
}
|
||||||
|
|
||||||
void Preprocessor::getErrorMessages(std::ostream &ostr)
|
|
||||||
{
|
|
||||||
std::list<ErrorLogger::ErrorMessage::FileLocation> locationList;
|
|
||||||
const ErrorLogger::ErrorMessage errmsg(locationList,
|
|
||||||
Severity::style,
|
|
||||||
"Include file: \"\" not found.",
|
|
||||||
"missingInclude");
|
|
||||||
ostr << errmsg.toXML(false, 1) << std::endl;
|
|
||||||
|
|
||||||
const ErrorLogger::ErrorMessage errmsg2(locationList,
|
void Preprocessor::getErrorMessages(ErrorLogger *errorLogger, const Settings *settings)
|
||||||
Severity::error,
|
{
|
||||||
"#error ...",
|
Settings settings2(*settings);
|
||||||
"preprocessorErrorDirective");
|
Preprocessor preprocessor(&settings2, errorLogger);
|
||||||
ostr << errmsg2.toXML(false, 1) << std::endl;
|
preprocessor.missingInclude("", 1, "", true);
|
||||||
|
preprocessor.error("", 1, "#error message"); // #error ..
|
||||||
}
|
}
|
||||||
|
|
|
@ -196,9 +196,13 @@ public:
|
||||||
*/
|
*/
|
||||||
static bool match_cfg_def(const std::map<std::string, std::string> &cfg, std::string def);
|
static bool match_cfg_def(const std::map<std::string, std::string> &cfg, std::string def);
|
||||||
|
|
||||||
static void getErrorMessages(std::ostream &ostr);
|
static void getErrorMessages(ErrorLogger *errorLogger, const Settings *settings);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
void missingInclude(const std::string &filename, unsigned int linenr, const std::string &header, bool userheader);
|
||||||
|
|
||||||
|
void error(const std::string &filename, unsigned int linenr, const std::string &msg);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Search includes from code and append code from the included
|
* Search includes from code and append code from the included
|
||||||
* file
|
* file
|
||||||
|
|
|
@ -8224,10 +8224,11 @@ void Tokenizer::simplifyConst()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Tokenizer::getErrorMessages()
|
void Tokenizer::getErrorMessages(ErrorLogger *errorLogger, const Settings *settings)
|
||||||
{
|
{
|
||||||
syntaxError(0, ' ');
|
Tokenizer t(settings, errorLogger);
|
||||||
cppcheckError(0);
|
t.syntaxError(0, ' ');
|
||||||
|
t.cppcheckError(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
/** find pattern */
|
/** find pattern */
|
||||||
|
|
|
@ -133,7 +133,7 @@ public:
|
||||||
/**
|
/**
|
||||||
* get error messages
|
* get error messages
|
||||||
*/
|
*/
|
||||||
virtual void getErrorMessages();
|
virtual void getErrorMessages(ErrorLogger *errorLogger, const Settings *settings);
|
||||||
|
|
||||||
/** Simplify assignment in function call "f(x=g());" => "x=g();f(x);"
|
/** Simplify assignment in function call "f(x=g());" => "x=g();f(x);"
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -2763,7 +2763,7 @@ private:
|
||||||
{
|
{
|
||||||
// Ticket #2292: segmentation fault when using --errorlist
|
// Ticket #2292: segmentation fault when using --errorlist
|
||||||
CheckBufferOverrun c;
|
CheckBufferOverrun c;
|
||||||
c.getErrorMessages();
|
c.getErrorMessages(this, 0);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue