2014-09-23 21:00:23 +02:00
|
|
|
/*
|
|
|
|
* Cppcheck - A tool for static C/C++ code analysis
|
2015-01-03 12:14:58 +01:00
|
|
|
* Copyright (C) 2007-2015 Daniel Marjamäki and Cppcheck team.
|
2014-09-23 21:00:23 +02: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
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------
|
|
|
|
#ifndef checkobsoletefunctionsH
|
|
|
|
#define checkobsoletefunctionsH
|
|
|
|
//---------------------------------------------------------------------------
|
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
#include "check.h"
|
|
|
|
#include <string>
|
|
|
|
#include <map>
|
|
|
|
|
|
|
|
|
|
|
|
/// @addtogroup Checks
|
|
|
|
/// @{
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Using obsolete functions that are always insecure to use.
|
|
|
|
*/
|
|
|
|
|
|
|
|
class CPPCHECKLIB CheckObsoleteFunctions : public Check {
|
|
|
|
public:
|
|
|
|
/** This constructor is used when registering the CheckObsoleteFunctions */
|
2014-11-20 14:20:09 +01:00
|
|
|
CheckObsoleteFunctions() : Check(myName()) {
|
2014-09-23 21:00:23 +02:00
|
|
|
initObsoleteFunctions();
|
|
|
|
}
|
|
|
|
|
|
|
|
/** This constructor is used when running checks. */
|
|
|
|
CheckObsoleteFunctions(const Tokenizer *tokenizer, const Settings *settings, ErrorLogger *errorLogger)
|
2014-11-20 14:20:09 +01:00
|
|
|
: Check(myName(), tokenizer, settings, errorLogger) {
|
2015-11-06 22:49:02 +01:00
|
|
|
initObsoleteFunctions();
|
2014-09-23 21:00:23 +02:00
|
|
|
}
|
|
|
|
|
2014-11-20 14:20:09 +01:00
|
|
|
void runSimplifiedChecks(const Tokenizer *tokenizer, const Settings *settings, ErrorLogger *errorLogger) {
|
2014-09-23 21:00:23 +02:00
|
|
|
CheckObsoleteFunctions checkObsoleteFunctions(tokenizer, settings, errorLogger);
|
|
|
|
checkObsoleteFunctions.obsoleteFunctions();
|
|
|
|
}
|
|
|
|
|
|
|
|
/** Check for obsolete functions */
|
|
|
|
void obsoleteFunctions();
|
|
|
|
|
|
|
|
private:
|
|
|
|
/* function name / error message */
|
2015-11-06 22:49:02 +01:00
|
|
|
std::map<std::string, std::string> _obsoleteStandardFunctions;
|
|
|
|
std::map<std::string, std::string> _obsoletePosixFunctions;
|
|
|
|
std::map<std::string, std::string> _obsoleteC99Functions;
|
2014-09-23 21:00:23 +02:00
|
|
|
|
|
|
|
/** init obsolete functions list ' */
|
2015-11-06 22:49:02 +01:00
|
|
|
void initObsoleteFunctions();
|
2014-09-23 21:00:23 +02:00
|
|
|
|
2014-11-20 14:20:09 +01:00
|
|
|
void getErrorMessages(ErrorLogger *errorLogger, const Settings *settings) const {
|
2014-09-23 21:00:23 +02:00
|
|
|
CheckObsoleteFunctions c(0, settings, errorLogger);
|
|
|
|
|
2015-08-11 14:57:05 +02:00
|
|
|
for (std::map<std::string, std::string>::const_iterator it = _obsoleteStandardFunctions.begin(); it != _obsoleteStandardFunctions.end(); ++it)
|
|
|
|
c.reportError(0, Severity::style, "obsoleteFunctions" + it->first, it->second);
|
|
|
|
for (std::map<std::string, std::string>::const_iterator it = _obsoleteC99Functions.begin(); it != _obsoleteC99Functions.end(); ++it)
|
|
|
|
c.reportError(0, Severity::style, "obsoleteFunctions" + it->first, it->second);
|
|
|
|
for (std::map<std::string, std::string>::const_iterator it = _obsoletePosixFunctions.begin(); it != _obsoletePosixFunctions.end(); ++it)
|
|
|
|
c.reportError(0, Severity::style, "obsoleteFunctions" + it->first, it->second);
|
2014-09-23 21:00:23 +02:00
|
|
|
}
|
|
|
|
|
2014-11-20 14:20:09 +01:00
|
|
|
static std::string myName() {
|
2014-09-23 21:00:23 +02:00
|
|
|
return "Obsolete functions";
|
|
|
|
}
|
|
|
|
|
2014-11-20 14:20:09 +01:00
|
|
|
std::string classInfo() const {
|
2014-09-23 21:00:23 +02:00
|
|
|
std::string info = "Warn if any of these obsolete functions are used:\n";
|
2015-08-11 14:57:05 +02:00
|
|
|
for (std::map<std::string, std::string>::const_iterator it = _obsoleteStandardFunctions.begin(); it != _obsoleteStandardFunctions.end(); ++it)
|
|
|
|
info += "- " + it->first + "\n";
|
|
|
|
for (std::map<std::string, std::string>::const_iterator it = _obsoleteC99Functions.begin(); it != _obsoleteC99Functions.end(); ++it)
|
|
|
|
info += "- " + it->first + "\n";
|
|
|
|
for (std::map<std::string, std::string>::const_iterator it = _obsoletePosixFunctions.begin(); it != _obsoletePosixFunctions.end(); ++it)
|
2014-10-18 21:20:29 +02:00
|
|
|
info += "- " + it->first + "\n";
|
2014-09-23 21:00:23 +02:00
|
|
|
return info;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
/// @}
|
|
|
|
//---------------------------------------------------------------------------
|
|
|
|
#endif // checkobsoletefunctionsH
|