Refactoring: Reusing the ArrayInfo in CheckBufferOverrun
This commit is contained in:
parent
814f706329
commit
1ae5a89982
|
@ -994,28 +994,17 @@ void CheckBufferOverrun::checkStructVariable()
|
||||||
if (tok2->str() == "}")
|
if (tok2->str() == "}")
|
||||||
break;
|
break;
|
||||||
|
|
||||||
int ivar = 0;
|
ArrayInfo arrayInfo;
|
||||||
if (Token::Match(tok2->next(), "%type% %var% [ %num% ] ;"))
|
if (!arrayInfo.declare(tok2->next(), *_tokenizer))
|
||||||
ivar = 2;
|
|
||||||
else if (Token::Match(tok2->next(), "%type% %type% %var% [ %num% ] ;"))
|
|
||||||
ivar = 3;
|
|
||||||
else if (Token::Match(tok2->next(), "%type% * %var% [ %num% ] ;"))
|
|
||||||
ivar = 3;
|
|
||||||
else if (Token::Match(tok2->next(), "%type% %type% * %var% [ %num% ] ;"))
|
|
||||||
ivar = 4;
|
|
||||||
else
|
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
std::vector<std::string> varname(2, "");
|
// Only handling 1-dimensional arrays yet..
|
||||||
const unsigned int varId = tok2->tokAt(ivar)->varId();
|
if (arrayInfo.num.size() > 1)
|
||||||
varname[1] = tok2->strAt(ivar);
|
|
||||||
int arrsize = MathLib::toLongNumber(tok2->strAt(ivar + 2));
|
|
||||||
int total_size = arrsize * _tokenizer->sizeOfType(tok2->tokAt(1));
|
|
||||||
if (tok2->tokAt(2)->str() == "*")
|
|
||||||
total_size = arrsize * _tokenizer->sizeOfType(tok2->tokAt(2));
|
|
||||||
if (total_size == 0)
|
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
|
std::vector<std::string> varname;
|
||||||
|
varname.push_back("");
|
||||||
|
varname.push_back(arrayInfo.varname);
|
||||||
|
|
||||||
// Class member variable => Check functions
|
// Class member variable => Check functions
|
||||||
if (tok->str() == "class")
|
if (tok->str() == "class")
|
||||||
|
@ -1032,7 +1021,7 @@ void CheckBufferOverrun::checkStructVariable()
|
||||||
if (Token::simpleMatch(tok4, ") {"))
|
if (Token::simpleMatch(tok4, ") {"))
|
||||||
{
|
{
|
||||||
std::vector<std::string> v;
|
std::vector<std::string> v;
|
||||||
checkScope(tok4->tokAt(2), v, arrsize, total_size, varId);
|
checkScope(tok4->tokAt(2), v, arrayInfo.num[0], arrayInfo.num[0] * arrayInfo.type_size, arrayInfo.varid);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1089,7 +1078,7 @@ void CheckBufferOverrun::checkStructVariable()
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
// Check variable usage..
|
// Check variable usage..
|
||||||
checkScope(CheckTok, varname, arrsize, total_size, 0);
|
checkScope(CheckTok, varname, arrayInfo.num[0], arrayInfo.num[0] * arrayInfo.type_size, 0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue