Fixed #2976 (False positive: array out of bounds)
This commit is contained in:
parent
afe95be966
commit
e2367b4149
|
@ -894,6 +894,12 @@ void CheckBufferOverrun::checkScope(const Token *tok, const std::vector<std::str
|
|||
break;
|
||||
}
|
||||
|
||||
// reassign buffer => bailout
|
||||
if (varid > 0 &&
|
||||
Token::Match(tok, "[;{}] %varid% =", varid) &&
|
||||
!Token::Match(tok->tokAt(3), "%varid%", varid))
|
||||
break;
|
||||
|
||||
// Array index..
|
||||
if (varid > 0)
|
||||
{
|
||||
|
|
|
@ -2497,6 +2497,13 @@ private:
|
|||
" s[10] = 0;\n"
|
||||
"}\n");
|
||||
ASSERT_EQUALS("[test.cpp:4]: (error) Array 's[1]' index 10 out of bounds\n", errout.str());
|
||||
|
||||
check("void foo() {\n"
|
||||
" const char *s = \"\";\n"
|
||||
" s = y();\n"
|
||||
" s[10] = 0;\n"
|
||||
"}\n");
|
||||
ASSERT_EQUALS("", errout.str());
|
||||
}
|
||||
|
||||
// data is allocated with alloca
|
||||
|
|
Loading…
Reference in New Issue