partial fix of ticket #997; added check for write() two testcases
This commit is contained in:
parent
b0470d649a
commit
03e7914c98
|
@ -465,7 +465,7 @@ void CheckBufferOverrun::checkScope(const Token *tok, const char *varname[], con
|
||||||
|
|
||||||
// Writing data into array..
|
// Writing data into array..
|
||||||
if (varid > 0 &&
|
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)))
|
MathLib::isInt(tok->strAt(6)))
|
||||||
{
|
{
|
||||||
size_t len = MathLib::toLongNumber(tok->strAt(6));
|
size_t len = MathLib::toLongNumber(tok->strAt(6));
|
||||||
|
|
|
@ -817,6 +817,20 @@ private:
|
||||||
"}\n");
|
"}\n");
|
||||||
ASSERT_EQUALS("[test.cpp:4]: (error) Buffer access out-of-bounds\n", errout.str());
|
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"
|
check("void f()\n"
|
||||||
"{\n"
|
"{\n"
|
||||||
" char str[3];\n"
|
" char str[3];\n"
|
||||||
|
@ -830,6 +844,7 @@ private:
|
||||||
" fgets(str, 4, stdin);\n"
|
" fgets(str, 4, stdin);\n"
|
||||||
"}\n");
|
"}\n");
|
||||||
ASSERT_EQUALS("[test.cpp:4]: (error) Buffer access out-of-bounds\n", errout.str());
|
ASSERT_EQUALS("[test.cpp:4]: (error) Buffer access out-of-bounds\n", errout.str());
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue