2009-02-19 18:57:27 +01:00
|
|
|
/*
|
|
|
|
* Cppcheck - A tool for static C/C++ code analysis
|
2010-04-13 21:23:17 +02:00
|
|
|
* Copyright (C) 2007-2010 Daniel Marjamäki and 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
|
|
|
*/
|
|
|
|
|
|
|
|
// THIS FILE IS GENERATED BY MACHINE, SEE ../tools/errmsg.cpp !
|
|
|
|
|
|
|
|
#ifndef errorloggerH
|
|
|
|
#define errorloggerH
|
|
|
|
#include <list>
|
|
|
|
#include <string>
|
|
|
|
#include "settings.h"
|
|
|
|
class Token;
|
|
|
|
class Tokenizer;
|
|
|
|
|
2009-07-17 10:49:01 +02:00
|
|
|
/// @addtogroup Core
|
|
|
|
/// @{
|
|
|
|
|
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.
|
|
|
|
*/
|
|
|
|
class ErrorLogger
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Wrapper for error messages, provided by reportErr()
|
|
|
|
*/
|
|
|
|
class ErrorMessage
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
/**
|
|
|
|
* File name and line number.
|
|
|
|
*/
|
|
|
|
class FileLocation
|
|
|
|
{
|
|
|
|
public:
|
2009-03-01 20:38:17 +01:00
|
|
|
FileLocation()
|
|
|
|
{
|
|
|
|
line = 0;
|
|
|
|
}
|
2009-05-31 10:12:19 +02:00
|
|
|
|
|
|
|
std::string getfile() const;
|
2009-02-19 18:57:27 +01:00
|
|
|
std::string file;
|
|
|
|
unsigned int line;
|
|
|
|
};
|
|
|
|
|
|
|
|
ErrorMessage(const std::list<FileLocation> &callStack, const std::string &severity, const std::string &msg, const std::string &id);
|
2009-02-19 23:21:18 +01:00
|
|
|
ErrorMessage();
|
2009-02-19 18:57:27 +01:00
|
|
|
std::string toXML() const;
|
2009-06-15 20:36:39 +02:00
|
|
|
|
|
|
|
static std::string getXMLHeader();
|
|
|
|
static std::string getXMLFooter();
|
|
|
|
|
2009-09-05 21:01:49 +02:00
|
|
|
/**
|
|
|
|
* Format the error message into a string.
|
|
|
|
* @param outputFormat Empty string to use default output format
|
|
|
|
* or template to be used. E.g. "{file}:{line},{severity},{id},{message}"
|
|
|
|
*/
|
|
|
|
std::string toText(const std::string &outputFormat = "") const;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Replace all occurances of searchFor with replaceWith in the
|
|
|
|
* 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);
|
2009-02-19 23:21:18 +01:00
|
|
|
std::string serialize() const;
|
2009-02-20 07:28:18 +01:00
|
|
|
bool deserialize(const std::string &data);
|
2009-02-19 18:57:27 +01:00
|
|
|
std::list<FileLocation> _callStack;
|
|
|
|
std::string _severity;
|
|
|
|
std::string _msg;
|
|
|
|
std::string _id;
|
|
|
|
};
|
|
|
|
|
2009-07-10 22:38:26 +02:00
|
|
|
ErrorLogger() { }
|
2009-02-19 18:57:27 +01:00
|
|
|
virtual ~ErrorLogger() { }
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 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.
|
|
|
|
*
|
|
|
|
* @param msg Location and other information about the found.
|
|
|
|
* error
|
|
|
|
*/
|
|
|
|
virtual void reportErr(const ErrorLogger::ErrorMessage &msg) = 0;
|
|
|
|
|
2009-02-19 23:21:18 +01:00
|
|
|
/**
|
|
|
|
* Information about how many files have been checked
|
|
|
|
*
|
|
|
|
* @param index This many files have been checked.
|
|
|
|
* @param max This many files there are in total.
|
|
|
|
*/
|
|
|
|
virtual void reportStatus(unsigned int index, unsigned int max) = 0;
|
|
|
|
|
2009-02-19 18:57:27 +01:00
|
|
|
static bool outOfBounds()
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool stlOutOfBounds()
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool noConstructor(const Settings &s)
|
|
|
|
{
|
|
|
|
return s._checkCodingStyle;
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool uninitVar(const Settings &s)
|
|
|
|
{
|
|
|
|
return s._checkCodingStyle;
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool unusedPrivateFunction(const Settings &s)
|
|
|
|
{
|
|
|
|
return s._checkCodingStyle;
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool memsetClass()
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool memsetStruct()
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool operatorEq(const Settings &s)
|
|
|
|
{
|
|
|
|
return s._checkCodingStyle;
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool virtualDestructor()
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void unusedFunction(const std::string &filename, const std::string &funcname)
|
|
|
|
{
|
2009-06-09 22:45:31 +02:00
|
|
|
std::list<ErrorLogger::ErrorMessage::FileLocation> loc;
|
|
|
|
ErrorLogger::ErrorMessage::FileLocation fileLoc;
|
|
|
|
fileLoc.file = filename;
|
|
|
|
fileLoc.line = 1;
|
|
|
|
loc.push_back(fileLoc);
|
|
|
|
reportErr(ErrorLogger::ErrorMessage(loc, "style", "The function '" + funcname + "' is never used", "unusedFunction"));
|
2009-02-19 18:57:27 +01:00
|
|
|
}
|
2009-06-09 22:45:31 +02:00
|
|
|
|
2009-03-21 21:33:27 +01:00
|
|
|
|
2009-02-19 18:57:27 +01:00
|
|
|
static bool mismatchAllocDealloc()
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool memleak()
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool resourceLeak()
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool deallocDealloc()
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool deallocuse()
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool mismatchSize()
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool cstyleCast(const Settings &s)
|
|
|
|
{
|
|
|
|
return s._checkCodingStyle;
|
|
|
|
}
|
|
|
|
|
2009-03-21 17:58:13 +01:00
|
|
|
|
2009-02-19 18:57:27 +01:00
|
|
|
static bool redundantIfDelete0(const Settings &s)
|
|
|
|
{
|
|
|
|
return s._checkCodingStyle;
|
|
|
|
}
|
|
|
|
|
2009-03-21 17:58:13 +01:00
|
|
|
|
2009-02-19 18:57:27 +01:00
|
|
|
static bool redundantIfRemove(const Settings &s)
|
|
|
|
{
|
|
|
|
return s._checkCodingStyle;
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool dangerousUsageStrtol()
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool ifNoAction(const Settings &s)
|
|
|
|
{
|
|
|
|
return s._checkCodingStyle;
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool sprintfOverlappingData()
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2009-03-21 17:58:13 +01:00
|
|
|
|
2009-02-19 18:57:27 +01:00
|
|
|
static bool udivError()
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2009-03-21 17:58:13 +01:00
|
|
|
|
2009-02-19 18:57:27 +01:00
|
|
|
static bool unusedStructMember(const Settings &s)
|
|
|
|
{
|
|
|
|
return s._checkCodingStyle;
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool passedByValue(const Settings &s)
|
|
|
|
{
|
|
|
|
return s._checkCodingStyle;
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool constStatement(const Settings &s)
|
|
|
|
{
|
|
|
|
return s._checkCodingStyle;
|
|
|
|
}
|
|
|
|
|
2009-03-21 17:58:13 +01:00
|
|
|
|
2009-02-19 18:57:27 +01:00
|
|
|
static bool charArrayIndex(const Settings &s)
|
|
|
|
{
|
|
|
|
return s._checkCodingStyle;
|
|
|
|
}
|
|
|
|
|
2009-03-21 17:58:13 +01:00
|
|
|
|
2009-02-19 18:57:27 +01:00
|
|
|
static bool charBitOp(const Settings &s)
|
|
|
|
{
|
|
|
|
return s._checkCodingStyle;
|
|
|
|
}
|
|
|
|
|
2009-03-21 17:58:13 +01:00
|
|
|
|
2009-02-19 18:57:27 +01:00
|
|
|
static bool variableScope()
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool conditionAlwaysTrueFalse(const Settings &s)
|
|
|
|
{
|
|
|
|
return s._checkCodingStyle;
|
|
|
|
}
|
|
|
|
|
2009-03-21 17:58:13 +01:00
|
|
|
|
2009-02-19 18:57:27 +01:00
|
|
|
static bool strPlusChar()
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2009-03-21 17:58:13 +01:00
|
|
|
|
2009-02-19 18:57:27 +01:00
|
|
|
static bool returnLocalVariable()
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2009-03-21 18:31:28 +01:00
|
|
|
|
2009-02-19 18:57:27 +01:00
|
|
|
static bool dangerousFunctionmktemp(const Settings &s)
|
|
|
|
{
|
|
|
|
return s._checkCodingStyle;
|
|
|
|
}
|
|
|
|
|
2009-03-21 18:31:28 +01:00
|
|
|
|
2009-02-19 18:57:27 +01:00
|
|
|
static bool dangerousFunctiongets(const Settings &s)
|
|
|
|
{
|
|
|
|
return s._checkCodingStyle;
|
|
|
|
}
|
|
|
|
|
2009-03-21 18:31:28 +01:00
|
|
|
|
2009-02-19 18:57:27 +01:00
|
|
|
static bool dangerousFunctionscanf(const Settings &s)
|
|
|
|
{
|
|
|
|
return s._checkCodingStyle;
|
|
|
|
}
|
|
|
|
|
2009-03-21 18:31:28 +01:00
|
|
|
|
2009-07-10 22:38:26 +02:00
|
|
|
static std::string callStackToString(const std::list<ErrorLogger::ErrorMessage::FileLocation> &callStack);
|
2009-02-19 18:57:27 +01:00
|
|
|
|
|
|
|
private:
|
2009-03-01 20:30:51 +01:00
|
|
|
void _writemsg(const Tokenizer *tokenizer, const Token *tok, const char severity[], const std::string &msg, const std::string &id);
|
|
|
|
void _writemsg(const Tokenizer *tokenizer, const std::list<const Token *> &callstack, const char severity[], const std::string &msg, const std::string &id);
|
2009-02-19 18:57:27 +01:00
|
|
|
};
|
2009-07-13 10:16:31 +02:00
|
|
|
|
2010-03-13 21:49:09 +01:00
|
|
|
/** @brief enum class for severity. Used when reporting errors. */
|
2009-07-13 10:16:31 +02:00
|
|
|
class Severity
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
enum e { error, style, possibleError, possibleStyle };
|
|
|
|
static std::string stringify(e severity)
|
|
|
|
{
|
2010-04-02 07:30:58 +02:00
|
|
|
switch (severity)
|
2009-07-13 10:16:31 +02:00
|
|
|
{
|
2009-07-13 15:51:35 +02:00
|
|
|
case error:
|
|
|
|
return "error";
|
|
|
|
case style:
|
|
|
|
return "style";
|
|
|
|
case possibleError:
|
|
|
|
return "possible error";
|
|
|
|
case possibleStyle:
|
|
|
|
return "possible style";
|
2009-07-13 10:16:31 +02:00
|
|
|
};
|
|
|
|
return "???";
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2009-07-17 10:49:01 +02:00
|
|
|
/// @}
|
|
|
|
|
2009-02-19 18:57:27 +01:00
|
|
|
#endif
|