Fixed #1684 (false positive: buffer access out of bounds when using extern variable declaration)

This commit is contained in:
Daniel Marjamäki 2011-05-07 11:34:48 +02:00
parent bb5dfa58a1
commit af7c97f972
2 changed files with 17 additions and 0 deletions

View File

@ -1043,6 +1043,14 @@ void CheckBufferOverrun::checkScope(const Token *tok, const ArrayInfo &arrayInfo
--indentlevel;
}
// Skip array declarations
else if (Token::Match(tok, "[;{}] %type% *| %var% [") &&
tok->strAt(1) != "return")
{
tok = tok->tokAt(3);
continue;
}
else if (Token::Match(tok, "%varid% [ %num% ]", arrayInfo.varid))
{
std::vector<MathLib::bigint> indexes;

View File

@ -117,6 +117,7 @@ private:
TEST_CASE(array_index_for); // FN: for,if
TEST_CASE(array_index_for_neq); // #2211: Using != in condition
TEST_CASE(array_index_for_question); // #2561: for, ?:
TEST_CASE(array_index_extern); // FP when using 'extern'. #1684
TEST_CASE(buffer_overrun_1);
TEST_CASE(buffer_overrun_2);
@ -1381,6 +1382,14 @@ private:
ASSERT_EQUALS("", errout.str());
}
void array_index_extern()
{
// Ticket #1684. FP when using 'extern'.
check("extern char arr[15];\n"
"char arr[15] = \"abc\";");
ASSERT_EQUALS("", errout.str());
}
void buffer_overrun_1()
{
check("void f()\n"