Preprocessor: set error flag when unhandled characters are found so checking can bailout

This commit is contained in:
Daniel Marjamäki 2014-06-01 11:24:10 +02:00
parent af369b4925
commit 42140b6488
3 changed files with 15 additions and 1 deletions

View File

@ -160,6 +160,10 @@ unsigned int CppCheck::processFile(const std::string& filename, const std::strin
preprocessor.preprocess(fin, filedata, configurations, filename, _settings._includePaths);
}
// Unhandled chars found during preprocessing => abort checking this file
if (preprocessor.foundUnhandledChars())
return 0;
if (_settings.checkConfiguration) {
return 0;
}

View File

@ -38,7 +38,7 @@ bool Preprocessor::missingSystemIncludeFlag;
char Preprocessor::macroChar = char(1);
Preprocessor::Preprocessor(Settings *settings, ErrorLogger *errorLogger) : _settings(settings), _errorLogger(errorLogger)
Preprocessor::Preprocessor(Settings *settings, ErrorLogger *errorLogger) : _settings(settings), _errorLogger(errorLogger), _foundUnhandledChars(false)
{
}
@ -486,6 +486,7 @@ std::string Preprocessor::removeComments(const std::string &str, const std::stri
<< "Neither unicode nor extended ASCII are supported. "
<< "(line=" << lineno << ", character code=" << std::hex << (int(ch) & 0xff) << ")";
writeError(filename, lineno, _errorLogger, "syntaxError", errmsg.str());
_foundUnhandledChars = true;
}
if (_settings && _settings->terminated())

View File

@ -251,6 +251,10 @@ public:
file0 = f;
}
bool foundUnhandledChars() const {
return _foundUnhandledChars;
}
private:
void missingInclude(const std::string &filename, unsigned int linenr, const std::string &header, HeaderTypes headerType);
@ -274,6 +278,11 @@ private:
/** filename for cpp/c file - useful when reporting errors */
std::string file0;
/** set to true if unhandled chars are found in code. any char is ok
* in comments and string literals, but variable/type names must
* have plain ascii characters. */
bool _foundUnhandledChars;
};
/// @}