partial fix of ticket #997; added check for write() two testcases

This commit is contained in:
Martin Ettl 2009-11-28 13:41:24 +01:00
parent b0470d649a
commit 03e7914c98
2 changed files with 16 additions and 1 deletions

View File

@ -465,7 +465,7 @@ void CheckBufferOverrun::checkScope(const Token *tok, const char *varname[], con
// Writing data into array..
if (varid > 0 &&
Token::Match(tok, "read ( %any% , %varid% , %num% )", varid) &&
Token::Match(tok, "read|write ( %any% , %varid% , %num% )", varid) &&
MathLib::isInt(tok->strAt(6)))
{
size_t len = MathLib::toLongNumber(tok->strAt(6));

View File

@ -817,6 +817,20 @@ private:
"}\n");
ASSERT_EQUALS("[test.cpp:4]: (error) Buffer access out-of-bounds\n", errout.str());
check("void f(int fd)\n"
"{\n"
" char str[3];\n"
" write(fd, str, 3);\n"
"}\n");
ASSERT_EQUALS("", errout.str());
check("void f(int fd)\n"
"{\n"
" char str[3];\n"
" write(fd, str, 4);\n"
"}\n");
ASSERT_EQUALS("[test.cpp:4]: (error) Buffer access out-of-bounds\n", errout.str());
check("void f()\n"
"{\n"
" char str[3];\n"
@ -830,6 +844,7 @@ private:
" fgets(str, 4, stdin);\n"
"}\n");
ASSERT_EQUALS("[test.cpp:4]: (error) Buffer access out-of-bounds\n", errout.str());
}