Rename private member variables

This commit is contained in:
Daniel Marjamäki 2018-06-17 17:20:16 +02:00
parent 0b74a90e75
commit ad4ce84cf7
8 changed files with 53 additions and 48 deletions

View File

@ -968,6 +968,7 @@ void CheckBufferOverrun::checkScope_inner(const Token *tok, const ArrayInfo &arr
}
else if (printPortability && astParent && astParent->str() == "-") {
const SymbolDatabase *symbolDatabase = mTokenizer->getSymbolDatabase();
const Variable *var = symbolDatabase->getVariableFromVarId(arrayInfo.declarationId());
if (var && var->isArray()) {
const Token *index = astParent->astOperand2();
@ -1108,6 +1109,7 @@ static bool isVLAIndex(const Token *index)
void CheckBufferOverrun::negativeArraySize()
{
const SymbolDatabase *symbolDatabase = mTokenizer->getSymbolDatabase();
for (const Variable *var : symbolDatabase->variableList()) {
if (!var || !var->isArray())
continue;
@ -1159,6 +1161,8 @@ bool CheckBufferOverrun::isArrayOfStruct(const Token* tok, int &position)
void CheckBufferOverrun::checkGlobalAndLocalVariable()
{
const SymbolDatabase *symbolDatabase = mTokenizer->getSymbolDatabase();
// check string literals
for (const Token *tok = mTokenizer->tokens(); tok; tok = tok->next()) {
if (Token::Match(tok, "%str% [") && tok->next()->astOperand2()) {
@ -1331,6 +1335,7 @@ void CheckBufferOverrun::checkGlobalAndLocalVariable()
void CheckBufferOverrun::checkStructVariable()
{
// find every class and struct
const SymbolDatabase *symbolDatabase = mTokenizer->getSymbolDatabase();
const std::size_t classes = symbolDatabase->classAndStructScopes.size();
for (std::size_t i = 0; i < classes; ++i) {
const Scope * scope = symbolDatabase->classAndStructScopes[i];
@ -1488,6 +1493,8 @@ void CheckBufferOverrun::checkStructVariable()
void CheckBufferOverrun::bufferOverrun()
{
const SymbolDatabase *symbolDatabase = mTokenizer->getSymbolDatabase();
// singlepass checking using ast, symboldatabase and valueflow
for (const Token *tok = mTokenizer->tokens(); tok; tok = tok->next()) {
if (mSettings->isEnabled(Settings::PORTABILITY) && tok->str() == "+" && tok->valueType() && tok->valueType()->pointer > 0) {
@ -1701,6 +1708,7 @@ MathLib::biguint CheckBufferOverrun::countSprintfLength(const std::string &input
//---------------------------------------------------------------------------
void CheckBufferOverrun::checkBufferAllocatedWithStrlen()
{
const SymbolDatabase *symbolDatabase = mTokenizer->getSymbolDatabase();
const std::size_t functions = symbolDatabase->functionScopes.size();
for (std::size_t i = 0; i < functions; ++i) {
const Scope * scope = symbolDatabase->functionScopes[i];
@ -1751,6 +1759,7 @@ void CheckBufferOverrun::checkBufferAllocatedWithStrlen()
//---------------------------------------------------------------------------
void CheckBufferOverrun::checkStringArgument()
{
const SymbolDatabase *symbolDatabase = mTokenizer->getSymbolDatabase();
const std::size_t functions = symbolDatabase->functionScopes.size();
for (std::size_t functionIndex = 0; functionIndex < functions; ++functionIndex) {
const Scope * const scope = symbolDatabase->functionScopes[functionIndex];
@ -1788,6 +1797,7 @@ void CheckBufferOverrun::checkStringArgument()
//---------------------------------------------------------------------------
void CheckBufferOverrun::checkInsecureCmdLineArgs()
{
const SymbolDatabase *symbolDatabase = mTokenizer->getSymbolDatabase();
const std::size_t functions = symbolDatabase->functionScopes.size();
for (std::size_t i = 0; i < functions; ++i) {
const Function * function = symbolDatabase->functionScopes[i]->function;
@ -1851,21 +1861,21 @@ void CheckBufferOverrun::negativeIndexError(const Token *tok, const ValueFlow::V
}
CheckBufferOverrun::ArrayInfo::ArrayInfo()
: _element_size(0), _declarationId(0)
: mElementSize(0), mDeclarationId(0)
{
}
CheckBufferOverrun::ArrayInfo::ArrayInfo(const Variable *var, const SymbolDatabase * symbolDatabase, const unsigned int forcedeclid)
: _varname(var->name()), _declarationId((forcedeclid == 0U) ? var->declarationId() : forcedeclid)
: mVarName(var->name()), mDeclarationId((forcedeclid == 0U) ? var->declarationId() : forcedeclid)
{
for (std::size_t i = 0; i < var->dimensions().size(); i++)
_num.push_back(var->dimension(i));
mNum.push_back(var->dimension(i));
if (var->typeEndToken()->str() == "*")
_element_size = symbolDatabase->sizeOfType(var->typeEndToken());
mElementSize = symbolDatabase->sizeOfType(var->typeEndToken());
else if (var->typeStartToken()->strAt(-1) == "struct")
_element_size = 100;
mElementSize = 100;
else {
_element_size = symbolDatabase->sizeOfType(var->typeEndToken());
mElementSize = symbolDatabase->sizeOfType(var->typeEndToken());
}
}
@ -1876,31 +1886,31 @@ CheckBufferOverrun::ArrayInfo::ArrayInfo(const Variable *var, const SymbolDataba
* this will not be needed as the declare can be used instead.
*/
CheckBufferOverrun::ArrayInfo::ArrayInfo(unsigned int id, const std::string &name, MathLib::bigint size1, MathLib::bigint n)
: _varname(name), _element_size(size1), _declarationId(id)
: mVarName(name), mElementSize(size1), mDeclarationId(id)
{
_num.push_back(n);
mNum.push_back(n);
}
CheckBufferOverrun::ArrayInfo CheckBufferOverrun::ArrayInfo::limit(MathLib::bigint value) const
{
const MathLib::bigint uvalue = std::max(MathLib::bigint(0), value);
MathLib::bigint n = 1;
for (std::size_t i = 0; i < _num.size(); ++i)
n *= _num[i];
for (std::size_t i = 0; i < mNum.size(); ++i)
n *= mNum[i];
if (uvalue > n)
n = uvalue;
return ArrayInfo(_declarationId, _varname, _element_size, n - uvalue);
return ArrayInfo(mDeclarationId, mVarName, mElementSize, n - uvalue);
}
MathLib::bigint CheckBufferOverrun::ArrayInfo::numberOfElements() const
{
if (_num.empty())
if (mNum.empty())
return 0;
// total number of elements of array..
MathLib::bigint ret = 1;
for (std::size_t i = 0; i < _num.size(); ++i) {
ret *= _num[i];
for (std::size_t i = 0; i < mNum.size(); ++i) {
ret *= mNum[i];
}
return ret;
}
@ -1909,10 +1919,10 @@ MathLib::bigint CheckBufferOverrun::ArrayInfo::totalIndex(const std::vector<Valu
{
MathLib::bigint index = 0;
MathLib::bigint elements = 1;
for (std::size_t i = 0; i < _num.size(); ++i) {
const std::size_t ri = _num.size() - 1U - i;
for (std::size_t i = 0; i < mNum.size(); ++i) {
const std::size_t ri = mNum.size() - 1U - i;
index += indexes[ri].intvalue * elements;
elements *= _num[ri];
elements *= mNum[ri];
}
return index;
}
@ -1923,6 +1933,7 @@ void CheckBufferOverrun::arrayIndexThenCheck()
if (!mSettings->isEnabled(Settings::PORTABILITY))
return;
const SymbolDatabase *symbolDatabase = mTokenizer->getSymbolDatabase();
const std::size_t functions = symbolDatabase->functionScopes.size();
for (std::size_t i = 0; i < functions; ++i) {
const Scope * const scope = symbolDatabase->functionScopes[i];
@ -2122,8 +2133,5 @@ bool CheckBufferOverrun::analyseWholeProgram(const std::list<Check::FileInfo*> &
unsigned int CheckBufferOverrun::sizeOfType(const Token *type) const
{
if (symbolDatabase)
return symbolDatabase->sizeOfType(type);
return 0;
return mTokenizer->getSymbolDatabase()->sizeOfType(type);
}

View File

@ -65,13 +65,12 @@ class CPPCHECKLIB CheckBufferOverrun : public Check {
public:
/** This constructor is used when registering the CheckClass */
CheckBufferOverrun() : Check(myName()), symbolDatabase(nullptr) {
CheckBufferOverrun() : Check(myName()) {
}
/** This constructor is used when running checks. */
CheckBufferOverrun(const Tokenizer *tokenizer, const Settings *settings, ErrorLogger *errorLogger)
: Check(myName(), tokenizer, settings, errorLogger)
, symbolDatabase(tokenizer?tokenizer->getSymbolDatabase():nullptr) {
: Check(myName(), tokenizer, settings, errorLogger) {
}
void runSimplifiedChecks(const Tokenizer *tokenizer, const Settings *settings, ErrorLogger *errorLogger) override {
@ -128,16 +127,16 @@ public:
class CPPCHECKLIB ArrayInfo {
private:
/** number of elements of array */
std::vector<MathLib::bigint> _num;
std::vector<MathLib::bigint> mNum;
/** full name of variable as pattern */
std::string _varname;
std::string mVarName;
/** size of each element in array */
MathLib::bigint _element_size;
MathLib::bigint mElementSize;
/** declaration id */
unsigned int _declarationId;
unsigned int mDeclarationId;
public:
ArrayInfo();
@ -156,36 +155,36 @@ public:
/** array sizes */
const std::vector<MathLib::bigint> &num() const {
return _num;
return mNum;
}
/** array size */
MathLib::bigint num(std::size_t index) const {
return _num[index];
return mNum[index];
}
void num(std::size_t index, MathLib::bigint number) {
_num[index] = number;
mNum[index] = number;
}
/** size of each element */
MathLib::bigint element_size() const {
return _element_size;
return mElementSize;
}
/** Variable name */
unsigned int declarationId() const {
return _declarationId;
return mDeclarationId;
}
void declarationId(unsigned int id) {
_declarationId = id;
mDeclarationId = id;
}
/** Variable name */
const std::string &varname() const {
return _varname;
return mVarName;
}
void varname(const std::string &name) {
_varname = name;
mVarName = name;
}
MathLib::bigint numberOfElements() const;
@ -254,8 +253,6 @@ public:
unsigned int sizeOfType(const Token *type) const;
private:
const SymbolDatabase *symbolDatabase;
static bool isArrayOfStruct(const Token* tok, int &position);
void arrayIndexOutOfBoundsError(const std::list<const Token *> &callstack, const ArrayInfo &arrayInfo, const std::vector<MathLib::bigint> &index);
void bufferOverrunError(const Token *tok, const std::string &varnames = emptyString);

View File

@ -3664,7 +3664,7 @@ const Enumerator * SymbolDatabase::findEnumerator(const Token * tok) const
const std::string &tokStr = tok->str();
if (tokensThatAreNotEnumeratorValues.find(tokStr) != tokensThatAreNotEnumeratorValues.end()) {
if (mTokensThatAreNotEnumeratorValues.find(tokStr) != mTokensThatAreNotEnumeratorValues.end()) {
return nullptr;
}
@ -3760,7 +3760,7 @@ const Enumerator * SymbolDatabase::findEnumerator(const Token * tok) const
}
}
tokensThatAreNotEnumeratorValues.insert(tokStr);
mTokensThatAreNotEnumeratorValues.insert(tokStr);
return nullptr;
}

View File

@ -1252,7 +1252,7 @@ private:
ValueType::Sign mDefaultSignedness;
/** "negative cache" list of tokens that we find are not enumeration values */
mutable std::set<std::string> tokensThatAreNotEnumeratorValues;
mutable std::set<std::string> mTokensThatAreNotEnumeratorValues;
};

View File

@ -47,7 +47,7 @@ void TimerResults::ShowResults(SHOWTIME_MODES mode) const
std::cout << std::endl;
TimerResultsData overallData;
std::vector<dataElementType> data(_results.begin(), _results.end());
std::vector<dataElementType> data(mResults.begin(), mResults.end());
std::sort(data.begin(), data.end(), more_second_sec);
size_t ordinal = 1; // maybe it would be nice to have an ordinal in output later!
@ -67,8 +67,8 @@ void TimerResults::ShowResults(SHOWTIME_MODES mode) const
void TimerResults::AddResults(const std::string& str, std::clock_t clocks)
{
_results[str].mClocks += clocks;
_results[str].mNumberOfResults++;
mResults[str].mClocks += clocks;
mResults[str].mNumberOfResults++;
}
Timer::Timer(const std::string& str, unsigned int showtimeMode, TimerResultsIntf* timerResults)

View File

@ -64,7 +64,7 @@ public:
virtual void AddResults(const std::string& str, std::clock_t clocks) override;
private:
std::map<std::string, struct TimerResultsData> _results;
std::map<std::string, struct TimerResultsData> mResults;
};
class CPPCHECKLIB Timer {

View File

@ -33,7 +33,7 @@
#include <stack>
#include <utility>
const std::list<ValueFlow::Value> Token::emptyValueList;
const std::list<ValueFlow::Value> Token::mEmptyValueList;
Token::Token(TokensFrontBack *tokensFrontBack) :
mTokensFrontBack(tokensFrontBack),

View File

@ -808,7 +808,7 @@ public:
}
const std::list<ValueFlow::Value>& values() const {
return mValues ? *mValues : emptyValueList;
return mValues ? *mValues : mEmptyValueList;
}
/**
@ -1001,7 +1001,7 @@ private:
// ValueFlow
std::list<ValueFlow::Value>* mValues;
static const std::list<ValueFlow::Value> emptyValueList;
static const std::list<ValueFlow::Value> mEmptyValueList;
public:
void astOperand1(Token *tok);