Improved performance of CheckBufferOverrun::checkScope() (#5944):
-> Speedup by 40% (MSVC12, x64, not matchcompiled) on the file attached to the ticket
This commit is contained in:
parent
1ae6531c4c
commit
2d54bace1b
|
@ -572,7 +572,7 @@ void CheckBufferOverrun::parse_for_body(const Token *tok, const ArrayInfo &array
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void CheckBufferOverrun::checkFunctionParameter(const Token &tok, unsigned int par, const ArrayInfo &arrayInfo, std::list<const Token *> callstack)
|
void CheckBufferOverrun::checkFunctionParameter(const Token &tok, unsigned int par, const ArrayInfo &arrayInfo, const std::list<const Token *>& callstack)
|
||||||
{
|
{
|
||||||
// total_size : which parameter in function call takes the total size?
|
// total_size : which parameter in function call takes the total size?
|
||||||
std::map<std::string, unsigned int> total_size;
|
std::map<std::string, unsigned int> total_size;
|
||||||
|
@ -1279,9 +1279,7 @@ void CheckBufferOverrun::checkScope(const Token *tok, const ArrayInfo &arrayInfo
|
||||||
|
|
||||||
// Check function call..
|
// Check function call..
|
||||||
if (Token::Match(tok, "%var% (")) {
|
if (Token::Match(tok, "%var% (")) {
|
||||||
const std::list<const Token *> callstack;
|
checkFunctionCall(tok, arrayInfo, std::list<const Token*>());
|
||||||
checkFunctionCall(tok, arrayInfo, callstack);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (Token::Match(tok, "strncpy|memcpy|memmove ( %varid% , %str% , %num% )", declarationId)) {
|
if (Token::Match(tok, "strncpy|memcpy|memmove ( %varid% , %str% , %num% )", declarationId)) {
|
||||||
const unsigned int num = (unsigned int)MathLib::toLongNumber(tok->strAt(6));
|
const unsigned int num = (unsigned int)MathLib::toLongNumber(tok->strAt(6));
|
||||||
|
@ -1369,6 +1367,7 @@ void CheckBufferOverrun::checkScope(const Token *tok, const ArrayInfo &arrayInfo
|
||||||
if (_settings->standards.posix && Token::Match(tok, "readlink|readlinkat ("))
|
if (_settings->standards.posix && Token::Match(tok, "readlink|readlinkat ("))
|
||||||
checkReadlinkBufferUsage(tok, scope_begin, declarationId, total_size);
|
checkReadlinkBufferUsage(tok, scope_begin, declarationId, total_size);
|
||||||
|
|
||||||
|
}
|
||||||
// undefined behaviour: result of pointer arithmetic is out of bounds
|
// undefined behaviour: result of pointer arithmetic is out of bounds
|
||||||
if (isPortabilityEnabled && Token::Match(tok, "= %varid% + %num% ;", declarationId)) {
|
if (isPortabilityEnabled && Token::Match(tok, "= %varid% + %num% ;", declarationId)) {
|
||||||
const MathLib::bigint index = MathLib::toLongNumber(tok->strAt(3));
|
const MathLib::bigint index = MathLib::toLongNumber(tok->strAt(3));
|
||||||
|
|
|
@ -192,7 +192,7 @@ public:
|
||||||
* \param arrayInfo the array information
|
* \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.
|
* \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, std::list<const Token *> callstack);
|
void checkFunctionParameter(const Token &tok, const unsigned int par, const ArrayInfo &arrayInfo, const std::list<const Token *>& callstack);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Helper function that checks if the array is used and if so calls the checkFunctionCall
|
* Helper function that checks if the array is used and if so calls the checkFunctionCall
|
||||||
|
|
Loading…
Reference in New Issue