Refactorization: Store minsizes in vector instead of list which has less overhead
This commit is contained in:
parent
63d39390b4
commit
2938278f00
|
@ -313,7 +313,7 @@ static bool bailoutIfSwitch(const Token *tok, const unsigned int varid)
|
|||
}
|
||||
//---------------------------------------------------------------------------
|
||||
|
||||
static bool checkMinSizes(const std::list<Library::ArgumentChecks::MinSize> &minsizes, const Token * const ftok, const MathLib::bigint arraySize, const Token **charSizeToken, const Settings * const settings)
|
||||
static bool checkMinSizes(const std::vector<Library::ArgumentChecks::MinSize> &minsizes, const Token * const ftok, const MathLib::bigint arraySize, const Token **charSizeToken, const Settings * const settings)
|
||||
{
|
||||
if (charSizeToken)
|
||||
*charSizeToken = nullptr;
|
||||
|
@ -323,7 +323,7 @@ static bool checkMinSizes(const std::list<Library::ArgumentChecks::MinSize> &min
|
|||
|
||||
// All conditions must be true
|
||||
bool error = true;
|
||||
for (std::list<Library::ArgumentChecks::MinSize>::const_iterator minsize = minsizes.begin(); minsize != minsizes.end(); ++minsize) {
|
||||
for (std::vector<Library::ArgumentChecks::MinSize>::const_iterator minsize = minsizes.begin(); minsize != minsizes.end(); ++minsize) {
|
||||
if (!error)
|
||||
return false;
|
||||
error = false;
|
||||
|
@ -383,7 +383,7 @@ static bool checkMinSizes(const std::list<Library::ArgumentChecks::MinSize> &min
|
|||
|
||||
void CheckBufferOverrun::checkFunctionParameter(const Token &ftok, unsigned int paramIndex, const ArrayInfo &arrayInfo, const std::list<const Token *>& callstack)
|
||||
{
|
||||
const std::list<Library::ArgumentChecks::MinSize> * const minsizes = _settings->library.argminsizes(&ftok, paramIndex);
|
||||
const std::vector<Library::ArgumentChecks::MinSize> * const minsizes = _settings->library.argminsizes(&ftok, paramIndex);
|
||||
|
||||
if (minsizes) {
|
||||
MathLib::bigint arraySize = arrayInfo.element_size();
|
||||
|
@ -1704,7 +1704,7 @@ void CheckBufferOverrun::checkStringArgument()
|
|||
const Token *strtoken = argtok->getValueTokenMinStrSize();
|
||||
if (!strtoken)
|
||||
continue;
|
||||
const std::list<Library::ArgumentChecks::MinSize> *minsizes = _settings->library.argminsizes(tok, argnr);
|
||||
const std::vector<Library::ArgumentChecks::MinSize> *minsizes = _settings->library.argminsizes(tok, argnr);
|
||||
if (!minsizes)
|
||||
continue;
|
||||
if (checkMinSizes(*minsizes, tok, Token::getStrSize(strtoken), nullptr, _settings))
|
||||
|
|
|
@ -623,6 +623,7 @@ Library::Error Library::loadFunction(const tinyxml2::XMLElement * const node, co
|
|||
if (strlen(argattr) != 1 || argattr[0]<'0' || argattr[0]>'9')
|
||||
return Error(BAD_ATTRIBUTE_VALUE, argattr);
|
||||
|
||||
ac.minsizes.reserve(type == ArgumentChecks::MinSize::MUL ? 2 : 1);
|
||||
ac.minsizes.push_back(ArgumentChecks::MinSize(type,argattr[0]-'0'));
|
||||
if (type == ArgumentChecks::MinSize::MUL) {
|
||||
const char *arg2attr = argnode->Attribute("arg2");
|
||||
|
|
|
@ -29,7 +29,6 @@
|
|||
#include <map>
|
||||
#include <set>
|
||||
#include <string>
|
||||
#include <list>
|
||||
#include <vector>
|
||||
|
||||
namespace tinyxml2 {
|
||||
|
@ -255,7 +254,7 @@ public:
|
|||
int arg;
|
||||
int arg2;
|
||||
};
|
||||
std::list<MinSize> minsizes;
|
||||
std::vector<MinSize> minsizes;
|
||||
};
|
||||
|
||||
|
||||
|
@ -310,7 +309,7 @@ public:
|
|||
|
||||
bool hasminsize(const std::string &functionName) const;
|
||||
|
||||
const std::list<ArgumentChecks::MinSize> *argminsizes(const Token *ftok, int argnr) const {
|
||||
const std::vector<ArgumentChecks::MinSize> *argminsizes(const Token *ftok, int argnr) const {
|
||||
const ArgumentChecks *arg = getarg(ftok, argnr);
|
||||
return arg ? &arg->minsizes : nullptr;
|
||||
}
|
||||
|
|
|
@ -339,7 +339,7 @@ private:
|
|||
tokenList.front()->next()->astOperand1(tokenList.front());
|
||||
|
||||
// arg1: type=strlen arg2
|
||||
const std::list<Library::ArgumentChecks::MinSize> *minsizes = library.argminsizes(tokenList.front(),1);
|
||||
const std::vector<Library::ArgumentChecks::MinSize> *minsizes = library.argminsizes(tokenList.front(),1);
|
||||
ASSERT_EQUALS(true, minsizes != nullptr);
|
||||
ASSERT_EQUALS(1U, minsizes ? minsizes->size() : 1U);
|
||||
if (minsizes && minsizes->size() == 1U) {
|
||||
|
|
Loading…
Reference in New Issue