Fixed #2121 (False positive: Buffer access out-of-bounds when using uint32_t)

This commit is contained in:
Daniel Marjamäki 2010-10-23 13:12:17 +02:00
parent 120073f000
commit f3c6c64e9a
2 changed files with 18 additions and 2 deletions

View File

@ -458,6 +458,11 @@ void CheckBufferOverrun::parse_for_body(const Token *tok2, const ArrayInfo &arra
void CheckBufferOverrun::checkFunctionCall(const Token &tok, unsigned int par, const ArrayInfo &arrayInfo)
{
// unknown element size : don't report errors
if (arrayInfo.element_size == 0)
return;
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
total_size["memcmp"] = 3;

View File

@ -154,7 +154,8 @@ private:
TEST_CASE(strcat1);
TEST_CASE(strcat2);
TEST_CASE(memfunc); // memchr/memset/memcpy
TEST_CASE(memfunc1); // memchr/memset/memcpy
TEST_CASE(memfunc2);
TEST_CASE(varid1);
TEST_CASE(varid2);
@ -2001,7 +2002,7 @@ private:
// memchr/memset/memcpy/etc
void memfunc()
void memfunc1()
{
check("struct S {\n"
" char a[5];\n"
@ -2044,6 +2045,16 @@ private:
ASSERT_EQUALS("", errout.str());
}
// ticket #2121 - buffer access out of bounds when using uint32_t
void memfunc2()
{
check("void f()\n"
"{\n"
" unknown_type_t buf[4];\n"
" memset(buf, 0, 100);\n"
"}\n");
ASSERT_EQUALS("", errout.str());
}
void varid1()
{