2014-08-06 14:20:46 +02:00
|
|
|
/*
|
|
|
|
* Cppcheck - A tool for static C/C++ code analysis
|
2022-05-21 12:18:27 +02:00
|
|
|
* Copyright (C) 2007-2022 Cppcheck team.
|
2014-08-06 14:20:46 +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 checkvaargtH
|
|
|
|
#define checkvaargtH
|
|
|
|
//---------------------------------------------------------------------------
|
|
|
|
|
|
|
|
#include "check.h"
|
2017-05-27 04:33:47 +02:00
|
|
|
#include "config.h"
|
2023-08-18 12:03:50 +02:00
|
|
|
#include "tokenize.h"
|
2017-05-27 04:33:47 +02:00
|
|
|
|
|
|
|
#include <string>
|
|
|
|
|
|
|
|
class ErrorLogger;
|
|
|
|
class Settings;
|
|
|
|
class Token;
|
2014-08-06 14:20:46 +02:00
|
|
|
|
|
|
|
/// @addtogroup Checks
|
|
|
|
/// @{
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Checking for misusage of variable argument lists
|
|
|
|
*/
|
|
|
|
|
|
|
|
class CPPCHECKLIB CheckVaarg : public Check {
|
|
|
|
public:
|
2021-08-07 20:51:18 +02:00
|
|
|
CheckVaarg() : Check(myName()) {}
|
2014-08-06 14:20:46 +02:00
|
|
|
|
|
|
|
CheckVaarg(const Tokenizer *tokenizer, const Settings *settings, ErrorLogger *errorLogger)
|
2021-08-07 20:51:18 +02:00
|
|
|
: Check(myName(), tokenizer, settings, errorLogger) {}
|
2014-08-06 14:20:46 +02:00
|
|
|
|
2023-08-18 12:03:50 +02:00
|
|
|
void runChecks(const Tokenizer &tokenizer, ErrorLogger *errorLogger) override {
|
|
|
|
CheckVaarg check(&tokenizer, tokenizer.getSettings(), errorLogger);
|
2014-08-06 14:20:46 +02:00
|
|
|
check.va_start_argument();
|
|
|
|
check.va_list_usage();
|
|
|
|
}
|
|
|
|
|
|
|
|
void va_start_argument();
|
|
|
|
void va_list_usage();
|
|
|
|
|
|
|
|
private:
|
|
|
|
void wrongParameterTo_va_start_error(const Token *tok, const std::string& paramIsName, const std::string& paramShouldName);
|
|
|
|
void referenceAs_va_start_error(const Token *tok, const std::string& paramName);
|
|
|
|
void va_end_missingError(const Token *tok, const std::string& varname);
|
|
|
|
void va_list_usedBeforeStartedError(const Token *tok, const std::string& varname);
|
|
|
|
void va_start_subsequentCallsError(const Token *tok, const std::string& varname);
|
|
|
|
|
2022-02-10 23:02:24 +01:00
|
|
|
void getErrorMessages(ErrorLogger *errorLogger, const Settings *settings) const override {
|
2016-05-07 16:30:54 +02:00
|
|
|
CheckVaarg c(nullptr, settings, errorLogger);
|
|
|
|
c.wrongParameterTo_va_start_error(nullptr, "arg1", "arg2");
|
|
|
|
c.referenceAs_va_start_error(nullptr, "arg1");
|
|
|
|
c.va_end_missingError(nullptr, "vl");
|
|
|
|
c.va_list_usedBeforeStartedError(nullptr, "vl");
|
|
|
|
c.va_start_subsequentCallsError(nullptr, "vl");
|
2014-08-06 14:20:46 +02:00
|
|
|
}
|
|
|
|
|
2014-11-20 14:20:09 +01:00
|
|
|
static std::string myName() {
|
2014-09-30 14:56:12 +02:00
|
|
|
return "Vaarg";
|
2014-08-06 14:20:46 +02:00
|
|
|
}
|
|
|
|
|
2022-02-10 23:02:24 +01:00
|
|
|
std::string classInfo() const override {
|
2014-08-06 14:20:46 +02:00
|
|
|
return "Check for misusage of variable argument lists:\n"
|
2014-09-30 14:56:12 +02:00
|
|
|
"- Wrong parameter passed to va_start()\n"
|
|
|
|
"- Reference passed to va_start()\n"
|
|
|
|
"- Missing va_end()\n"
|
|
|
|
"- Using va_list before it is opened\n"
|
|
|
|
"- Subsequent calls to va_start/va_copy()\n";
|
2014-08-06 14:20:46 +02:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
/// @}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------
|
|
|
|
#endif // checkvaargtH
|