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))
|
||||
{
|
||||
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;
|
||||
|
|
|
@ -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()
|
||||
|
|
Loading…
Reference in New Issue