Fixed #4968 (False positive: Structure with 'read' member is confused with read() function.)

This commit is contained in:
Daniel Marjamäki 2013-10-05 18:25:44 +02:00
parent 564d36698b
commit 946722faf0
2 changed files with 21 additions and 7 deletions

View File

@ -577,15 +577,20 @@ void CheckBufferOverrun::checkFunctionParameter(const Token &tok, unsigned int p
}
else if (par == 2) {
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 (_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::Match(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()) {
if (arrayInfo.element_size() == 0)

View File

@ -2162,6 +2162,15 @@ private:
"sendto(s, str, 4, 0, 0x0, 0x0);\n"
"}");
ASSERT_EQUALS("[test.cpp:4]: (error) Buffer is accessed out of bounds: str\n", errout.str());
// #4968 - not standard function
check("void f() {\n"
" char str[3];\n"
" foo.memset(str, 0, 100);\n"
" foo::memset(str, 0, 100);\n"
" std::memset(str, 0, 100);\n"
"}");
ASSERT_EQUALS("[test.cpp:5]: (error) Buffer is accessed out of bounds: str\n", errout.str());
}