Fixed #2093 (False positive: buffer access out of bounds (unknown type))
This commit is contained in:
parent
afe52fa9f2
commit
229604b3e3
|
@ -1012,7 +1012,7 @@ void CheckBufferOverrun::checkScope(const Token *tok, const ArrayInfo &arrayInfo
|
||||||
if (Token::Match(tok, "strcpy|strcat ( %varid% , %str% )", arrayInfo.varid))
|
if (Token::Match(tok, "strcpy|strcat ( %varid% , %str% )", arrayInfo.varid))
|
||||||
{
|
{
|
||||||
const unsigned long len = Token::getStrLength(tok->tokAt(4));
|
const unsigned long len = Token::getStrLength(tok->tokAt(4));
|
||||||
if (len >= total_size)
|
if (total_size > 0 && len >= total_size)
|
||||||
{
|
{
|
||||||
bufferOverrun(tok, arrayInfo.varname);
|
bufferOverrun(tok, arrayInfo.varname);
|
||||||
continue;
|
continue;
|
||||||
|
|
|
@ -1688,11 +1688,18 @@ private:
|
||||||
|
|
||||||
void buffer_overrun_16()
|
void buffer_overrun_16()
|
||||||
{
|
{
|
||||||
|
// unknown types
|
||||||
check("void f() {\n"
|
check("void f() {\n"
|
||||||
" struct Foo foo[5];\n"
|
" struct Foo foo[5];\n"
|
||||||
" memset(foo, 0, sizeof(foo));\n"
|
" memset(foo, 0, sizeof(foo));\n"
|
||||||
"}\n");
|
"}\n");
|
||||||
ASSERT_EQUALS("", errout.str());
|
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()
|
void sprintf1()
|
||||||
|
|
Loading…
Reference in New Issue