2009-02-19 18:57:27 +01:00
|
|
|
/*
|
|
|
|
* Cppcheck - A tool for static C/C++ code analysis
|
2018-06-10 22:07:21 +02:00
|
|
|
* Copyright (C) 2007-2018 Cppcheck team.
|
2009-02-19 18:57:27 +01:00
|
|
|
*
|
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
2009-09-27 17:08:31 +02:00
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
2009-02-19 18:57:27 +01:00
|
|
|
*/
|
|
|
|
|
2013-09-04 20:59:49 +02:00
|
|
|
//---------------------------------------------------------------------------
|
2009-02-19 18:57:27 +01:00
|
|
|
#ifndef errorloggerH
|
|
|
|
#define errorloggerH
|
2013-09-04 20:59:49 +02:00
|
|
|
//---------------------------------------------------------------------------
|
2010-07-19 09:54:53 +02:00
|
|
|
|
2012-06-10 14:19:09 +02:00
|
|
|
#include "config.h"
|
2011-08-22 18:54:23 +02:00
|
|
|
#include "suppressions.h"
|
2011-02-16 02:12:15 +01:00
|
|
|
|
2017-05-27 04:33:47 +02:00
|
|
|
#include <cstddef>
|
2017-05-16 14:07:23 +02:00
|
|
|
#include <fstream>
|
2015-11-29 10:49:10 +01:00
|
|
|
#include <list>
|
|
|
|
#include <string>
|
2017-05-27 04:33:47 +02:00
|
|
|
#include <utility>
|
2017-05-16 14:07:23 +02:00
|
|
|
#include <vector>
|
2015-11-29 10:49:10 +01:00
|
|
|
|
2016-02-27 16:03:50 +01:00
|
|
|
/**
|
|
|
|
* CWE id (Common Weakness Enumeration)
|
|
|
|
* See https://cwe.mitre.org/ for further reference.
|
|
|
|
* */
|
Mapped toomanyconfigs ,AssignmentAddressToInteger
,AssignmentIntegerToAddress ,CastIntegerToAddressAtReturn
,CastAddressToIntegerAtReturn ,assertWithSideEffect ,assignmentInAssert
,uselessAssignmentArg ,uselessAssignmentPtrArg
,comparisonOfFuncReturningBoolError
,comparisonOfTwoFuncsReturningBoolError ,comparisonOfBoolWithBoolError
,incrementboolean ,comparisonOfBoolWithInt ,compareBoolExpressionWithInt
,negativeIndex ,pointerOutOfBounds ,arrayIndexThenCheck
,possibleBufferAccessOutOfBounds ,argumentSize
,arrayIndexOutOfBoundsCond ,noConstructor ,copyCtorPointerCopying
,noCopyConstructor ,uninitMemberVar ,operatorEqVarError
,unusedPrivateFunction ,memsetClassFloat ,mallocOnClassWarning
,operatorEq ,thisSubtraction ,operatorEqRetRefThis ,operatorEqToSelf
,useInitializationList ,duplInheritedMember ,assignIfError
,comparisonError ,multiCondition ,mismatchingBitAnd
,oppositeInnerCondition ,incorrectLogicOperator ,redundantCondition
,moduloAlwaysTrueFalse to their CWEs ids.
2016-02-20 23:56:36 +01:00
|
|
|
struct CWE {
|
2016-02-27 16:03:50 +01:00
|
|
|
explicit CWE(unsigned short ID) : id(ID) {}
|
|
|
|
unsigned short id;
|
Mapped toomanyconfigs ,AssignmentAddressToInteger
,AssignmentIntegerToAddress ,CastIntegerToAddressAtReturn
,CastAddressToIntegerAtReturn ,assertWithSideEffect ,assignmentInAssert
,uselessAssignmentArg ,uselessAssignmentPtrArg
,comparisonOfFuncReturningBoolError
,comparisonOfTwoFuncsReturningBoolError ,comparisonOfBoolWithBoolError
,incrementboolean ,comparisonOfBoolWithInt ,compareBoolExpressionWithInt
,negativeIndex ,pointerOutOfBounds ,arrayIndexThenCheck
,possibleBufferAccessOutOfBounds ,argumentSize
,arrayIndexOutOfBoundsCond ,noConstructor ,copyCtorPointerCopying
,noCopyConstructor ,uninitMemberVar ,operatorEqVarError
,unusedPrivateFunction ,memsetClassFloat ,mallocOnClassWarning
,operatorEq ,thisSubtraction ,operatorEqRetRefThis ,operatorEqToSelf
,useInitializationList ,duplInheritedMember ,assignIfError
,comparisonError ,multiCondition ,mismatchingBitAnd
,oppositeInnerCondition ,incorrectLogicOperator ,redundantCondition
,moduloAlwaysTrueFalse to their CWEs ids.
2016-02-20 23:56:36 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
2009-02-19 18:57:27 +01:00
|
|
|
class Token;
|
2012-05-06 10:17:15 +02:00
|
|
|
class TokenList;
|
2017-05-27 04:33:47 +02:00
|
|
|
|
2016-10-29 12:18:11 +02:00
|
|
|
namespace tinyxml2 {
|
|
|
|
class XMLElement;
|
|
|
|
}
|
2009-02-19 18:57:27 +01:00
|
|
|
|
2009-07-17 10:49:01 +02:00
|
|
|
/// @addtogroup Core
|
|
|
|
/// @{
|
|
|
|
|
2012-08-10 12:43:53 +02:00
|
|
|
/** @brief Simple container to be thrown when internal error is detected. */
|
|
|
|
struct InternalError {
|
2018-11-13 20:14:56 +01:00
|
|
|
enum Type {AST, SYNTAX, UNKNOWN_MACRO, INTERNAL};
|
2014-03-27 13:15:21 +01:00
|
|
|
InternalError(const Token *tok, const std::string &errorMsg, Type type = INTERNAL);
|
2012-08-10 12:43:53 +02:00
|
|
|
const Token *token;
|
|
|
|
std::string errorMessage;
|
2018-11-13 20:14:56 +01:00
|
|
|
Type type;
|
2014-03-27 13:15:21 +01:00
|
|
|
std::string id;
|
2012-08-10 12:43:53 +02:00
|
|
|
};
|
|
|
|
|
2010-07-14 16:30:03 +02:00
|
|
|
/** @brief enum class for severity. Used when reporting errors. */
|
2012-06-10 14:19:09 +02:00
|
|
|
class CPPCHECKLIB Severity {
|
2010-07-14 16:30:03 +02:00
|
|
|
public:
|
2011-03-06 13:29:12 +01:00
|
|
|
/**
|
|
|
|
* Message severities.
|
|
|
|
*/
|
2011-10-13 20:53:06 +02:00
|
|
|
enum SeverityType {
|
2011-03-06 13:29:12 +01:00
|
|
|
/**
|
|
|
|
* No severity (default value).
|
|
|
|
*/
|
|
|
|
none,
|
|
|
|
/**
|
|
|
|
* Programming error.
|
|
|
|
* This indicates severe error like memory leak etc.
|
2011-03-06 14:26:02 +01:00
|
|
|
* The error is certain.
|
2011-03-06 13:29:12 +01:00
|
|
|
*/
|
|
|
|
error,
|
|
|
|
/**
|
|
|
|
* Warning.
|
2011-03-06 14:26:02 +01:00
|
|
|
* Used for dangerous coding style that can cause severe runtime errors.
|
|
|
|
* For example: forgetting to initialize a member variable in a constructor.
|
2011-03-06 13:29:12 +01:00
|
|
|
*/
|
|
|
|
warning,
|
|
|
|
/**
|
|
|
|
* Style warning.
|
2011-03-06 14:26:02 +01:00
|
|
|
* Used for general code cleanup recommendations. Fixing these
|
|
|
|
* will not fix any bugs but will make the code easier to maintain.
|
|
|
|
* For example: redundant code, unreachable code, etc.
|
2011-03-06 13:29:12 +01:00
|
|
|
*/
|
|
|
|
style,
|
|
|
|
/**
|
|
|
|
* Performance warning.
|
|
|
|
* Not an error as is but suboptimal code and fixing it probably leads
|
|
|
|
* to faster performance of the compiled code.
|
|
|
|
*/
|
|
|
|
performance,
|
|
|
|
/**
|
|
|
|
* Portability warning.
|
|
|
|
* This warning indicates the code is not properly portable for
|
|
|
|
* different platforms and bitnesses (32/64 bit). If the code is meant
|
|
|
|
* to compile in different platforms and bitnesses these warnings
|
|
|
|
* should be fixed.
|
|
|
|
*/
|
|
|
|
portability,
|
|
|
|
/**
|
|
|
|
* Checking information.
|
|
|
|
* Information message about the checking (process) itself. These
|
|
|
|
* messages inform about header files not found etc issues that are
|
|
|
|
* not errors in the code but something user needs to know.
|
|
|
|
*/
|
|
|
|
information,
|
|
|
|
/**
|
|
|
|
* Debug message.
|
|
|
|
* Debug-mode message useful for the developers.
|
|
|
|
*/
|
2011-04-14 18:02:01 +02:00
|
|
|
debug
|
2011-03-06 13:29:12 +01:00
|
|
|
};
|
|
|
|
|
2014-11-20 14:20:09 +01:00
|
|
|
static std::string toString(SeverityType severity) {
|
2011-10-13 20:53:06 +02:00
|
|
|
switch (severity) {
|
2010-07-14 19:21:39 +02:00
|
|
|
case none:
|
|
|
|
return "";
|
2010-07-14 16:30:03 +02:00
|
|
|
case error:
|
|
|
|
return "error";
|
2010-10-17 14:41:00 +02:00
|
|
|
case warning:
|
|
|
|
return "warning";
|
2010-07-14 16:30:03 +02:00
|
|
|
case style:
|
|
|
|
return "style";
|
2010-10-17 14:41:00 +02:00
|
|
|
case performance:
|
|
|
|
return "performance";
|
2010-12-11 21:54:06 +01:00
|
|
|
case portability:
|
|
|
|
return "portability";
|
2010-12-22 19:53:17 +01:00
|
|
|
case information:
|
|
|
|
return "information";
|
2010-07-14 18:41:29 +02:00
|
|
|
case debug:
|
|
|
|
return "debug";
|
2010-07-14 16:30:03 +02:00
|
|
|
};
|
2016-05-07 16:30:54 +02:00
|
|
|
throw InternalError(nullptr, "Unknown severity");
|
2010-07-14 16:30:03 +02:00
|
|
|
}
|
2014-11-20 14:20:09 +01:00
|
|
|
static SeverityType fromString(const std::string &severity) {
|
2010-07-14 19:21:39 +02:00
|
|
|
if (severity.empty())
|
|
|
|
return none;
|
|
|
|
if (severity == "none")
|
|
|
|
return none;
|
2010-07-14 18:36:34 +02:00
|
|
|
if (severity == "error")
|
|
|
|
return error;
|
2010-10-17 14:41:00 +02:00
|
|
|
if (severity == "warning")
|
|
|
|
return warning;
|
2010-07-14 18:36:34 +02:00
|
|
|
if (severity == "style")
|
|
|
|
return style;
|
2010-10-17 14:41:00 +02:00
|
|
|
if (severity == "performance")
|
|
|
|
return performance;
|
2010-12-11 21:54:06 +01:00
|
|
|
if (severity == "portability")
|
|
|
|
return portability;
|
2010-12-22 19:53:17 +01:00
|
|
|
if (severity == "information")
|
|
|
|
return information;
|
2010-07-14 18:41:29 +02:00
|
|
|
if (severity == "debug")
|
|
|
|
return debug;
|
2010-07-14 18:36:34 +02:00
|
|
|
return none;
|
|
|
|
}
|
2010-07-14 16:30:03 +02:00
|
|
|
};
|
|
|
|
|
2017-05-16 22:38:13 +02:00
|
|
|
|
|
|
|
typedef std::pair<const Token *, std::string> ErrorPathItem;
|
|
|
|
typedef std::list<ErrorPathItem> ErrorPath;
|
|
|
|
|
2009-02-19 18:57:27 +01:00
|
|
|
/**
|
2010-03-13 21:49:09 +01:00
|
|
|
* @brief This is an interface, which the class responsible of error logging
|
2009-02-19 18:57:27 +01:00
|
|
|
* should implement.
|
|
|
|
*/
|
2012-06-10 14:19:09 +02:00
|
|
|
class CPPCHECKLIB ErrorLogger {
|
2017-05-16 14:07:23 +02:00
|
|
|
protected:
|
|
|
|
std::ofstream plistFile;
|
2009-02-19 18:57:27 +01:00
|
|
|
public:
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Wrapper for error messages, provided by reportErr()
|
|
|
|
*/
|
2012-06-10 14:19:09 +02:00
|
|
|
class CPPCHECKLIB ErrorMessage {
|
2009-02-19 18:57:27 +01:00
|
|
|
public:
|
|
|
|
/**
|
|
|
|
* File name and line number.
|
2010-07-18 10:20:10 +02:00
|
|
|
* Internally paths are stored with / separator. When getting the filename
|
|
|
|
* it is by default converted to native separators.
|
2009-02-19 18:57:27 +01:00
|
|
|
*/
|
2012-06-10 14:19:09 +02:00
|
|
|
class CPPCHECKLIB FileLocation {
|
2009-02-19 18:57:27 +01:00
|
|
|
public:
|
2012-05-18 16:57:11 +02:00
|
|
|
FileLocation()
|
2017-05-17 15:22:51 +02:00
|
|
|
: fileIndex(0), line(0), col(0) {
|
2009-03-01 20:38:17 +01:00
|
|
|
}
|
2009-05-31 10:12:19 +02:00
|
|
|
|
2011-02-16 20:56:02 +01:00
|
|
|
FileLocation(const std::string &file, unsigned int aline)
|
2018-11-18 16:08:08 +01:00
|
|
|
: fileIndex(0), line(aline), col(0), mOrigFileName(file), mFileName(file) {
|
2011-02-16 02:12:15 +01:00
|
|
|
}
|
|
|
|
|
2017-05-16 22:58:02 +02:00
|
|
|
FileLocation(const std::string &file, const std::string &info, unsigned int aline)
|
2018-11-18 16:08:08 +01:00
|
|
|
: fileIndex(0), line(aline), col(0), mOrigFileName(file), mFileName(file), mInfo(info) {
|
2017-05-16 22:58:02 +02:00
|
|
|
}
|
|
|
|
|
2017-05-17 15:22:51 +02:00
|
|
|
FileLocation(const Token* tok, const TokenList* tokenList);
|
2017-05-16 22:38:13 +02:00
|
|
|
FileLocation(const Token* tok, const std::string &info, const TokenList* tokenList);
|
2012-05-06 10:17:15 +02:00
|
|
|
|
2010-07-18 10:20:10 +02:00
|
|
|
/**
|
|
|
|
* Return the filename.
|
|
|
|
* @param convert If true convert path to native separators.
|
|
|
|
* @return filename.
|
|
|
|
*/
|
|
|
|
std::string getfile(bool convert = true) const;
|
|
|
|
|
2018-11-18 16:08:08 +01:00
|
|
|
std::string getOrigFile(bool convert = true) const;
|
|
|
|
|
2010-07-18 10:20:10 +02:00
|
|
|
/**
|
|
|
|
* Set the filename.
|
|
|
|
* @param file Filename to set.
|
|
|
|
*/
|
2010-07-17 00:27:40 +02:00
|
|
|
void setfile(const std::string &file);
|
2012-05-06 10:17:15 +02:00
|
|
|
|
|
|
|
/**
|
2014-04-27 21:42:10 +02:00
|
|
|
* @return the location as a string. Format: [file:line]
|
2012-05-06 10:17:15 +02:00
|
|
|
*/
|
|
|
|
std::string stringify() const;
|
|
|
|
|
2017-05-17 15:22:51 +02:00
|
|
|
unsigned int fileIndex;
|
2018-09-25 06:14:26 +02:00
|
|
|
int line; // negative value means "no line"
|
2017-05-17 15:22:51 +02:00
|
|
|
unsigned int col;
|
2016-01-31 10:10:26 +01:00
|
|
|
|
2017-05-16 23:12:35 +02:00
|
|
|
std::string getinfo() const {
|
2018-06-17 07:52:59 +02:00
|
|
|
return mInfo;
|
2017-05-16 23:12:35 +02:00
|
|
|
}
|
|
|
|
void setinfo(const std::string &i) {
|
2018-06-17 07:52:59 +02:00
|
|
|
mInfo = i;
|
2017-05-16 23:12:35 +02:00
|
|
|
}
|
2017-05-16 22:58:02 +02:00
|
|
|
|
2010-07-17 00:27:40 +02:00
|
|
|
private:
|
2018-11-18 16:08:08 +01:00
|
|
|
std::string mOrigFileName;
|
2018-06-17 07:52:59 +02:00
|
|
|
std::string mFileName;
|
|
|
|
std::string mInfo;
|
2009-02-19 18:57:27 +01:00
|
|
|
};
|
|
|
|
|
lib: fix a bunch of warnings about differing function arguments in definition and declaration.
[lib/token.h:72] -> [lib/token.cpp:36]: (style, inconclusive) Function 'Token' argument 1 names different: declaration 'tokensBack' definition 't'.
[lib/token.h:445] -> [lib/token.cpp:497]: (style, inconclusive) Function 'multiCompare' argument 1 names different: declaration 'needle' definition 'tok'.
[lib/checkio.h:73] -> [lib/checkio.cpp:1385]: (style, inconclusive) Function 'ArgumentInfo' argument 3 names different: declaration 'isCPP' definition '_isCPP'.
[lib/checkother.h:216] -> [lib/checkother.cpp:2136]: (style, inconclusive) Function 'checkComparisonFunctionIsAlwaysTrueOrFalseError' argument 2 names different: declaration 'strFunctionName' definition 'functionName'.
[lib/errorlogger.h:214] -> [lib/errorlogger.cpp:51]: (style, inconclusive) Function 'ErrorMessage' argument 2 names different: declaration 'file0' definition 'file0_'.
[lib/errorlogger.h:215] -> [lib/errorlogger.cpp:65]: (style, inconclusive) Function 'ErrorMessage' argument 2 names different: declaration 'file0' definition 'file0_'.
[lib/library.h:327] -> [lib/library.cpp:1043]: (style, inconclusive) Function 'ignorefunction' argument 1 names different: declaration 'function' definition 'functionName'.
[lib/mathlib.h:112] -> [lib/mathlib.cpp:1275]: (style, inconclusive) Function 'isNullValue' argument 1 names different: declaration 'tok' definition 'str'.
[lib/preprocessor.h:91] -> [lib/preprocessor.cpp:122]: (style, inconclusive) Function 'setDirectives' argument 1 names different: declaration 'tokens' definition 'tokens1'.
[lib/symboldatabase.h:860] -> [lib/symboldatabase.cpp:1801]: (style, inconclusive) Function 'argsMatch' argument 1 names different: declaration 'info' definition 'scope'.
[lib/symboldatabase.h:1171] -> [lib/symboldatabase.cpp:2048]: (style, inconclusive) Function 'addClassFunction' argument 1 names different: declaration 'info' definition 'scope'.
[lib/symboldatabase.h:1174] -> [lib/symboldatabase.cpp:2208]: (style, inconclusive) Function 'addNewFunction' argument 1 names different: declaration 'info' definition 'scope'.
[lib/symboldatabase.h:1090] -> [lib/symboldatabase.cpp:3648]: (style, inconclusive) Function 'findVariableType' argument 2 names different: declaration 'type' definition 'typeTok'.
[lib/symboldatabase.h:1101] -> [lib/symboldatabase.cpp:4308]: (style, inconclusive) Function 'findType' argument 1 names different: declaration 'tok' definition 'startTok'.
[lib/symboldatabase.h:1176] -> [lib/symboldatabase.cpp:4349]: (style, inconclusive) Function 'findTypeInNested' argument 1 names different: declaration 'tok' definition 'startTok'.
[lib/symboldatabase.h:1193] -> [lib/symboldatabase.cpp:4501]: (style, inconclusive) Function 'setValueType' argument 2 names different: declaration 'enumerators' definition 'enumerator'.
[lib/path.h:159] -> [lib/path.cpp:247]: (style, inconclusive) Function 'isCPP' argument 1 names different: declaration 'extensionInLowerCase' definition 'path'.
[lib/path.h:145] -> [lib/path.cpp:266]: (style, inconclusive) Function 'acceptFile' argument 1 names different: declaration 'filename' definition 'path'.
2017-04-03 00:06:46 +02:00
|
|
|
ErrorMessage(const std::list<FileLocation> &callStack, const std::string& file1, Severity::SeverityType severity, const std::string &msg, const std::string &id, bool inconclusive);
|
|
|
|
ErrorMessage(const std::list<FileLocation> &callStack, const std::string& file1, Severity::SeverityType severity, const std::string &msg, const std::string &id, const CWE &cwe, bool inconclusive);
|
2012-05-06 10:17:15 +02:00
|
|
|
ErrorMessage(const std::list<const Token*>& callstack, const TokenList* list, Severity::SeverityType severity, const std::string& id, const std::string& msg, bool inconclusive);
|
Mapped toomanyconfigs ,AssignmentAddressToInteger
,AssignmentIntegerToAddress ,CastIntegerToAddressAtReturn
,CastAddressToIntegerAtReturn ,assertWithSideEffect ,assignmentInAssert
,uselessAssignmentArg ,uselessAssignmentPtrArg
,comparisonOfFuncReturningBoolError
,comparisonOfTwoFuncsReturningBoolError ,comparisonOfBoolWithBoolError
,incrementboolean ,comparisonOfBoolWithInt ,compareBoolExpressionWithInt
,negativeIndex ,pointerOutOfBounds ,arrayIndexThenCheck
,possibleBufferAccessOutOfBounds ,argumentSize
,arrayIndexOutOfBoundsCond ,noConstructor ,copyCtorPointerCopying
,noCopyConstructor ,uninitMemberVar ,operatorEqVarError
,unusedPrivateFunction ,memsetClassFloat ,mallocOnClassWarning
,operatorEq ,thisSubtraction ,operatorEqRetRefThis ,operatorEqToSelf
,useInitializationList ,duplInheritedMember ,assignIfError
,comparisonError ,multiCondition ,mismatchingBitAnd
,oppositeInnerCondition ,incorrectLogicOperator ,redundantCondition
,moduloAlwaysTrueFalse to their CWEs ids.
2016-02-20 23:56:36 +01:00
|
|
|
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);
|
2017-05-16 22:38:13 +02:00
|
|
|
ErrorMessage(const ErrorPath &errorPath, const TokenList *tokenList, Severity::SeverityType severity, const char id[], const std::string &msg, const CWE &cwe, bool inconclusive);
|
2009-02-19 23:21:18 +01:00
|
|
|
ErrorMessage();
|
2016-10-29 12:35:14 +02:00
|
|
|
explicit ErrorMessage(const tinyxml2::XMLElement * const errmsg);
|
2010-11-11 19:54:43 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Format the error message in XML format
|
|
|
|
*/
|
2017-07-29 18:56:22 +02:00
|
|
|
std::string toXML() const;
|
2009-06-15 20:36:39 +02:00
|
|
|
|
2017-07-29 18:56:22 +02:00
|
|
|
static std::string getXMLHeader();
|
|
|
|
static std::string getXMLFooter();
|
2009-06-15 20:36:39 +02:00
|
|
|
|
2009-09-05 21:01:49 +02:00
|
|
|
/**
|
|
|
|
* Format the error message into a string.
|
2010-11-11 19:54:43 +01:00
|
|
|
* @param verbose use verbose message
|
2018-04-23 12:21:18 +02:00
|
|
|
* @param templateFormat Empty string to use default output format
|
2009-09-05 21:01:49 +02:00
|
|
|
* or template to be used. E.g. "{file}:{line},{severity},{id},{message}"
|
2018-04-23 12:21:18 +02:00
|
|
|
* @param templateLocation Format Empty string to use default output format
|
|
|
|
* or template to be used. E.g. "{file}:{line},{info}"
|
2014-04-27 21:42:10 +02:00
|
|
|
* @return formatted string
|
2014-06-26 11:44:19 +02:00
|
|
|
*/
|
2018-04-23 12:21:18 +02:00
|
|
|
std::string toString(bool verbose, const std::string &templateFormat = emptyString, const std::string &templateLocation = emptyString) const;
|
2010-11-11 19:54:43 +01:00
|
|
|
|
|
|
|
std::string serialize() const;
|
|
|
|
bool deserialize(const std::string &data);
|
|
|
|
|
|
|
|
std::list<FileLocation> _callStack;
|
|
|
|
std::string _id;
|
|
|
|
|
|
|
|
/** source file (not header) */
|
|
|
|
std::string file0;
|
2009-09-05 21:01:49 +02:00
|
|
|
|
2012-05-14 20:46:23 +02:00
|
|
|
Severity::SeverityType _severity;
|
2016-02-27 16:03:50 +01:00
|
|
|
CWE _cwe;
|
2012-05-14 20:46:23 +02:00
|
|
|
bool _inconclusive;
|
|
|
|
|
2010-11-11 19:54:43 +01:00
|
|
|
/** set short and verbose messages */
|
|
|
|
void setmsg(const std::string &msg);
|
|
|
|
|
|
|
|
/** Short message (single line short message) */
|
2014-11-20 14:20:09 +01:00
|
|
|
const std::string &shortMessage() const {
|
2018-06-17 07:54:50 +02:00
|
|
|
return mShortMessage;
|
2010-11-11 19:54:43 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/** Verbose message (may be the same as the short message) */
|
2014-11-20 14:20:09 +01:00
|
|
|
const std::string &verboseMessage() const {
|
2018-06-17 07:55:47 +02:00
|
|
|
return mVerboseMessage;
|
2010-11-11 19:54:43 +01:00
|
|
|
}
|
|
|
|
|
2018-04-09 06:43:48 +02:00
|
|
|
/** Symbol names */
|
|
|
|
const std::string &symbolNames() const {
|
2018-06-17 07:59:48 +02:00
|
|
|
return mSymbolNames;
|
2018-04-09 06:43:48 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
Suppressions::ErrorMessage toSuppressionsErrorMessage() const;
|
|
|
|
|
2010-11-11 19:54:43 +01:00
|
|
|
private:
|
2009-09-05 21:01:49 +02:00
|
|
|
/**
|
2010-12-15 18:45:53 +01:00
|
|
|
* Replace all occurrences of searchFor with replaceWith in the
|
2009-09-05 21:01:49 +02:00
|
|
|
* given source.
|
|
|
|
* @param source The string to modify
|
|
|
|
* @param searchFor What should be searched for
|
|
|
|
* @param replaceWith What will replace the found item
|
|
|
|
*/
|
|
|
|
static void findAndReplace(std::string &source, const std::string &searchFor, const std::string &replaceWith);
|
2010-08-30 17:44:46 +02:00
|
|
|
|
2015-06-18 19:07:51 +02:00
|
|
|
static std::string fixInvalidChars(const std::string& raw);
|
|
|
|
|
2010-11-11 19:54:43 +01:00
|
|
|
/** Short message */
|
2018-06-17 07:54:50 +02:00
|
|
|
std::string mShortMessage;
|
2010-11-11 19:54:43 +01:00
|
|
|
|
|
|
|
/** Verbose message */
|
2018-06-17 07:55:47 +02:00
|
|
|
std::string mVerboseMessage;
|
2018-04-09 06:43:48 +02:00
|
|
|
|
|
|
|
/** symbol names */
|
2018-06-17 07:59:48 +02:00
|
|
|
std::string mSymbolNames;
|
2009-02-19 18:57:27 +01:00
|
|
|
};
|
|
|
|
|
2010-08-03 16:36:21 +02:00
|
|
|
ErrorLogger() { }
|
2017-05-16 14:07:23 +02:00
|
|
|
virtual ~ErrorLogger() {
|
|
|
|
if (plistFile.is_open()) {
|
|
|
|
plistFile << ErrorLogger::plistFooter();
|
|
|
|
plistFile.close();
|
|
|
|
}
|
|
|
|
}
|
2009-02-19 18:57:27 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Information about progress is directed here.
|
|
|
|
* Override this to receive the progress messages.
|
|
|
|
*
|
2009-06-20 11:54:49 +02:00
|
|
|
* @param outmsg Message to show e.g. "Checking main.cpp..."
|
2009-02-19 18:57:27 +01:00
|
|
|
*/
|
|
|
|
virtual void reportOut(const std::string &outmsg) = 0;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Information about found errors and warnings is directed
|
|
|
|
* here. Override this to receive the errormessages.
|
|
|
|
*
|
2012-06-18 23:15:48 +02:00
|
|
|
* @param msg Location and other information about the found error.
|
2009-02-19 18:57:27 +01:00
|
|
|
*/
|
|
|
|
virtual void reportErr(const ErrorLogger::ErrorMessage &msg) = 0;
|
|
|
|
|
2010-07-24 18:58:52 +02:00
|
|
|
/**
|
2010-08-03 16:36:21 +02:00
|
|
|
* Report progress to client
|
|
|
|
* @param filename main file that is checked
|
|
|
|
* @param stage for example preprocess / tokenize / simplify / check
|
|
|
|
* @param value progress value (0-100)
|
2010-07-24 18:58:52 +02:00
|
|
|
*/
|
2014-11-20 14:20:09 +01:00
|
|
|
virtual void reportProgress(const std::string &filename, const char stage[], const std::size_t value) {
|
2010-08-03 16:36:21 +02:00
|
|
|
(void)filename;
|
|
|
|
(void)stage;
|
|
|
|
(void)value;
|
|
|
|
}
|
2010-07-24 18:58:52 +02:00
|
|
|
|
2012-06-18 23:15:48 +02:00
|
|
|
/**
|
|
|
|
* Output information messages.
|
|
|
|
* @param msg Location and other information about the found error.
|
|
|
|
*/
|
2014-11-20 14:20:09 +01:00
|
|
|
virtual void reportInfo(const ErrorLogger::ErrorMessage &msg) {
|
2012-06-21 19:05:14 +02:00
|
|
|
reportErr(msg);
|
|
|
|
}
|
2012-06-18 23:15:48 +02:00
|
|
|
|
2011-02-16 02:12:15 +01:00
|
|
|
/**
|
|
|
|
* Report list of unmatched suppressions
|
|
|
|
* @param unmatched list of unmatched suppressions (from Settings::Suppressions::getUnmatched(Local|Global)Suppressions)
|
|
|
|
*/
|
2018-04-09 06:43:48 +02:00
|
|
|
void reportUnmatchedSuppressions(const std::list<Suppressions::Suppression> &unmatched);
|
2011-02-16 02:12:15 +01:00
|
|
|
|
2009-07-10 22:38:26 +02:00
|
|
|
static std::string callStackToString(const std::list<ErrorLogger::ErrorMessage::FileLocation> &callStack);
|
2015-12-07 18:11:13 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Convert XML-sensitive characters into XML entities
|
|
|
|
* @param str The input string containing XML-sensitive characters
|
2016-11-04 15:01:05 +01:00
|
|
|
* @return The output string containing XML entities
|
2015-12-07 18:11:13 +01:00
|
|
|
*/
|
|
|
|
static std::string toxml(const std::string &str);
|
2017-05-16 14:07:23 +02:00
|
|
|
|
|
|
|
static std::string plistHeader(const std::string &version, const std::vector<std::string> &files);
|
|
|
|
static std::string plistData(const ErrorLogger::ErrorMessage &msg);
|
|
|
|
static const char *plistFooter() {
|
|
|
|
return " </array>\r\n"
|
|
|
|
"</dict>\r\n"
|
|
|
|
"</plist>";
|
|
|
|
}
|
2009-02-19 18:57:27 +01:00
|
|
|
};
|
2009-07-13 10:16:31 +02:00
|
|
|
|
2018-12-28 13:11:54 +01:00
|
|
|
/** Replace substring. Example replaceStr("1,NR,3", "NR", "2") => "1,2,3" */
|
|
|
|
std::string replaceStr(std::string s, const std::string &from, const std::string &to);
|
|
|
|
|
2009-07-17 10:49:01 +02:00
|
|
|
/// @}
|
2013-09-04 20:59:49 +02:00
|
|
|
//---------------------------------------------------------------------------
|
|
|
|
#endif // errorloggerH
|