Merge pull request #327 from simartin/only_fill_if_needed

Only fill total_size in CheckBufferOverrun::checkFunctionParameter when useful
This commit is contained in:
PKEuS 2014-05-30 20:56:33 +02:00
commit 86dede14c0
1 changed files with 26 additions and 26 deletions

View File

@ -577,37 +577,37 @@ void CheckBufferOverrun::checkFunctionParameter(const Token &tok, unsigned int p
// 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;
total_size["fgets"] = 2; // The second argument for fgets can't exceed the total size of the array if (!(Token::simpleMatch(tok.previous(), ".") || Token::Match(tok.tokAt(-2), "!!std ::"))) {
total_size["memcmp"] = 3;
total_size["memcpy"] = 3;
total_size["memmove"] = 3;
total_size["memchr"] = 3;
if (par == 1) { total_size["fgets"] = 2; // The second argument for fgets can't exceed the total size of the array
// reading from array total_size["memcmp"] = 3;
// if it is zero terminated properly there won't be buffer overruns total_size["memcpy"] = 3;
total_size["strncat"] = 3; total_size["memmove"] = 3;
total_size["strncpy"] = 3; total_size["memchr"] = 3;
total_size["memset"] = 3;
total_size["fread"] = 1001; // parameter 2 * parameter 3
total_size["fwrite"] = 1001; // parameter 2 * parameter 3
}
else if (par == 2) { if (par == 1) {
if (_settings->standards.posix) { // reading from array
total_size["read"] = 3; // if it is zero terminated properly there won't be buffer overruns
total_size["pread"] = 3; total_size["strncat"] = 3;
total_size["write"] = 3; total_size["strncpy"] = 3;
total_size["recv"] = 3; total_size["memset"] = 3;
total_size["recvfrom"] = 3; total_size["fread"] = 1001; // parameter 2 * parameter 3
total_size["send"] = 3; total_size["fwrite"] = 1001; // parameter 2 * parameter 3
total_size["sendto"] = 3; }
else if (par == 2) {
if (_settings->standards.posix) {
total_size["read"] = 3;
total_size["pread"] = 3;
total_size["write"] = 3;
total_size["recv"] = 3;
total_size["recvfrom"] = 3;
total_size["send"] = 3;
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()); std::map<std::string, unsigned int>::const_iterator it = total_size.find(tok.str());
if (it != total_size.end()) { if (it != total_size.end()) {
if (arrayInfo.element_size() == 0) if (arrayInfo.element_size() == 0)