From a5ba82c2d3e29271ec798c14f20809be0b4d50aa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Sun, 18 Aug 2019 16:33:32 +0200 Subject: [PATCH] Fixed #9260 (--template=gcc does not work correctly with -j) --- lib/cppcheck.cpp | 14 +++++------- lib/errorlogger.cpp | 47 ++++++++++++++++++++-------------------- lib/errorlogger.h | 5 +++++ test/testerrorlogger.cpp | 11 +++++----- 4 files changed, 39 insertions(+), 38 deletions(-) diff --git a/lib/cppcheck.cpp b/lib/cppcheck.cpp index 358673cfa..49c7ba497 100644 --- a/lib/cppcheck.cpp +++ b/lib/cppcheck.cpp @@ -559,19 +559,15 @@ unsigned int CppCheck::checkFile(const std::string& filename, const std::string } catch (const InternalError &e) { std::list locationList; - ErrorLogger::ErrorMessage::FileLocation loc; if (e.token) { - loc.line = e.token->linenr(); - loc.column = e.token->column(); - const std::string fixedpath = Path::toNativeSeparators(mTokenizer.list.file(e.token)); - loc.setfile(fixedpath); + ErrorLogger::ErrorMessage::FileLocation loc(e.token, &mTokenizer.list); + locationList.push_back(loc); } else { - ErrorLogger::ErrorMessage::FileLocation loc2; - loc2.setfile(Path::toNativeSeparators(filename)); + ErrorLogger::ErrorMessage::FileLocation loc(mTokenizer.list.getSourceFilePath(), 0, 0); + ErrorLogger::ErrorMessage::FileLocation loc2(filename, 0, 0); locationList.push_back(loc2); - loc.setfile(mTokenizer.list.getSourceFilePath()); + locationList.push_back(loc); } - locationList.push_back(loc); ErrorLogger::ErrorMessage errmsg(locationList, mTokenizer.list.getSourceFilePath(), Severity::error, diff --git a/lib/errorlogger.cpp b/lib/errorlogger.cpp index 3ef66dd7f..f882e5fea 100644 --- a/lib/errorlogger.cpp +++ b/lib/errorlogger.cpp @@ -247,7 +247,7 @@ std::string ErrorLogger::ErrorMessage::serialize() const for (std::list::const_iterator loc = callStack.begin(); loc != callStack.end(); ++loc) { std::ostringstream smallStream; - smallStream << (*loc).line << ':' << (*loc).column << ':' << (*loc).getfile() << '\t' << loc->getinfo(); + smallStream << (*loc).line << '\t' << (*loc).column << '\t' << (*loc).getfile(false) << '\t' << loc->getOrigFile(false) << '\t' << loc->getinfo(); oss << smallStream.str().length() << " " << smallStream.str(); } @@ -309,28 +309,29 @@ bool ErrorLogger::ErrorMessage::deserialize(const std::string &data) temp.append(1, c); } - const std::string::size_type colonPos1 = temp.find(':'); - if (colonPos1 == std::string::npos) - throw InternalError(nullptr, "Internal Error: No colon found in pattern"); - const std::string::size_type colonPos2 = temp.find(':', colonPos1+1); - if (colonPos2 == std::string::npos) - throw InternalError(nullptr, "Internal Error: second colon not found in pattern"); - const std::string::size_type tabPos = temp.find('\t'); - if (tabPos == std::string::npos) - throw InternalError(nullptr, "Internal Error: No tab found in pattern"); + std::vector substrings; + for (std::string::size_type pos = 0; pos < temp.size() && substrings.size() < 5; ++pos) { + if (substrings.size() == 4) { + substrings.push_back(temp.substr(pos)); + break; + } + const std::string::size_type start = pos; + pos = temp.find("\t", pos); + if (pos == std::string::npos) { + substrings.push_back(temp.substr(start)); + break; + } + substrings.push_back(temp.substr(start, pos - start)); + } + if (substrings.size() < 4) + throw InternalError(nullptr, "Internal Error: serializing/deserializing of error message failed!"); - const std::string tempinfo = temp.substr(tabPos + 1); - temp.erase(tabPos); - const std::string tempfile = temp.substr(colonPos2 + 1); - temp.erase(colonPos2); - const std::string tempcolumn = temp.substr(colonPos1 + 1); - temp.erase(colonPos1); - const std::string templine = temp; - ErrorLogger::ErrorMessage::FileLocation loc; - loc.setfile(tempfile); - loc.setinfo(tempinfo); - loc.column = MathLib::toLongNumber(tempcolumn); - loc.line = MathLib::toLongNumber(templine); + // (*loc).line << '\t' << (*loc).column << '\t' << (*loc).getfile(false) << '\t' << loc->getOrigFile(false) << '\t' << loc->getinfo(); + + ErrorLogger::ErrorMessage::FileLocation loc(substrings[3], MathLib::toLongNumber(substrings[0]), MathLib::toLongNumber(substrings[1])); + loc.setfile(substrings[2]); + if (substrings.size() == 5) + loc.setinfo(substrings[4]); callStack.push_back(loc); @@ -441,7 +442,7 @@ void ErrorLogger::ErrorMessage::findAndReplace(std::string &source, const std::s } // TODO: read info from some shared resource instead? -static std::string readCode(const std::string &file, unsigned int linenr, unsigned int column, const char endl[]) +static std::string readCode(const std::string &file, int linenr, int column, const char endl[]) { std::ifstream fin(file); std::string line; diff --git a/lib/errorlogger.h b/lib/errorlogger.h index 7751a8111..c442c8620 100644 --- a/lib/errorlogger.h +++ b/lib/errorlogger.h @@ -211,6 +211,11 @@ public: */ std::string getfile(bool convert = true) const; + /** + * Filename with the whole path (no --rp) + * @param convert If true convert path to native separators. + * @return filename. + */ std::string getOrigFile(bool convert = true) const; /** diff --git a/test/testerrorlogger.cpp b/test/testerrorlogger.cpp index 71f9a9b11..d83d4bfe0 100644 --- a/test/testerrorlogger.cpp +++ b/test/testerrorlogger.cpp @@ -291,10 +291,8 @@ private: } void SerializeFileLocation() const { - ErrorLogger::ErrorMessage::FileLocation loc1; - loc1.setfile(":/,"); - loc1.line = 643; - loc1.column = 33; + ErrorLogger::ErrorMessage::FileLocation loc1(":/,;", 654, 33); + loc1.setfile("[]:;,()"); loc1.setinfo("abcd:/,"); std::list locs{loc1}; @@ -303,8 +301,9 @@ private: ErrorMessage msg2; msg2.deserialize(msg.serialize()); - ASSERT_EQUALS(":/,", msg2.callStack.front().getfile(false)); - ASSERT_EQUALS(643, msg2.callStack.front().line); + ASSERT_EQUALS("[]:;,()", msg2.callStack.front().getfile(false)); + ASSERT_EQUALS(":/,;", msg2.callStack.front().getOrigFile(false)); + ASSERT_EQUALS(654, msg2.callStack.front().line); ASSERT_EQUALS(33, msg2.callStack.front().column); ASSERT_EQUALS("abcd:/,", msg2.callStack.front().getinfo()); }