Fixed #731 (False positive, strcpy copying a buffer with a null character)
http://sourceforge.net/apps/trac/cppcheck/ticket/731
This commit is contained in:
parent
6d56ab9df6
commit
50a34b8a37
|
@ -510,7 +510,14 @@ size_t Token::getStrLength(const Token *tok)
|
|||
while (*str)
|
||||
{
|
||||
if (*str == '\\')
|
||||
{
|
||||
++str;
|
||||
|
||||
// string ends at '\0'
|
||||
if (*str == '0')
|
||||
break;
|
||||
}
|
||||
|
||||
++str;
|
||||
++len;
|
||||
}
|
||||
|
|
|
@ -94,6 +94,7 @@ private:
|
|||
TEST_CASE(buffer_overrun_4);
|
||||
TEST_CASE(buffer_overrun_5);
|
||||
TEST_CASE(buffer_overrun_6);
|
||||
TEST_CASE(buffer_overrun_7);
|
||||
|
||||
TEST_CASE(sprintf1);
|
||||
TEST_CASE(sprintf2);
|
||||
|
@ -580,6 +581,17 @@ private:
|
|||
ASSERT_EQUALS("[test.cpp:4]: (possible error) Buffer overrun\n", errout.str());
|
||||
}
|
||||
|
||||
void buffer_overrun_7()
|
||||
{
|
||||
// ticket #731
|
||||
check("void f()\n"
|
||||
"{\n"
|
||||
" char a[2];\n"
|
||||
" strcpy(a, \"a\\0\");\n"
|
||||
"}\n");
|
||||
ASSERT_EQUALS("", errout.str());
|
||||
}
|
||||
|
||||
void sprintf1()
|
||||
{
|
||||
check("void f()\n"
|
||||
|
|
|
@ -93,6 +93,9 @@ private:
|
|||
|
||||
tok.str("\"test \\\\test\"");
|
||||
ASSERT_EQUALS(10, Token::getStrLength(&tok));
|
||||
|
||||
tok.str("\"a\\0\"");
|
||||
ASSERT_EQUALS(1, Token::getStrLength(&tok));
|
||||
}
|
||||
|
||||
void strValue()
|
||||
|
|
Loading…
Reference in New Issue