Fixed #2109 (false positive: buffer overrun)

This commit is contained in:
Daniel Marjamäki 2010-10-19 18:23:44 +02:00
parent f1640d6731
commit 2ca7dbc004
2 changed files with 14 additions and 0 deletions

View File

@ -1474,6 +1474,9 @@ unsigned int CheckBufferOverrun::countSprintfLength(const std::string &input_str
void CheckBufferOverrun::checkSprintfCall(const Token *tok, const unsigned int size)
{
if (size == 0)
return;
const Token *end = tok->next()->link();
// Count the number of tokens in the buffer variable's name

View File

@ -136,6 +136,7 @@ private:
TEST_CASE(sprintf6);
TEST_CASE(sprintf7);
TEST_CASE(sprintf8);
TEST_CASE(sprintf9);
TEST_CASE(snprintf1);
TEST_CASE(snprintf2);
@ -1824,6 +1825,16 @@ private:
ASSERT_EQUALS("", errout.str());
}
void sprintf9()
{
check("void f()\n"
"{\n"
" gchar str[3];\n"
" sprintf(str, \"1\");\n"
"}\n");
ASSERT_EQUALS("", errout.str());
}
void snprintf1()
{
check("void f()\n"