Fixed #1684 (false positive: buffer access out of bounds when using extern variable declaration)
This commit is contained in:
parent
bb5dfa58a1
commit
af7c97f972
|
@ -1043,6 +1043,14 @@ void CheckBufferOverrun::checkScope(const Token *tok, const ArrayInfo &arrayInfo
|
||||||
--indentlevel;
|
--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))
|
else if (Token::Match(tok, "%varid% [ %num% ]", arrayInfo.varid))
|
||||||
{
|
{
|
||||||
std::vector<MathLib::bigint> indexes;
|
std::vector<MathLib::bigint> indexes;
|
||||||
|
|
|
@ -117,6 +117,7 @@ private:
|
||||||
TEST_CASE(array_index_for); // FN: for,if
|
TEST_CASE(array_index_for); // FN: for,if
|
||||||
TEST_CASE(array_index_for_neq); // #2211: Using != in condition
|
TEST_CASE(array_index_for_neq); // #2211: Using != in condition
|
||||||
TEST_CASE(array_index_for_question); // #2561: for, ?:
|
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_1);
|
||||||
TEST_CASE(buffer_overrun_2);
|
TEST_CASE(buffer_overrun_2);
|
||||||
|
@ -1381,6 +1382,14 @@ private:
|
||||||
ASSERT_EQUALS("", errout.str());
|
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()
|
void buffer_overrun_1()
|
||||||
{
|
{
|
||||||
check("void f()\n"
|
check("void f()\n"
|
||||||
|
|
Loading…
Reference in New Issue