Fixed #2576 (False positive: (error) Buffer access out-of-bounds)
This commit is contained in:
parent
07e8325e50
commit
518a495334
|
@ -791,7 +791,7 @@ void CheckBufferOverrun::checkScopeForBody(const Token *tok, const ArrayInfo &ar
|
|||
return;
|
||||
|
||||
// Get index variable and stopsize.
|
||||
bool condition_out_of_bounds = true;
|
||||
bool condition_out_of_bounds = bool(size > 0);
|
||||
if (MathLib::toLongNumber(max_counter_value) < size)
|
||||
condition_out_of_bounds = false;
|
||||
|
||||
|
|
|
@ -135,6 +135,7 @@ private:
|
|||
TEST_CASE(buffer_overrun_15); // ticket #1787
|
||||
TEST_CASE(buffer_overrun_16);
|
||||
TEST_CASE(buffer_overrun_17); // ticket #2548
|
||||
TEST_CASE(buffer_overrun_18); // ticket #2576 - for, calculation with loop variable
|
||||
TEST_CASE(buffer_overrun_bailoutIfSwitch); // ticket #2378 : bailoutIfSwitch
|
||||
|
||||
// It is undefined behaviour to point out of bounds of an array
|
||||
|
@ -1883,6 +1884,35 @@ private:
|
|||
ASSERT_EQUALS("[test.cpp:3]: (error) Buffer access out-of-bounds\n", errout.str());
|
||||
}
|
||||
|
||||
void buffer_overrun_18() // ticket #2576
|
||||
{
|
||||
check("class A {\n"
|
||||
" void foo();\n"
|
||||
" bool b[7];\n"
|
||||
"};\n"
|
||||
"\n"
|
||||
"void A::foo() {\n"
|
||||
" for (int i=0; i<6; i++) {\n"
|
||||
" b[i] = b[i+1];\n"
|
||||
" }\n"
|
||||
"}\n");
|
||||
ASSERT_EQUALS("", errout.str());
|
||||
|
||||
check("class A {\n"
|
||||
" void foo();\n"
|
||||
" bool b[7];\n"
|
||||
"};\n"
|
||||
"\n"
|
||||
"void A::foo() {\n"
|
||||
" for (int i=0; i<7; i++) {\n"
|
||||
" b[i] = b[i+1];\n"
|
||||
" }\n"
|
||||
"}\n");
|
||||
TODO_ASSERT_EQUALS("error", // wanted result
|
||||
"", // current result
|
||||
errout.str());
|
||||
}
|
||||
|
||||
void buffer_overrun_bailoutIfSwitch()
|
||||
{
|
||||
// No false positive
|
||||
|
|
Loading…
Reference in New Issue