Refactorized CheckBufferOverrun:

- Removed redundant code
- Apply non-simplified checking in test suite
This commit is contained in:
PKEuS 2016-07-27 17:28:43 +02:00
parent dec839ea79
commit 3f4fe8f578
2 changed files with 4 additions and 5 deletions

View File

@ -383,7 +383,7 @@ void CheckBufferOverrun::checkFunctionParameter(const Token &ftok, unsigned int
{ {
const std::list<Library::ArgumentChecks::MinSize> * const minsizes = _settings->library.argminsizes(&ftok, paramIndex); 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 (minsizes) {
MathLib::bigint arraySize = arrayInfo.element_size(); MathLib::bigint arraySize = arrayInfo.element_size();
if (arraySize == 0) if (arraySize == 0)
return; return;
@ -1682,9 +1682,7 @@ void CheckBufferOverrun::checkStringArgument()
unsigned int argnr = 1; unsigned int argnr = 1;
for (const Token *argtok = tok->tokAt(2); argtok; argtok = argtok->nextArgument(), argnr++) { for (const Token *argtok = tok->tokAt(2); argtok; argtok = argtok->nextArgument(), argnr++) {
if (!Token::Match(argtok, "%name%|%str% ,|)")) if (!Token::Match(argtok, "%str% ,|)"))
continue;
if (argtok->variable() && !argtok->variable()->isPointer())
continue; continue;
const Token *strtoken = argtok->getValueTokenMinStrSize(); const Token *strtoken = argtok->getValueTokenMinStrSize();
if (!strtoken) if (!strtoken)

View File

@ -43,10 +43,11 @@ private:
Tokenizer tokenizer(&settings0, this); Tokenizer tokenizer(&settings0, this);
std::istringstream istr(code); std::istringstream istr(code);
tokenizer.tokenize(istr, filename); tokenizer.tokenize(istr, filename);
tokenizer.simplifyTokenList2();
// Check for buffer overruns.. // Check for buffer overruns..
CheckBufferOverrun checkBufferOverrun; CheckBufferOverrun checkBufferOverrun;
checkBufferOverrun.runChecks(&tokenizer, &settings0, this);
tokenizer.simplifyTokenList2();
checkBufferOverrun.runSimplifiedChecks(&tokenizer, &settings0, this); checkBufferOverrun.runSimplifiedChecks(&tokenizer, &settings0, this);
} }