Fixed #2210 (False positive: buffer overrun (snprintf, unknown type))

This commit is contained in:
Daniel Marjamäki 2010-11-18 19:26:46 +01:00
parent aa653fe42b
commit 66c2825b23
2 changed files with 12 additions and 1 deletions

View File

@ -1056,7 +1056,7 @@ void CheckBufferOverrun::checkScope(const Token *tok, const ArrayInfo &arrayInfo
} }
// snprintf.. // snprintf..
if (Token::Match(tok, "snprintf ( %varid% , %num% ,", arrayInfo.varid)) if (total_size > 0 && Token::Match(tok, "snprintf ( %varid% , %num% ,", arrayInfo.varid))
{ {
const long n = MathLib::toLongNumber(tok->strAt(4)); const long n = MathLib::toLongNumber(tok->strAt(4));
if (static_cast<unsigned long>(n) > total_size) if (static_cast<unsigned long>(n) > total_size)

View File

@ -146,6 +146,7 @@ private:
TEST_CASE(snprintf4); TEST_CASE(snprintf4);
TEST_CASE(snprintf5); TEST_CASE(snprintf5);
TEST_CASE(snprintf6); TEST_CASE(snprintf6);
TEST_CASE(snprintf7);
TEST_CASE(strncat1); TEST_CASE(strncat1);
TEST_CASE(strncat2); TEST_CASE(strncat2);
@ -1950,6 +1951,16 @@ private:
ASSERT_EQUALS("", errout.str()); ASSERT_EQUALS("", errout.str());
} }
void snprintf7()
{
check("void x() {\n"
" const int nBezString = 1024;\n"
" sal_Char pString[nBezString];\n"
" snprintf(pString, nBezString, \"ab\");\n"
"}\n");
ASSERT_EQUALS("", errout.str());
}
void strncat1() void strncat1()
{ {
check("void f(char *a, char *b)\n" check("void f(char *a, char *b)\n"