Uninitialized variables: Broke out the checking into separate file
This commit is contained in:
parent
df8a93bf97
commit
bc283d8b99
10
Makefile
10
Makefile
|
@ -32,6 +32,7 @@ LIBOBJ = lib/checkautovariables.o \
|
|||
lib/checkother.o \
|
||||
lib/checkpostfixoperator.o \
|
||||
lib/checkstl.o \
|
||||
lib/checkuninitvar.o \
|
||||
lib/checkunusedfunctions.o \
|
||||
lib/cppcheck.o \
|
||||
lib/errorlogger.o \
|
||||
|
@ -80,6 +81,7 @@ TESTOBJ = test/options.o \
|
|||
test/testthreadexecutor.o \
|
||||
test/testtoken.o \
|
||||
test/testtokenize.o \
|
||||
test/testuninitvar.o \
|
||||
test/testunusedfunctions.o \
|
||||
test/testunusedprivfunc.o \
|
||||
test/testunusedvar.o \
|
||||
|
@ -148,7 +150,7 @@ lib/checknullpointer.o: lib/checknullpointer.cpp lib/checknullpointer.h lib/chec
|
|||
lib/checkobsoletefunctions.o: lib/checkobsoletefunctions.cpp lib/checkobsoletefunctions.h lib/check.h lib/token.h lib/tokenize.h lib/settings.h lib/errorlogger.h
|
||||
$(CXX) $(CXXFLAGS) -Ilib -c -o lib/checkobsoletefunctions.o lib/checkobsoletefunctions.cpp
|
||||
|
||||
lib/checkother.o: lib/checkother.cpp lib/checkother.h lib/check.h lib/token.h lib/tokenize.h lib/settings.h lib/errorlogger.h lib/mathlib.h lib/executionpath.h lib/checknullpointer.h
|
||||
lib/checkother.o: lib/checkother.cpp lib/checkother.h lib/check.h lib/token.h lib/tokenize.h lib/settings.h lib/errorlogger.h lib/mathlib.h
|
||||
$(CXX) $(CXXFLAGS) -Ilib -c -o lib/checkother.o lib/checkother.cpp
|
||||
|
||||
lib/checkpostfixoperator.o: lib/checkpostfixoperator.cpp lib/checkpostfixoperator.h lib/check.h lib/token.h lib/tokenize.h lib/settings.h lib/errorlogger.h
|
||||
|
@ -157,6 +159,9 @@ lib/checkpostfixoperator.o: lib/checkpostfixoperator.cpp lib/checkpostfixoperato
|
|||
lib/checkstl.o: lib/checkstl.cpp lib/checkstl.h lib/check.h lib/token.h lib/tokenize.h lib/settings.h lib/errorlogger.h lib/executionpath.h
|
||||
$(CXX) $(CXXFLAGS) -Ilib -c -o lib/checkstl.o lib/checkstl.cpp
|
||||
|
||||
lib/checkuninitvar.o: lib/checkuninitvar.cpp lib/checkuninitvar.h lib/check.h lib/token.h lib/tokenize.h lib/settings.h lib/errorlogger.h lib/mathlib.h lib/executionpath.h lib/checknullpointer.h
|
||||
$(CXX) $(CXXFLAGS) -Ilib -c -o lib/checkuninitvar.o lib/checkuninitvar.cpp
|
||||
|
||||
lib/checkunusedfunctions.o: lib/checkunusedfunctions.cpp lib/checkunusedfunctions.h lib/check.h lib/token.h lib/tokenize.h lib/settings.h lib/errorlogger.h
|
||||
$(CXX) $(CXXFLAGS) -Ilib -c -o lib/checkunusedfunctions.o lib/checkunusedfunctions.cpp
|
||||
|
||||
|
@ -295,6 +300,9 @@ test/testtoken.o: test/testtoken.cpp test/testsuite.h lib/errorlogger.h test/red
|
|||
test/testtokenize.o: test/testtokenize.cpp test/testsuite.h lib/errorlogger.h test/redirect.h lib/tokenize.h lib/token.h lib/settings.h
|
||||
$(CXX) $(CXXFLAGS) -Ilib -Icli -c -o test/testtokenize.o test/testtokenize.cpp
|
||||
|
||||
test/testuninitvar.o: test/testuninitvar.cpp lib/tokenize.h lib/checkuninitvar.h lib/check.h lib/token.h lib/settings.h lib/errorlogger.h test/testsuite.h test/redirect.h
|
||||
$(CXX) $(CXXFLAGS) -Ilib -Icli -c -o test/testuninitvar.o test/testuninitvar.cpp
|
||||
|
||||
test/testunusedfunctions.o: test/testunusedfunctions.cpp lib/tokenize.h test/testsuite.h lib/errorlogger.h test/redirect.h lib/checkunusedfunctions.h lib/check.h lib/token.h lib/settings.h
|
||||
$(CXX) $(CXXFLAGS) -Ilib -Icli -c -o test/testunusedfunctions.o test/testunusedfunctions.cpp
|
||||
|
||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -82,23 +82,9 @@ public:
|
|||
|
||||
checkOther.checkSelfAssignment();
|
||||
checkOther.checkIncorrectLogicOperator();
|
||||
|
||||
// New type of check: Check execution paths
|
||||
checkOther.executionPaths();
|
||||
checkOther.checkMisusedScopedObject();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief Uninitialized variables: analyse functions to see how they work with uninitialized variables
|
||||
* @param tokens [in] the token list
|
||||
* @param func [out] names of functions that don't handle uninitialized variables well. the function names are added to the set. No clearing is made.
|
||||
*/
|
||||
void analyse(const Token * tokens, std::set<std::string> &func) const;
|
||||
|
||||
/** Save analysis results */
|
||||
void saveAnalysisData(const std::set<std::string> &data) const;
|
||||
|
||||
/** @brief Are there C-style pointer casts in a c++ file? */
|
||||
void warningOldStylePointerCast();
|
||||
|
||||
|
@ -138,9 +124,6 @@ public:
|
|||
/** @brief str plus char (unusual pointer arithmetic) */
|
||||
void strPlusChar();
|
||||
|
||||
/** @brief new type of check: check execution paths */
|
||||
void executionPaths();
|
||||
|
||||
/** @brief %Check zero division*/
|
||||
void checkZeroDivision();
|
||||
|
||||
|
@ -195,9 +178,6 @@ public:
|
|||
void variableScopeError(const Token *tok, const std::string &varname);
|
||||
void conditionAlwaysTrueFalse(const Token *tok, const std::string &truefalse);
|
||||
void strPlusChar(const Token *tok);
|
||||
void uninitstringError(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 zerodivError(const Token *tok);
|
||||
void mathfunctionCallError(const Token *tok, const unsigned int numParam = 1);
|
||||
void emptyStringTestError(const Token *tok, const std::string &var_name, const bool isTestForEmpty);
|
||||
|
@ -213,9 +193,6 @@ public:
|
|||
// error
|
||||
sprintfOverlappingDataError(0, "varname");
|
||||
udivError(0);
|
||||
uninitstringError(0, "varname");
|
||||
uninitdataError(0, "varname");
|
||||
uninitvarError(0, "varname");
|
||||
zerodivError(0);
|
||||
mathfunctionCallError(0);
|
||||
fflushOnInputStreamError(0, "stdin");
|
||||
|
@ -259,7 +236,6 @@ public:
|
|||
// error
|
||||
"* [[OverlappingData|bad usage of the function 'sprintf' (overlapping data)]]\n"
|
||||
"* division with zero\n"
|
||||
"* using uninitialized variables and data\n"
|
||||
"* using fflush() on an input stream\n"
|
||||
"* scoped object destroyed immediately after construction\n"
|
||||
"* assignment in an assert statement\n"
|
||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -0,0 +1,102 @@
|
|||
/*
|
||||
* Cppcheck - A tool for static C/C++ code analysis
|
||||
* Copyright (C) 2007-2010 Daniel Marjamäki and Cppcheck team.
|
||||
*
|
||||
* 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 checkuninitvarH
|
||||
#define checkuninitvarH
|
||||
//---------------------------------------------------------------------------
|
||||
|
||||
#include "check.h"
|
||||
#include "settings.h"
|
||||
|
||||
class Token;
|
||||
|
||||
/// @addtogroup Checks
|
||||
/// @{
|
||||
|
||||
|
||||
/** @brief Checking for uninitialized variables */
|
||||
|
||||
class CheckUninitVar : public Check
|
||||
{
|
||||
public:
|
||||
/** @brief This constructor is used when registering the CheckUninitVar */
|
||||
CheckUninitVar() : Check()
|
||||
{ }
|
||||
|
||||
/** @brief This constructor is used when running checks. */
|
||||
CheckUninitVar(const Tokenizer *tokenizer, const Settings *settings, ErrorLogger *errorLogger)
|
||||
: Check(tokenizer, settings, errorLogger)
|
||||
{ }
|
||||
|
||||
/** @brief Run checks against the normal token list */
|
||||
void runChecks(const Tokenizer *tokenizer, const Settings *settings, ErrorLogger *errorLogger)
|
||||
{
|
||||
(void)tokenizer;
|
||||
(void)settings;
|
||||
(void)errorLogger;
|
||||
}
|
||||
|
||||
/** @brief Run checks against the simplified token list */
|
||||
void runSimplifiedChecks(const Tokenizer *tokenizer, const Settings *settings, ErrorLogger *errorLogger)
|
||||
{
|
||||
CheckUninitVar checkUninitVar(tokenizer, settings, errorLogger);
|
||||
checkUninitVar.executionPaths();
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Uninitialized variables: analyse functions to see how they work with uninitialized variables
|
||||
* @param tokens [in] the token list
|
||||
* @param func [out] names of functions that don't handle uninitialized variables well. the function names are added to the set. No clearing is made.
|
||||
*/
|
||||
void analyse(const Token * tokens, std::set<std::string> &func) const;
|
||||
|
||||
/** Save analysis results */
|
||||
void saveAnalysisData(const std::set<std::string> &data) const;
|
||||
|
||||
/** @brief new type of check: check execution paths */
|
||||
void executionPaths();
|
||||
|
||||
void uninitstringError(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 getErrorMessages()
|
||||
{
|
||||
// error
|
||||
uninitstringError(0, "varname");
|
||||
uninitdataError(0, "varname");
|
||||
uninitvarError(0, "varname");
|
||||
}
|
||||
|
||||
std::string name() const
|
||||
{
|
||||
return "Uninitialized variables";
|
||||
}
|
||||
|
||||
std::string classInfo() const
|
||||
{
|
||||
return "Uninitialized variables\n"
|
||||
"* using uninitialized variables and data\n";
|
||||
}
|
||||
};
|
||||
/// @}
|
||||
//---------------------------------------------------------------------------
|
||||
#endif
|
||||
|
|
@ -11,6 +11,7 @@ HEADERS += $$PWD/check.h \
|
|||
$$PWD/checkother.h \
|
||||
$$PWD/checkpostfixoperator.h \
|
||||
$$PWD/checkstl.h \
|
||||
$$PWD/checkuninitvar.h \
|
||||
$$PWD/checkunusedfunctions.h \
|
||||
$$PWD/cppcheck.h \
|
||||
$$PWD/errorlogger.h \
|
||||
|
@ -36,6 +37,7 @@ SOURCES += $$PWD/checkautovariables.cpp \
|
|||
$$PWD/checkother.cpp \
|
||||
$$PWD/checkpostfixoperator.cpp \
|
||||
$$PWD/checkstl.cpp \
|
||||
$$PWD/checkuninitvar.cpp \
|
||||
$$PWD/checkunusedfunctions.cpp \
|
||||
$$PWD/cppcheck.cpp \
|
||||
$$PWD/errorlogger.cpp \
|
||||
|
|
1200
test/testother.cpp
1200
test/testother.cpp
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue