Only fill total_size in CheckBufferOverrun::checkFunctionParameter when it's useful.

This commit is contained in:
Simon Martin 2014-05-29 23:51:13 +02:00
parent 92759dfd9d
commit f7356dd8c7
1 changed files with 26 additions and 26 deletions

View File

@ -577,6 +577,8 @@ void CheckBufferOverrun::checkFunctionParameter(const Token &tok, unsigned int p
// total_size : which parameter in function call takes the total size?
std::map<std::string, unsigned int> total_size;
if (!(Token::simpleMatch(tok.previous(), ".") || Token::Match(tok.tokAt(-2), "!!std ::"))) {
total_size["fgets"] = 2; // The second argument for fgets can't exceed the total size of the array
total_size["memcmp"] = 3;
total_size["memcpy"] = 3;
@ -604,9 +606,7 @@ void CheckBufferOverrun::checkFunctionParameter(const Token &tok, unsigned int p
total_size["sendto"] = 3;
}
}
if (Token::simpleMatch(tok.previous(), ".") || Token::Match(tok.tokAt(-2), "!!std ::"))
total_size.clear();
}
std::map<std::string, unsigned int>::const_iterator it = total_size.find(tok.str());
if (it != total_size.end()) {