"Internal error. Token::Match called with varid 0." will now cause check to abort and write a proper error log with filename. Previously filename was empty and format was always xml.

This commit is contained in:
Reijo Tomperi 2011-11-20 23:38:37 +02:00
parent 004dcf834b
commit e0ea4228cd
3 changed files with 17 additions and 2 deletions

View File

@ -250,6 +250,19 @@ 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)

View File

@ -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);
Check::reportError(errmsg);
throw errmsg;
}
if (tok->varId() != varid)

View File

@ -277,7 +277,9 @@ private:
void matchVarid() {
givenACodeSampleToTokenize var("int a ; int b ;");
ASSERT_EQUALS(false, Token::Match(var.tokens(), "%type% %varid% ; %type% %var%", 0));
// Varid == 0 should throw exception
ASSERT_THROW(Token::Match(var.tokens(), "%type% %varid% ; %type% %var%", 0),ErrorLogger::ErrorMessage );
ASSERT_EQUALS(true, Token::Match(var.tokens(), "%type% %varid% ; %type% %var%", 1));
ASSERT_EQUALS(true, Token::Match(var.tokens(), "%type% %var% ; %type% %varid%", 2));