fix #2986 (segmentation fault of cppcheck ( x[y] ))
This commit is contained in:
parent
10eb224ac7
commit
a30da73d3e
|
@ -2214,9 +2214,13 @@ void CheckBufferOverrun::arrayIndexThenCheck()
|
|||
|
||||
// skip array index..
|
||||
tok = tok->tokAt(4);
|
||||
while (tok->str() == "[")
|
||||
while (tok && tok->str() == "[")
|
||||
tok = tok->link()->next();
|
||||
|
||||
// syntax error
|
||||
if (!tok)
|
||||
return;
|
||||
|
||||
// skip comparison
|
||||
if (Token::Match(tok, "==|!=|<|<=|>|>= %any% &&"))
|
||||
tok = tok->tokAt(2);
|
||||
|
|
|
@ -140,6 +140,7 @@ private:
|
|||
TEST_CASE(buffer_overrun_17); // ticket #2548
|
||||
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_20); // #2986 (segmentation fault)
|
||||
TEST_CASE(buffer_overrun_bailoutIfSwitch); // ticket #2378 : bailoutIfSwitch
|
||||
|
||||
// It is undefined behaviour to point out of bounds of an array
|
||||
|
@ -1969,6 +1970,12 @@ private:
|
|||
ASSERT_EQUALS("", errout.str());
|
||||
}
|
||||
|
||||
void buffer_overrun_20() // #2986(segmentation fault)
|
||||
{
|
||||
check("x[y]\n");
|
||||
ASSERT_EQUALS("", errout.str());
|
||||
}
|
||||
|
||||
void buffer_overrun_bailoutIfSwitch()
|
||||
{
|
||||
// No false positive
|
||||
|
|
Loading…
Reference in New Issue