stl: removed false positives for STL buffer overruns. Bailing out when it can't be checked if the index is ok or not. (#285)
This commit is contained in:
parent
a32114b15c
commit
80fe293c19
|
@ -86,59 +86,45 @@ void CheckStl::stlOutOfBounds()
|
|||
if (!Token::simpleMatch(tok, "for ("))
|
||||
continue;
|
||||
|
||||
|
||||
int indent = 1;
|
||||
tok = tok->tokAt(2);
|
||||
const Token *num = 0;
|
||||
const Token *var = 0;
|
||||
while (tok)
|
||||
unsigned int indent = 0;
|
||||
for (const Token *tok2 = tok; tok2; tok2 = tok2->next())
|
||||
{
|
||||
|
||||
if (tok->str() == "(")
|
||||
if (tok2->str() == "(")
|
||||
++indent;
|
||||
if (tok->str() == ")")
|
||||
|
||||
else if (tok2->str() == ")")
|
||||
{
|
||||
--indent;
|
||||
if (indent == 0)
|
||||
break;
|
||||
}
|
||||
|
||||
if (Token::Match(tok, "; %var% <= %var% . size ( ) ;"))
|
||||
{
|
||||
num = tok->tokAt(1);
|
||||
var = tok->tokAt(3);
|
||||
}
|
||||
|
||||
tok = tok->next();
|
||||
}
|
||||
|
||||
if (!tok)
|
||||
return;
|
||||
|
||||
tok = tok->next();
|
||||
if (!num || tok->str() != "{")
|
||||
continue;
|
||||
|
||||
std::string pattern = var->str() + " [ " + num->str() + " ]";
|
||||
while (tok)
|
||||
{
|
||||
|
||||
if (tok->str() == "{")
|
||||
++indent;
|
||||
if (tok->str() == "}")
|
||||
{
|
||||
--indent;
|
||||
if (indent == 0)
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
if (Token::Match(tok, pattern.c_str()))
|
||||
if (Token::Match(tok2, "; %var% <= %var% . size ( ) ;"))
|
||||
{
|
||||
stlOutOfBoundsError(tok, num->str(), var->str());
|
||||
indent = 0;
|
||||
const std::string num(tok2->strAt(1));
|
||||
const std::string varname(tok2->strAt(3));
|
||||
for (const Token *tok3 = tok2->tokAt(8); tok3; tok3 = tok3->next())
|
||||
{
|
||||
if (tok3->str() == "{")
|
||||
++indent;
|
||||
else if (tok3->str() == "}")
|
||||
{
|
||||
if (indent == 0)
|
||||
break;
|
||||
--indent;
|
||||
}
|
||||
else if (tok3->str() == varname)
|
||||
{
|
||||
if (Token::simpleMatch(tok3->next(), ". size ( )"))
|
||||
break;
|
||||
else if (Token::simpleMatch(tok3->next(), ("[ " + num + " ]").c_str()))
|
||||
stlOutOfBoundsError(tok3, num, varname);
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
tok = tok->next();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -188,7 +188,7 @@ private:
|
|||
" }\n"
|
||||
" }\n"
|
||||
"}\n");
|
||||
TODO_ASSERT_EQUALS(std::string(""), errout.str());
|
||||
ASSERT_EQUALS(std::string(""), errout.str());
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue