"Internal error. Token::Match called with varid 0." didn't work when error was in a header file. Fixed that.
This commit is contained in:
parent
7d7d68b192
commit
eebd1393ff
|
@ -115,11 +115,7 @@ bool CppCheck::findError(std::string code, const char FileName[])
|
|||
// is still there.
|
||||
code = previousCode.substr(found+9);
|
||||
_errorList.clear();
|
||||
try {
|
||||
checkFile(code, FileName);
|
||||
} catch (ErrorLogger::ErrorMessage &err) {
|
||||
reportErr(err);
|
||||
}
|
||||
}
|
||||
|
||||
if (_errorList.empty()) {
|
||||
|
@ -254,18 +250,6 @@ unsigned int CppCheck::processFile()
|
|||
// Exception was thrown when checking this file..
|
||||
const std::string fixedpath = Path::toNativeSeparators(_filename);
|
||||
_errorLogger.reportOut("Bailing out from checking " + fixedpath + ": " + e.what());
|
||||
} catch (ErrorLogger::ErrorMessage &err) {
|
||||
// Catch exception from Token class
|
||||
const std::string fixedpath = Path::toNativeSeparators(_filename);
|
||||
if (err._callStack.empty()) {
|
||||
ErrorLogger::ErrorMessage::FileLocation loc;
|
||||
loc.setfile(fixedpath);
|
||||
err._callStack.push_back(loc);
|
||||
} else {
|
||||
err._callStack.begin()->setfile(fixedpath);
|
||||
}
|
||||
|
||||
_errorLogger.reportErr(err);
|
||||
}
|
||||
|
||||
if (!_settings._errorsOnly)
|
||||
|
@ -337,6 +321,7 @@ void CppCheck::checkFile(const std::string &code, const char FileName[])
|
|||
return;
|
||||
|
||||
Tokenizer _tokenizer(&_settings, this);
|
||||
try {
|
||||
bool result;
|
||||
|
||||
// Tokenize the file
|
||||
|
@ -454,6 +439,28 @@ void CppCheck::checkFile(const std::string &code, const char FileName[])
|
|||
}
|
||||
}
|
||||
#endif
|
||||
} catch (const Token &tok) {
|
||||
// Catch exception from Token class
|
||||
const std::string fixedpath = Path::toNativeSeparators(_tokenizer.file(&tok));
|
||||
std::list<ErrorLogger::ErrorMessage::FileLocation> locationList;
|
||||
|
||||
ErrorLogger::ErrorMessage::FileLocation loc2;
|
||||
loc2.setfile(Path::toNativeSeparators(FileName));
|
||||
locationList.push_back(loc2);
|
||||
|
||||
ErrorLogger::ErrorMessage::FileLocation loc;
|
||||
loc.line = tok.linenr();
|
||||
loc.setfile(fixedpath);
|
||||
locationList.push_back(loc);
|
||||
|
||||
const ErrorLogger::ErrorMessage errmsg(locationList,
|
||||
Severity::error,
|
||||
"Internal error. Token::Match called with varid 0.",
|
||||
"cppcheckError",
|
||||
false);
|
||||
|
||||
_errorLogger.reportErr(errmsg);
|
||||
}
|
||||
}
|
||||
|
||||
Settings &CppCheck::settings()
|
||||
|
|
|
@ -542,7 +542,7 @@ bool Token::Match(const Token *tok, const char pattern[], unsigned int varid)
|
|||
"Internal error. Token::Match called with varid 0.",
|
||||
"cppcheckError",
|
||||
false);
|
||||
throw errmsg;
|
||||
throw *tok;
|
||||
}
|
||||
|
||||
if (tok->varId() != varid)
|
||||
|
|
|
@ -279,7 +279,7 @@ private:
|
|||
givenACodeSampleToTokenize var("int a ; int b ;");
|
||||
|
||||
// Varid == 0 should throw exception
|
||||
ASSERT_THROW(Token::Match(var.tokens(), "%type% %varid% ; %type% %var%", 0),ErrorLogger::ErrorMessage);
|
||||
ASSERT_THROW(Token::Match(var.tokens(), "%type% %varid% ; %type% %var%", 0),Token);
|
||||
|
||||
ASSERT_EQUALS(true, Token::Match(var.tokens(), "%type% %varid% ; %type% %var%", 1));
|
||||
ASSERT_EQUALS(true, Token::Match(var.tokens(), "%type% %var% ; %type% %varid%", 2));
|
||||
|
|
Loading…
Reference in New Issue