Add a sanity check and an error message to linkAt when the index is outside the tokens range.
This commit is contained in:
parent
fa34a14d57
commit
ccdb18f213
|
@ -224,13 +224,39 @@ Token *Token::tokAt(int index)
|
|||
const Token *Token::linkAt(int index) const
|
||||
{
|
||||
const Token *tok = this->tokAt(index);
|
||||
return tok->link();
|
||||
if (!tok) {
|
||||
std::list<ErrorLogger::ErrorMessage::FileLocation> locationList;
|
||||
ErrorLogger::ErrorMessage::FileLocation loc;
|
||||
loc.setfile("");
|
||||
loc.line = this->linenr();
|
||||
locationList.push_back(loc);
|
||||
const ErrorLogger::ErrorMessage errmsg(locationList,
|
||||
Severity::error,
|
||||
"Internal error. Token::linkAt called with index outside the tokens range.",
|
||||
"cppcheckError",
|
||||
false);
|
||||
Check::reportError(errmsg);
|
||||
}
|
||||
return tok ? tok->link() : 0;
|
||||
}
|
||||
|
||||
Token *Token::linkAt(int index)
|
||||
{
|
||||
Token *tok = this->tokAt(index);
|
||||
return tok->link();
|
||||
if (!tok) {
|
||||
std::list<ErrorLogger::ErrorMessage::FileLocation> locationList;
|
||||
ErrorLogger::ErrorMessage::FileLocation loc;
|
||||
loc.setfile("");
|
||||
loc.line = this->linenr();
|
||||
locationList.push_back(loc);
|
||||
const ErrorLogger::ErrorMessage errmsg(locationList,
|
||||
Severity::error,
|
||||
"Internal error. Token::linkAt called with index outside the tokens range.",
|
||||
"cppcheckError",
|
||||
false);
|
||||
Check::reportError(errmsg);
|
||||
}
|
||||
return tok ? tok->link() : 0;
|
||||
}
|
||||
|
||||
const std::string &Token::strAt(int index) const
|
||||
|
|
Loading…
Reference in New Issue