Remove repeated code, better variable name
This commit is contained in:
parent
3a1c20e9c4
commit
26788a1dc1
|
@ -371,15 +371,14 @@ static bool checkMinSizes(const std::list<Library::ArgumentChecks::MinSize> &min
|
|||
return error;
|
||||
}
|
||||
|
||||
void CheckBufferOverrun::checkFunctionParameter(const Token &ftok, unsigned int par, const ArrayInfo &arrayInfo, const std::list<const Token *>& callstack)
|
||||
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,par);
|
||||
const std::list<Library::ArgumentChecks::MinSize> * const minsizes = _settings->library.argminsizes(&ftok, paramIndex);
|
||||
|
||||
if (minsizes && (!(Token::simpleMatch(ftok.previous(), ".") || Token::Match(ftok.tokAt(-2), "!!std ::")))) {
|
||||
if (arrayInfo.element_size() == 0)
|
||||
return;
|
||||
|
||||
MathLib::bigint arraySize = arrayInfo.element_size();
|
||||
if (arraySize == 0)
|
||||
return;
|
||||
for (std::size_t i = 0; i < arrayInfo.num().size(); ++i)
|
||||
arraySize *= arrayInfo.num(i);
|
||||
|
||||
|
@ -401,7 +400,7 @@ void CheckBufferOverrun::checkFunctionParameter(const Token &ftok, unsigned int
|
|||
|
||||
if (func && func->hasBody()) {
|
||||
// Get corresponding parameter..
|
||||
const Variable* const parameter = func->getArgumentVar(par-1);
|
||||
const Variable* const parameter = func->getArgumentVar(paramIndex-1);
|
||||
|
||||
// Ensure that it has a compatible size..
|
||||
if (!parameter || _tokenizer->sizeOfType(parameter->typeStartToken()) != arrayInfo.element_size())
|
||||
|
@ -471,7 +470,7 @@ void CheckBufferOverrun::checkFunctionParameter(const Token &ftok, unsigned int
|
|||
|
||||
// If argument is '%type% a[num]' then check bounds against num
|
||||
if (func) {
|
||||
const Variable* const argument = func->getArgumentVar(par-1);
|
||||
const Variable* const argument = func->getArgumentVar(paramIndex-1);
|
||||
const Token *nameToken;
|
||||
if (argument && Token::Match(argument->typeStartToken(), "%type% %var% [ %num% ] [,)[]")
|
||||
&& (nameToken = argument->nameToken()) != nullptr) {
|
||||
|
|
|
@ -175,11 +175,11 @@ public:
|
|||
/**
|
||||
* Helper function for checkFunctionCall - check a function parameter
|
||||
* \param tok token for the function name
|
||||
* \param par on what parameter is the array used
|
||||
* \param paramIndex on what parameter is the array used
|
||||
* \param arrayInfo the array information
|
||||
* \param callstack call stack. This is used to prevent recursion and to provide better error messages. Pass a empty list from checkScope etc.
|
||||
*/
|
||||
void checkFunctionParameter(const Token &tok, const unsigned int par, const ArrayInfo &arrayInfo, const std::list<const Token *>& callstack);
|
||||
void checkFunctionParameter(const Token &tok, const unsigned int paramIndex, const ArrayInfo &arrayInfo, const std::list<const Token *>& callstack);
|
||||
|
||||
/**
|
||||
* Helper function that checks if the array is used and if so calls the checkFunctionCall
|
||||
|
|
Loading…
Reference in New Issue