From 5c7cf584ef5e69094357f1cd67dc9ac0016cd490 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Tue, 12 Sep 2017 22:42:10 +0200 Subject: [PATCH] bump simplecpp --- externals/simplecpp/simplecpp.cpp | 16 +++++++++++- externals/simplecpp/simplecpp.h | 3 ++- lib/cppcheck.cpp | 41 +++++++++++++++++++++---------- lib/preprocessor.cpp | 2 ++ test/testastutils.cpp | 2 +- 5 files changed, 48 insertions(+), 16 deletions(-) diff --git a/externals/simplecpp/simplecpp.cpp b/externals/simplecpp/simplecpp.cpp index 1c44c6c50..e290421ae 100644 --- a/externals/simplecpp/simplecpp.cpp +++ b/externals/simplecpp/simplecpp.cpp @@ -401,6 +401,20 @@ void simplecpp::TokenList::readfile(std::istream &istr, const std::string &filen if (ch < ' ' && ch != '\t' && ch != '\n' && ch != '\r') ch = ' '; + if (ch >= 0x80) { + if (outputList) { + simplecpp::Output err(files); + err.type = simplecpp::Output::UNHANDLED_CHAR_ERROR; + err.location = location; + std::ostringstream s; + s << (int)ch; + err.msg = "The code contains unhandled character(s) (character code=" + s.str() + "). Neither unicode nor extended ascii is supported."; + outputList->push_back(err); + } + clear(); + return; + } + if (ch == '\n') { if (cback() && cback()->op == '\\') { if (location.col > cback()->location.col + 1U) @@ -1288,7 +1302,7 @@ namespace simplecpp { if (!expandArg(tokens, tok, tok->location, macros, expandedmacros, parametertokens)) { bool expanded = false; const std::map::const_iterator it = macros.find(tok->str); - if (it != macros.end() && expandedmacros.find(tok->str) == expandedmacros.end()) { + if (it != macros.end() && expandedmacros.find(tok->str) == expandedmacros.end()) { const Macro &m = it->second; if (!m.functionLike()) { m.expand(tokens, tok, macros, files); diff --git a/externals/simplecpp/simplecpp.h b/externals/simplecpp/simplecpp.h index 2e608d22e..c74ccf895 100644 --- a/externals/simplecpp/simplecpp.h +++ b/externals/simplecpp/simplecpp.h @@ -164,7 +164,8 @@ namespace simplecpp { MISSING_HEADER, INCLUDE_NESTED_TOO_DEEPLY, SYNTAX_ERROR, - PORTABILITY_BACKSLASH + PORTABILITY_BACKSLASH, + UNHANDLED_CHAR_ERROR } type; Location location; std::string msg; diff --git a/lib/cppcheck.cpp b/lib/cppcheck.cpp index a835845d0..45b66037f 100644 --- a/lib/cppcheck.cpp +++ b/lib/cppcheck.cpp @@ -147,20 +147,35 @@ unsigned int CppCheck::processFile(const std::string& filename, const std::strin // If there is a syntax error, report it and stop for (simplecpp::OutputList::const_iterator it = outputList.begin(); it != outputList.end(); ++it) { - if (it->type != simplecpp::Output::SYNTAX_ERROR) - continue; - const ErrorLogger::ErrorMessage::FileLocation loc1(it->location.file(), it->location.line); - std::list callstack; - callstack.push_back(loc1); + bool err; + switch (it->type) { + case simplecpp::Output::ERROR: + case simplecpp::Output::INCLUDE_NESTED_TOO_DEEPLY: + case simplecpp::Output::SYNTAX_ERROR: + case simplecpp::Output::UNHANDLED_CHAR_ERROR: + err = true; + break; + case simplecpp::Output::WARNING: + case simplecpp::Output::MISSING_HEADER: + case simplecpp::Output::PORTABILITY_BACKSLASH: + err = false; + break; + }; - ErrorLogger::ErrorMessage errmsg(callstack, - "", - Severity::error, - it->msg, - "syntaxError", - false); - _errorLogger.reportErr(errmsg); - return 1; + if (err) { + const ErrorLogger::ErrorMessage::FileLocation loc1(it->location.file(), it->location.line); + std::list callstack; + callstack.push_back(loc1); + + ErrorLogger::ErrorMessage errmsg(callstack, + "", + Severity::error, + it->msg, + "syntaxError", + false); + _errorLogger.reportErr(errmsg); + return 1; + } } preprocessor.loadFiles(tokens1, files); diff --git a/lib/preprocessor.cpp b/lib/preprocessor.cpp index 16519e7fc..d53d16a3c 100644 --- a/lib/preprocessor.cpp +++ b/lib/preprocessor.cpp @@ -550,6 +550,7 @@ static bool hasErrors(const simplecpp::OutputList &outputList) case simplecpp::Output::ERROR: case simplecpp::Output::INCLUDE_NESTED_TOO_DEEPLY: case simplecpp::Output::SYNTAX_ERROR: + case simplecpp::Output::UNHANDLED_CHAR_ERROR: return true; case simplecpp::Output::WARNING: case simplecpp::Output::MISSING_HEADER: @@ -688,6 +689,7 @@ void Preprocessor::reportOutput(const simplecpp::OutputList &outputList, bool sh break; case simplecpp::Output::INCLUDE_NESTED_TOO_DEEPLY: case simplecpp::Output::SYNTAX_ERROR: + case simplecpp::Output::UNHANDLED_CHAR_ERROR: error(it->location.file(), it->location.line, it->msg); break; }; diff --git a/test/testastutils.cpp b/test/testastutils.cpp index db3046086..3151ed922 100644 --- a/test/testastutils.cpp +++ b/test/testastutils.cpp @@ -67,7 +67,7 @@ private: } void isVariableChanged() { - // #8211 - no lhs for >> , do not crash + // #8211 - no lhs for >> , do not crash ASSERT_EQUALS(true, isVariableChanged("void f() {\n" " int b;\n"