Dont warn for arrays that are containers (#2240)

This commit is contained in:
Paul Fultz II 2019-10-05 09:14:30 -05:00 committed by Daniel Marjamäki
parent 887825d834
commit 6b6553e320
2 changed files with 12 additions and 0 deletions

View File

@ -286,6 +286,9 @@ void CheckBufferOverrun::arrayIndex()
continue;
}
if (astIsContainer(array))
continue;
std::vector<const Token *> indexTokens;
for (const Token *tok2 = tok; tok2 && tok2->str() == "["; tok2 = tok2->link()->next()) {
if (!tok2->astOperand2()) {

View File

@ -150,6 +150,7 @@ private:
TEST_CASE(array_index_valueflow_pointer);
TEST_CASE(array_index_function_parameter);
TEST_CASE(array_index_enum_array); // #8439
TEST_CASE(array_index_container); // #9386
TEST_CASE(buffer_overrun_2_struct);
TEST_CASE(buffer_overrun_3);
@ -2144,6 +2145,14 @@ private:
ASSERT_EQUALS("[test.cpp:4]: (error) Array 'arrE[2]' accessed at index 8, which is out of bounds.\n", errout.str());
}
void array_index_container() { // #9386
check("constexpr int blockLen = 10;\n"
"void foo(std::array<uint8_t, blockLen * 2>& a) {\n"
" a[2] = 2;\n"
"}\n");
ASSERT_EQUALS("", errout.str());
}
void buffer_overrun_2_struct() {
check("struct ABC\n"
"{\n"