Fixed #729 (False positive: Buffer overrun when ? is used to select parameter)
http://sourceforge.net/apps/trac/cppcheck/ticket/729
This commit is contained in:
parent
50a34b8a37
commit
19ed8e9311
|
@ -431,11 +431,17 @@ void CheckBufferOverrun::checkScope(const Token *tok, const char *varname[], con
|
|||
{
|
||||
len = 0;
|
||||
const Token *end = tok->next()->link();
|
||||
bool argumentAlreadyChecked = false;
|
||||
for (const Token *tok2 = tok->tokAt(6); tok2 && tok2 != end; tok2 = tok2->next())
|
||||
{
|
||||
if (tok2->str()[0] == '\"')
|
||||
if (tok2->str() == ",")
|
||||
{
|
||||
argumentAlreadyChecked = false;
|
||||
}
|
||||
else if (Token::Match(tok2, "%str%") && argumentAlreadyChecked == false)
|
||||
{
|
||||
len += (int)Token::getStrLength(tok2);
|
||||
argumentAlreadyChecked = true;
|
||||
}
|
||||
}
|
||||
if (len >= (int)size)
|
||||
|
|
|
@ -100,6 +100,7 @@ private:
|
|||
TEST_CASE(sprintf2);
|
||||
TEST_CASE(sprintf3);
|
||||
TEST_CASE(sprintf4);
|
||||
TEST_CASE(sprintf5);
|
||||
|
||||
TEST_CASE(snprintf1);
|
||||
TEST_CASE(snprintf2);
|
||||
|
@ -648,6 +649,17 @@ private:
|
|||
ASSERT_EQUALS("", errout.str());
|
||||
}
|
||||
|
||||
void sprintf5()
|
||||
{
|
||||
// ticket #729
|
||||
check("void f(bool condition)\n"
|
||||
"{\n"
|
||||
" char buf[3];\n"
|
||||
" sprintf(buf, \"%s\", condition ? \"11\" : \"22\");\n"
|
||||
"}\n");
|
||||
ASSERT_EQUALS("", errout.str());
|
||||
}
|
||||
|
||||
void snprintf1()
|
||||
{
|
||||
check("void f()\n"
|
||||
|
|
Loading…
Reference in New Issue