Fixed #2093 (False positive: buffer access out of bounds (unknown type))

This commit is contained in:
Daniel Marjamäki 2010-10-13 18:06:50 +02:00
parent afe52fa9f2
commit 229604b3e3
2 changed files with 8 additions and 1 deletions

View File

@ -1012,7 +1012,7 @@ void CheckBufferOverrun::checkScope(const Token *tok, const ArrayInfo &arrayInfo
if (Token::Match(tok, "strcpy|strcat ( %varid% , %str% )", arrayInfo.varid))
{
const unsigned long len = Token::getStrLength(tok->tokAt(4));
if (len >= total_size)
if (total_size > 0 && len >= total_size)
{
bufferOverrun(tok, arrayInfo.varname);
continue;

View File

@ -1688,11 +1688,18 @@ private:
void buffer_overrun_16()
{
// unknown types
check("void f() {\n"
" struct Foo foo[5];\n"
" memset(foo, 0, sizeof(foo));\n"
"}\n");
ASSERT_EQUALS("", errout.str());
check("void f() {\n" // ticket #2093
" gchar x[3];\n"
" strcpy(x, \"12\");\n"
"}\n");
ASSERT_EQUALS("", errout.str());
}
void sprintf1()