"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "lib/checkuninitvar.h" between
cppcheck-1.86.tar.gz and cppcheck-1.87.tar.gz

About: Cppcheck is a static analysis tool for C/C++ code. It checks for memory leaks, mismatching allocation-deallocation, buffer overrun, and many more.

checkuninitvar.h  (cppcheck-1.86):checkuninitvar.h  (cppcheck-1.87)
/* /*
* Cppcheck - A tool for static C/C++ code analysis * Cppcheck - A tool for static C/C++ code analysis
* Copyright (C) 2007-2018 Cppcheck team. * Copyright (C) 2007-2019 Cppcheck team.
* *
* This program is free software: you can redistribute it and/or modify * 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 * it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or * the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version. * (at your option) any later version.
* *
* This program is distributed in the hope that it will be useful, * This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of * but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details. * GNU General Public License for more details.
skipping to change at line 26 skipping to change at line 26
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
//--------------------------------------------------------------------------- //---------------------------------------------------------------------------
#ifndef checkuninitvarH #ifndef checkuninitvarH
#define checkuninitvarH #define checkuninitvarH
//--------------------------------------------------------------------------- //---------------------------------------------------------------------------
#include "check.h" #include "check.h"
#include "config.h" #include "config.h"
#include "ctu.h"
#include <set> #include <set>
#include <string> #include <string>
class ErrorLogger; class ErrorLogger;
class Scope; class Scope;
class Settings; class Settings;
class Token; class Token;
class Tokenizer; class Tokenizer;
class Variable; class Variable;
skipping to change at line 60 skipping to change at line 61
/** @brief This constructor is used when registering the CheckUninitVar */ /** @brief This constructor is used when registering the CheckUninitVar */
CheckUninitVar() : Check(myName()) { CheckUninitVar() : Check(myName()) {
} }
/** @brief This constructor is used when running checks. */ /** @brief This constructor is used when running checks. */
CheckUninitVar(const Tokenizer *tokenizer, const Settings *settings, ErrorLo gger *errorLogger) CheckUninitVar(const Tokenizer *tokenizer, const Settings *settings, ErrorLo gger *errorLogger)
: Check(myName(), tokenizer, settings, errorLogger) { : Check(myName(), tokenizer, settings, errorLogger) {
} }
/** @brief Run checks against the simplified token list */ /** @brief Run checks against the simplified token list */
void runSimplifiedChecks(const Tokenizer *tokenizer, const Settings *setting s, ErrorLogger *errorLogger) override { void runSimplifiedChecks(const Tokenizer *tokenizer, const Settings *setting s, ErrorLogger *errorLogger) OVERRIDE {
CheckUninitVar checkUninitVar(tokenizer, settings, errorLogger); CheckUninitVar checkUninitVar(tokenizer, settings, errorLogger);
checkUninitVar.check(); checkUninitVar.check();
checkUninitVar.deadPointer(); checkUninitVar.deadPointer();
checkUninitVar.valueFlowUninit(); checkUninitVar.valueFlowUninit();
} }
/** Check for uninitialized variables */ /** Check for uninitialized variables */
void check(); void check();
void checkScope(const Scope* scope, const std::set<std::string> &arrayTypeDe fs); void checkScope(const Scope* scope, const std::set<std::string> &arrayTypeDe fs);
void checkStruct(const Token *tok, const Variable &structvar); void checkStruct(const Token *tok, const Variable &structvar);
skipping to change at line 88 skipping to change at line 89
bool isMemberVariableAssignment(const Token *tok, const std::string &memberv ar) const; bool isMemberVariableAssignment(const Token *tok, const std::string &memberv ar) const;
bool isMemberVariableUsage(const Token *tok, bool isPointer, Alloc alloc, co nst std::string &membervar) const; bool isMemberVariableUsage(const Token *tok, bool isPointer, Alloc alloc, co nst std::string &membervar) const;
/** ValueFlow-based checking for dead pointer usage */ /** ValueFlow-based checking for dead pointer usage */
void deadPointer(); void deadPointer();
void deadPointerError(const Token *pointer, const Token *alias); void deadPointerError(const Token *pointer, const Token *alias);
/** ValueFlow-based checking for uninitialized variables */ /** ValueFlow-based checking for uninitialized variables */
void valueFlowUninit(); void valueFlowUninit();
/* data for multifile checking */
class MyFileInfo : public Check::FileInfo {
public:
/** function arguments that data are unconditionally read */
std::list<CTU::FileInfo::UnsafeUsage> unsafeUsage;
/** Convert MyFileInfo data into xml string */
std::string toString() const OVERRIDE;
};
/** @brief Parse current TU and extract file info */
Check::FileInfo *getFileInfo(const Tokenizer *tokenizer, const Settings *set
tings) const OVERRIDE;
Check::FileInfo * loadFileInfoFromXml(const tinyxml2::XMLElement *xmlElement
) const OVERRIDE;
/** @brief Analyse all file infos for all TU */
bool analyseWholeProgram(const CTU::FileInfo *ctu, const std::list<Check::Fi
leInfo*> &fileInfo, const Settings& settings, ErrorLogger &errorLogger) OVERRIDE
;
void uninitstringError(const Token *tok, const std::string &varname, bool st rncpy_); void uninitstringError(const Token *tok, const std::string &varname, bool st rncpy_);
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 uninitvarError(const Token *tok, const std::string &varname, Alloc allo c) { void uninitvarError(const Token *tok, const std::string &varname, Alloc allo c) {
if (alloc == NO_CTOR_CALL || alloc == CTOR_CALL) if (alloc == NO_CTOR_CALL || alloc == CTOR_CALL)
uninitdataError(tok, varname); uninitdataError(tok, varname);
else else
uninitvarError(tok, varname); uninitvarError(tok, varname);
} }
void uninitStructMemberError(const Token *tok, const std::string &membername ); void uninitStructMemberError(const Token *tok, const std::string &membername );
private: private:
void getErrorMessages(ErrorLogger *errorLogger, const Settings *settings) co Check::FileInfo *getFileInfo() const;
nst override { bool isUnsafeFunction(const Scope *scope, int argnr, const Token **tok) cons
t;
void getErrorMessages(ErrorLogger *errorLogger, const Settings *settings) co
nst OVERRIDE {
CheckUninitVar c(nullptr, settings, errorLogger); CheckUninitVar c(nullptr, settings, errorLogger);
// error // error
c.uninitstringError(nullptr, "varname", true); c.uninitstringError(nullptr, "varname", true);
c.uninitdataError(nullptr, "varname"); c.uninitdataError(nullptr, "varname");
c.uninitvarError(nullptr, "varname"); c.uninitvarError(nullptr, "varname");
c.uninitStructMemberError(nullptr, "a.b"); c.uninitStructMemberError(nullptr, "a.b");
c.deadPointerError(nullptr, nullptr); c.deadPointerError(nullptr, nullptr);
} }
static std::string myName() { static std::string myName() {
return "Uninitialized variables"; return "Uninitialized variables";
} }
std::string classInfo() const override { std::string classInfo() const OVERRIDE {
return "Uninitialized variables\n" return "Uninitialized variables\n"
"- using uninitialized local variables\n" "- using uninitialized local variables\n"
"- using allocated data before it has been initialized\n" "- using allocated data before it has been initialized\n"
"- using dead pointer\n"; "- using dead pointer\n";
} }
}; };
/// @} /// @}
//--------------------------------------------------------------------------- //---------------------------------------------------------------------------
#endif // checkuninitvarH #endif // checkuninitvarH
 End of changes. 6 change blocks. 
5 lines changed or deleted 32 lines changed or added

Home  |  About  |  Features  |  All  |  Newest  |  Dox  |  Diffs  |  RSS Feeds  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTP(S)