fix for loop false positives when zero length arrays present

This commit is contained in:
Robert Reif 2011-09-22 21:23:40 -04:00
parent 97d4277854
commit ac070b90f2
2 changed files with 16 additions and 1 deletions

View File

@ -546,7 +546,9 @@ void CheckBufferOverrun::parse_for_body(const Token *tok2, const ArrayInfo &arra
indexes.push_back(std::min(min_index, max_index)); indexes.push_back(std::min(min_index, max_index));
arrayIndexOutOfBoundsError(tok2, arrayInfo, indexes); arrayIndexOutOfBoundsError(tok2, arrayInfo, indexes);
} }
if (min_index >= (int)arrayInfo.num(0) || max_index >= (int)arrayInfo.num(0))
// skip 0 length arrays
if (arrayInfo.num(0) && (min_index >= (int)arrayInfo.num(0) || max_index >= (int)arrayInfo.num(0)))
{ {
std::vector<MathLib::bigint> indexes; std::vector<MathLib::bigint> indexes;
indexes.push_back(std::max(min_index, max_index)); indexes.push_back(std::max(min_index, max_index));

View File

@ -113,6 +113,7 @@ private:
TEST_CASE(array_index_34); // ticket #3063 TEST_CASE(array_index_34); // ticket #3063
TEST_CASE(array_index_35); // ticket #2889 TEST_CASE(array_index_35); // ticket #2889
TEST_CASE(array_index_36); // ticket #2960 TEST_CASE(array_index_36); // ticket #2960
TEST_CASE(array_index_37);
TEST_CASE(array_index_multidim); TEST_CASE(array_index_multidim);
TEST_CASE(array_index_switch_in_for); TEST_CASE(array_index_switch_in_for);
TEST_CASE(array_index_for_in_for); // FP: #2634 TEST_CASE(array_index_for_in_for); // FP: #2634
@ -1297,6 +1298,18 @@ private:
"[test.cpp:7]: (error) Array 'rhs.m_b[2]' index 2 out of bounds\n", errout.str()); "[test.cpp:7]: (error) Array 'rhs.m_b[2]' index 2 out of bounds\n", errout.str());
} }
void array_index_37()
{
check("class Fred {\n"
" char x[X];\n"
" Fred() {\n"
" for (unsigned int i = 0; i < 15; i++)\n"
" i;\n"
" }\n"
"}\n");
ASSERT_EQUALS("", errout.str());
}
void array_index_multidim() void array_index_multidim()
{ {
check("void f()\n" check("void f()\n"