moved `MyFileInfo` definitions into source files (#4697)

This commit is contained in:
Oliver Stöneberg 2023-10-21 16:58:29 +02:00 committed by GitHub
parent 26ba29c303
commit 09785a4eb8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
10 changed files with 103 additions and 99 deletions

View File

@ -458,7 +458,7 @@ validateRules:
###### Build
$(libcppdir)/valueflow.o: lib/valueflow.cpp lib/addoninfo.h lib/analyzer.h lib/astutils.h lib/calculate.h lib/check.h lib/checkuninitvar.h lib/color.h lib/config.h lib/ctu.h lib/errorlogger.h lib/errortypes.h lib/findtoken.h lib/forwardanalyzer.h lib/importproject.h lib/infer.h lib/library.h lib/mathlib.h lib/path.h lib/platform.h lib/programmemory.h lib/reverseanalyzer.h lib/settings.h lib/smallvector.h lib/sourcelocation.h lib/standards.h lib/suppressions.h lib/symboldatabase.h lib/templatesimplifier.h lib/timer.h lib/token.h lib/tokenize.h lib/tokenlist.h lib/utils.h lib/valueflow.h lib/valueptr.h lib/vfvalue.h
$(libcppdir)/valueflow.o: lib/valueflow.cpp lib/addoninfo.h lib/analyzer.h lib/astutils.h lib/calculate.h lib/check.h lib/checkuninitvar.h lib/color.h lib/config.h lib/errorlogger.h lib/errortypes.h lib/findtoken.h lib/forwardanalyzer.h lib/importproject.h lib/infer.h lib/library.h lib/mathlib.h lib/path.h lib/platform.h lib/programmemory.h lib/reverseanalyzer.h lib/settings.h lib/smallvector.h lib/sourcelocation.h lib/standards.h lib/suppressions.h lib/symboldatabase.h lib/templatesimplifier.h lib/timer.h lib/token.h lib/tokenize.h lib/tokenlist.h lib/utils.h lib/valueflow.h lib/valueptr.h lib/vfvalue.h
$(CXX) ${INCLUDE_FOR_LIB} $(CPPFLAGS) $(CXXFLAGS) -c -o $@ $(libcppdir)/valueflow.cpp
$(libcppdir)/tokenize.o: lib/tokenize.cpp externals/simplecpp/simplecpp.h lib/addoninfo.h lib/check.h lib/color.h lib/config.h lib/errorlogger.h lib/errortypes.h lib/importproject.h lib/library.h lib/mathlib.h lib/platform.h lib/preprocessor.h lib/settings.h lib/sourcelocation.h lib/standards.h lib/summaries.h lib/suppressions.h lib/symboldatabase.h lib/templatesimplifier.h lib/timer.h lib/token.h lib/tokenize.h lib/tokenlist.h lib/utils.h lib/valueflow.h lib/vfvalue.h
@ -521,7 +521,7 @@ $(libcppdir)/checkinternal.o: lib/checkinternal.cpp lib/addoninfo.h lib/astutils
$(libcppdir)/checkio.o: lib/checkio.cpp lib/addoninfo.h lib/check.h lib/checkio.h lib/config.h lib/errortypes.h lib/importproject.h lib/library.h lib/mathlib.h lib/platform.h lib/settings.h lib/sourcelocation.h lib/standards.h lib/suppressions.h lib/symboldatabase.h lib/templatesimplifier.h lib/token.h lib/tokenize.h lib/tokenlist.h lib/utils.h lib/vfvalue.h
$(CXX) ${INCLUDE_FOR_LIB} $(CPPFLAGS) $(CXXFLAGS) -c -o $@ $(libcppdir)/checkio.cpp
$(libcppdir)/checkleakautovar.o: lib/checkleakautovar.cpp lib/addoninfo.h lib/astutils.h lib/check.h lib/checkleakautovar.h lib/checkmemoryleak.h lib/checknullpointer.h lib/color.h lib/config.h lib/ctu.h lib/errorlogger.h lib/errortypes.h lib/importproject.h lib/library.h lib/mathlib.h lib/platform.h lib/settings.h lib/smallvector.h lib/sourcelocation.h lib/standards.h lib/suppressions.h lib/symboldatabase.h lib/templatesimplifier.h lib/token.h lib/tokenize.h lib/tokenlist.h lib/utils.h lib/vfvalue.h
$(libcppdir)/checkleakautovar.o: lib/checkleakautovar.cpp lib/addoninfo.h lib/astutils.h lib/check.h lib/checkleakautovar.h lib/checkmemoryleak.h lib/checknullpointer.h lib/config.h lib/errortypes.h lib/importproject.h lib/library.h lib/mathlib.h lib/platform.h lib/settings.h lib/smallvector.h lib/sourcelocation.h lib/standards.h lib/suppressions.h lib/symboldatabase.h lib/templatesimplifier.h lib/token.h lib/tokenize.h lib/tokenlist.h lib/utils.h lib/vfvalue.h
$(CXX) ${INCLUDE_FOR_LIB} $(CPPFLAGS) $(CXXFLAGS) -c -o $@ $(libcppdir)/checkleakautovar.cpp
$(libcppdir)/checkmemoryleak.o: lib/checkmemoryleak.cpp lib/addoninfo.h lib/astutils.h lib/check.h lib/checkmemoryleak.h lib/color.h lib/config.h lib/errorlogger.h lib/errortypes.h lib/importproject.h lib/library.h lib/mathlib.h lib/platform.h lib/settings.h lib/smallvector.h lib/sourcelocation.h lib/standards.h lib/suppressions.h lib/symboldatabase.h lib/templatesimplifier.h lib/token.h lib/tokenize.h lib/tokenlist.h lib/utils.h lib/vfvalue.h
@ -539,7 +539,7 @@ $(libcppdir)/checkpostfixoperator.o: lib/checkpostfixoperator.cpp lib/addoninfo.
$(libcppdir)/checksizeof.o: lib/checksizeof.cpp lib/addoninfo.h lib/check.h lib/checksizeof.h lib/config.h lib/errortypes.h lib/importproject.h lib/library.h lib/mathlib.h lib/platform.h lib/settings.h lib/sourcelocation.h lib/standards.h lib/suppressions.h lib/symboldatabase.h lib/templatesimplifier.h lib/token.h lib/tokenize.h lib/tokenlist.h lib/utils.h lib/vfvalue.h
$(CXX) ${INCLUDE_FOR_LIB} $(CPPFLAGS) $(CXXFLAGS) -c -o $@ $(libcppdir)/checksizeof.cpp
$(libcppdir)/checkstl.o: lib/checkstl.cpp lib/addoninfo.h lib/astutils.h lib/check.h lib/checknullpointer.h lib/checkstl.h lib/color.h lib/config.h lib/ctu.h lib/errorlogger.h lib/errortypes.h lib/importproject.h lib/library.h lib/mathlib.h lib/pathanalysis.h lib/platform.h lib/settings.h lib/smallvector.h lib/sourcelocation.h lib/standards.h lib/suppressions.h lib/symboldatabase.h lib/templatesimplifier.h lib/token.h lib/tokenize.h lib/tokenlist.h lib/utils.h lib/valueflow.h lib/vfvalue.h
$(libcppdir)/checkstl.o: lib/checkstl.cpp lib/addoninfo.h lib/astutils.h lib/check.h lib/checknullpointer.h lib/checkstl.h lib/config.h lib/errortypes.h lib/importproject.h lib/library.h lib/mathlib.h lib/pathanalysis.h lib/platform.h lib/settings.h lib/smallvector.h lib/sourcelocation.h lib/standards.h lib/suppressions.h lib/symboldatabase.h lib/templatesimplifier.h lib/token.h lib/tokenize.h lib/tokenlist.h lib/utils.h lib/valueflow.h lib/vfvalue.h
$(CXX) ${INCLUDE_FOR_LIB} $(CPPFLAGS) $(CXXFLAGS) -c -o $@ $(libcppdir)/checkstl.cpp
$(libcppdir)/checkstring.o: lib/checkstring.cpp lib/addoninfo.h lib/astutils.h lib/check.h lib/checkstring.h lib/config.h lib/errortypes.h lib/importproject.h lib/library.h lib/mathlib.h lib/platform.h lib/settings.h lib/smallvector.h lib/sourcelocation.h lib/standards.h lib/suppressions.h lib/symboldatabase.h lib/templatesimplifier.h lib/token.h lib/tokenize.h lib/tokenlist.h lib/utils.h lib/vfvalue.h

View File

@ -883,14 +883,27 @@ void CheckBufferOverrun::argumentSizeError(const Token *tok, const std::string &
// CTU..
//---------------------------------------------------------------------------
std::string CheckBufferOverrun::MyFileInfo::toString() const
{
std::string xml;
if (!unsafeArrayIndex.empty())
xml = " <array-index>\n" + CTU::toString(unsafeArrayIndex) + " </array-index>\n";
if (!unsafePointerArith.empty())
xml += " <pointer-arith>\n" + CTU::toString(unsafePointerArith) + " </pointer-arith>\n";
return xml;
namespace {
/** data for multifile checking */
class MyFileInfo : public Check::FileInfo {
public:
/** unsafe array index usage */
std::list<CTU::FileInfo::UnsafeUsage> unsafeArrayIndex;
/** unsafe pointer arithmetics */
std::list<CTU::FileInfo::UnsafeUsage> unsafePointerArith;
/** Convert data into xml string */
std::string toString() const override
{
std::string xml;
if (!unsafeArrayIndex.empty())
xml = " <array-index>\n" + CTU::toString(unsafeArrayIndex) + " </array-index>\n";
if (!unsafePointerArith.empty())
xml += " <pointer-arith>\n" + CTU::toString(unsafePointerArith) + " </pointer-arith>\n";
return xml;
}
};
}
bool CheckBufferOverrun::isCtuUnsafeBufferUsage(const Check *check, const Token *argtok, MathLib::bigint *offset, int type)

View File

@ -130,20 +130,6 @@ private:
ValueFlow::Value getBufferSize(const Token *bufTok) const;
// CTU
/** data for multifile checking */
class MyFileInfo : public Check::FileInfo {
public:
/** unsafe array index usage */
std::list<CTU::FileInfo::UnsafeUsage> unsafeArrayIndex;
/** unsafe pointer arithmetic */
std::list<CTU::FileInfo::UnsafeUsage> unsafePointerArith;
/** Convert MyFileInfo data into xml string */
std::string toString() const override;
};
static bool isCtuUnsafeBufferUsage(const Check *check, const Token *argtok, MathLib::bigint *offset, int type);
static bool isCtuUnsafeArrayIndex(const Check *check, const Token *argtok, MathLib::bigint *offset);
static bool isCtuUnsafePointerArith(const Check *check, const Token *argtok, MathLib::bigint *offset);

View File

@ -33,6 +33,7 @@
#include <algorithm>
#include <cctype>
#include <cstddef>
#include <cstring>
#include <iterator>
#include <utility>
@ -3390,6 +3391,42 @@ void CheckClass::unsafeClassRefMemberError(const Token *tok, const std::string &
CWE(0), Certainty::normal);
}
namespace {
/* multifile checking; one definition rule violations */
class MyFileInfo : public Check::FileInfo {
public:
struct NameLoc {
std::string className;
std::string fileName;
int lineNumber;
int column;
std::size_t hash;
bool isSameLocation(const NameLoc& other) const {
return fileName == other.fileName &&
lineNumber == other.lineNumber &&
column == other.column;
}
};
std::vector<NameLoc> classDefinitions;
/** Convert data into xml string */
std::string toString() const override
{
std::string ret;
for (const NameLoc &nameLoc: classDefinitions) {
ret += "<class name=\"" + ErrorLogger::toxml(nameLoc.className) +
"\" file=\"" + ErrorLogger::toxml(nameLoc.fileName) +
"\" line=\"" + std::to_string(nameLoc.lineNumber) +
"\" col=\"" + std::to_string(nameLoc.column) +
"\" hash=\"" + std::to_string(nameLoc.hash) +
"\"/>\n";
}
return ret;
}
};
}
Check::FileInfo *CheckClass::getFileInfo(const Tokenizer *tokenizer, const Settings *settings) const
{
if (!tokenizer->isCPP())
@ -3459,20 +3496,6 @@ Check::FileInfo *CheckClass::getFileInfo(const Tokenizer *tokenizer, const Setti
return fileInfo;
}
std::string CheckClass::MyFileInfo::toString() const
{
std::string ret;
for (const MyFileInfo::NameLoc &nameLoc: classDefinitions) {
ret += "<class name=\"" + ErrorLogger::toxml(nameLoc.className) +
"\" file=\"" + ErrorLogger::toxml(nameLoc.fileName) +
"\" line=\"" + std::to_string(nameLoc.lineNumber) +
"\" col=\"" + std::to_string(nameLoc.column) +
"\" hash=\"" + std::to_string(nameLoc.hash) +
"\"/>\n";
}
return ret;
}
Check::FileInfo * CheckClass::loadFileInfoFromXml(const tinyxml2::XMLElement *xmlElement) const
{
MyFileInfo *fileInfo = new MyFileInfo;

View File

@ -26,7 +26,6 @@
#include "tokenize.h"
#include "symboldatabase.h"
#include <cstddef>
#include <list>
#include <map>
#include <set>
@ -164,33 +163,6 @@ private:
/** @brief Unsafe class check - const reference member */
void checkUnsafeClassRefMember();
/* multifile checking; one definition rule violations */
class MyFileInfo : public Check::FileInfo {
public:
struct NameLoc {
std::string className;
std::string fileName;
int lineNumber;
int column;
std::size_t hash;
bool operator==(const NameLoc& other) const {
return isSameLocation(other) && hash == other.hash;
}
bool isSameLocation(const NameLoc& other) const {
return fileName == other.fileName &&
lineNumber == other.lineNumber &&
column == other.column;
}
};
std::vector<NameLoc> classDefinitions;
/** 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 *settings) const override;

View File

@ -21,6 +21,7 @@
#include "checknullpointer.h"
#include "astutils.h"
#include "ctu.h"
#include "errorlogger.h"
#include "errortypes.h"
#include "library.h"
@ -547,11 +548,6 @@ void CheckNullPointer::redundantConditionWarning(const Token* tok, const ValueFl
inconclusive ? Certainty::inconclusive : Certainty::normal);
}
std::string CheckNullPointer::MyFileInfo::toString() const
{
return CTU::toString(unsafeUsage);
}
// NOLINTNEXTLINE(readability-non-const-parameter) - used as callback so we need to preserve the signature
static bool isUnsafeUsage(const Check *check, const Token *vartok, MathLib::bigint *value)
{
@ -561,6 +557,22 @@ static bool isUnsafeUsage(const Check *check, const Token *vartok, MathLib::bigi
return checkNullPointer && checkNullPointer->isPointerDeRef(vartok, unknown);
}
namespace {
/* data for multifile checking */
class MyFileInfo : public Check::FileInfo {
public:
/** function arguments that are dereferenced without checking if they are null */
std::list<CTU::FileInfo::UnsafeUsage> unsafeUsage;
/** Convert data into xml string */
std::string toString() const override
{
return CTU::toString(unsafeUsage);
}
};
}
Check::FileInfo *CheckNullPointer::getFileInfo(const Tokenizer *tokenizer, const Settings *settings) const
{
CheckNullPointer check(tokenizer, settings, nullptr);

View File

@ -24,7 +24,6 @@
#include "check.h"
#include "config.h"
#include "ctu.h"
#include "tokenize.h"
#include "vfvalue.h"
@ -36,6 +35,10 @@ class Library;
class Settings;
class Token;
namespace CTU {
class FileInfo;
}
namespace tinyxml2 {
class XMLElement;
}
@ -102,16 +105,6 @@ private:
}
void nullPointerError(const Token *tok, const std::string &varname, const ValueFlow::Value* value, bool inconclusive);
/* data for multifile checking */
class MyFileInfo : public Check::FileInfo {
public:
/** function arguments that are dereferenced without checking if they are null */
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 *settings) const override;

View File

@ -21,6 +21,7 @@
#include "checkuninitvar.h"
#include "astutils.h"
#include "ctu.h"
#include "errorlogger.h"
#include "library.h"
#include "mathlib.h"
@ -1680,11 +1681,6 @@ void CheckUninitVar::valueFlowUninit()
}
}
std::string CheckUninitVar::MyFileInfo::toString() const
{
return CTU::toString(unsafeUsage);
}
Check::FileInfo *CheckUninitVar::getFileInfo(const Tokenizer *tokenizer, const Settings *settings) const
{
const CheckUninitVar checker(tokenizer, settings, nullptr);
@ -1699,6 +1695,21 @@ static bool isVariableUsage(const Check *check, const Token *vartok, MathLib::bi
return c && c->isVariableUsage(vartok, true, CheckUninitVar::Alloc::ARRAY);
}
namespace {
/* data for multifile checking */
class MyFileInfo : public Check::FileInfo {
public:
/** function arguments that data are unconditionally read */
std::list<CTU::FileInfo::UnsafeUsage> unsafeUsage;
/** Convert data into xml string */
std::string toString() const override
{
return CTU::toString(unsafeUsage);
}
};
}
Check::FileInfo *CheckUninitVar::getFileInfo() const
{
const std::list<CTU::FileInfo::UnsafeUsage> &unsafeUsage = CTU::getUnsafeUsage(mTokenizer, mSettings, this, ::isVariableUsage);

View File

@ -24,7 +24,6 @@
#include "check.h"
#include "config.h"
#include "ctu.h"
#include "mathlib.h"
#include "errortypes.h"
#include "tokenize.h"
@ -42,6 +41,10 @@ class ErrorLogger;
class Settings;
class Library;
namespace CTU {
class FileInfo;
}
namespace tinyxml2 {
class XMLElement;
}
@ -102,16 +105,6 @@ private:
/** ValueFlow-based checking for uninitialized variables */
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 *settings) const override;

View File

@ -36,6 +36,7 @@
#include <map>
#include <set>
#include <string>
#include <utility>
#include <vector>
class Tokenizer;