fix #2986 (segmentation fault of cppcheck ( x[y] ))

This commit is contained in:
Robert Reif 2011-08-09 19:45:18 -04:00
parent 10eb224ac7
commit a30da73d3e
2 changed files with 12 additions and 1 deletions

View File

@ -2214,9 +2214,13 @@ void CheckBufferOverrun::arrayIndexThenCheck()
// skip array index.. // skip array index..
tok = tok->tokAt(4); tok = tok->tokAt(4);
while (tok->str() == "[") while (tok && tok->str() == "[")
tok = tok->link()->next(); tok = tok->link()->next();
// syntax error
if (!tok)
return;
// skip comparison // skip comparison
if (Token::Match(tok, "==|!=|<|<=|>|>= %any% &&")) if (Token::Match(tok, "==|!=|<|<=|>|>= %any% &&"))
tok = tok->tokAt(2); tok = tok->tokAt(2);

View File

@ -140,6 +140,7 @@ private:
TEST_CASE(buffer_overrun_17); // ticket #2548 TEST_CASE(buffer_overrun_17); // ticket #2548
TEST_CASE(buffer_overrun_18); // ticket #2576 - for, calculation with loop variable TEST_CASE(buffer_overrun_18); // ticket #2576 - for, calculation with loop variable
TEST_CASE(buffer_overrun_19); // #2597 - class member with unknown type TEST_CASE(buffer_overrun_19); // #2597 - class member with unknown type
TEST_CASE(buffer_overrun_20); // #2986 (segmentation fault)
TEST_CASE(buffer_overrun_bailoutIfSwitch); // ticket #2378 : bailoutIfSwitch TEST_CASE(buffer_overrun_bailoutIfSwitch); // ticket #2378 : bailoutIfSwitch
// It is undefined behaviour to point out of bounds of an array // It is undefined behaviour to point out of bounds of an array
@ -1969,6 +1970,12 @@ private:
ASSERT_EQUALS("", errout.str()); ASSERT_EQUALS("", errout.str());
} }
void buffer_overrun_20() // #2986(segmentation fault)
{
check("x[y]\n");
ASSERT_EQUALS("", errout.str());
}
void buffer_overrun_bailoutIfSwitch() void buffer_overrun_bailoutIfSwitch()
{ {
// No false positive // No false positive