diff --git a/lib/errorlogger.cpp b/lib/errorlogger.cpp index 75e255a79..d35ab149a 100644 --- a/lib/errorlogger.cpp +++ b/lib/errorlogger.cpp @@ -245,7 +245,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).getfile() << '\t' << loc->getinfo(); + smallStream << (*loc).line << ':' << (*loc).col << ':' << (*loc).getfile() << '\t' << loc->getinfo(); oss << smallStream.str().length() << " " << smallStream.str(); } @@ -307,23 +307,28 @@ bool ErrorLogger::ErrorMessage::deserialize(const std::string &data) temp.append(1, c); } - const std::string::size_type colonPos = temp.find(':'); - if (colonPos == std::string::npos) - throw InternalError(nullptr, "Internal Error: No colon found in pattern"); + 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"); const std::string tempinfo = temp.substr(tabPos + 1); temp.erase(tabPos); - const std::string tempfile = temp.substr(colonPos + 1); - temp.erase(colonPos); + 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); - std::istringstream fiss(templine); - fiss >> loc.line; + loc.col = MathLib::toLongNumber(tempcolumn); + loc.line = MathLib::toLongNumber(templine); _callStack.push_back(loc); diff --git a/test/testerrorlogger.cpp b/test/testerrorlogger.cpp index 4c7d2a811..b23ce3f81 100644 --- a/test/testerrorlogger.cpp +++ b/test/testerrorlogger.cpp @@ -57,6 +57,7 @@ private: TEST_CASE(SerializeInconclusiveMessage); TEST_CASE(DeserializeInvalidInput); TEST_CASE(SerializeSanitize); + TEST_CASE(SerializeFileLocation); TEST_CASE(suppressUnmatchedSuppressions); } @@ -289,6 +290,25 @@ private: ASSERT_EQUALS("Illegal character in \"foo\\001bar\"", msg2.verboseMessage()); } + void SerializeFileLocation() const { + ErrorLogger::ErrorMessage::FileLocation loc1; + loc1.setfile(":/,"); + loc1.line = 643; + loc1.col = 33; + loc1.setinfo("abcd:/,"); + + std::list locs{loc1}; + + ErrorMessage msg(locs, emptyString, Severity::error, "Programming error", "errorId", true); + + ErrorMessage msg2; + msg2.deserialize(msg.serialize()); + ASSERT_EQUALS(":/,", msg2._callStack.front().getfile(false)); + ASSERT_EQUALS(643, msg2._callStack.front().line); + ASSERT_EQUALS(33, msg2._callStack.front().col); + ASSERT_EQUALS("abcd:/,", msg2._callStack.front().getinfo()); + } + void suppressUnmatchedSuppressions() { std::list suppressions;