From 6db365e6f7004872a6d1076ab6c73276af7c14f4 Mon Sep 17 00:00:00 2001 From: Kimmo Varis Date: Sat, 17 Jul 2010 01:27:40 +0300 Subject: [PATCH] Improve path name handling in ErrorLogger. This commit adds setfile() method to FileLocation class. The setfile method converts in Windows path separators to internally used Unix separators. And getfile() converts path separators back to Windows separators. This fixes bugs that error reports had mixed path separators in paths. --- lib/check.h | 2 +- lib/checkmemoryleak.cpp | 2 +- lib/checkunusedfunctions.cpp | 2 +- lib/errorlogger.cpp | 40 +++++++++++++++++++++++++++++++----- lib/errorlogger.h | 5 ++++- lib/preprocessor.cpp | 6 +++--- lib/tokenize.cpp | 18 ++++++++-------- test/testcppcheck.cpp | 4 ++-- 8 files changed, 56 insertions(+), 23 deletions(-) diff --git a/lib/check.h b/lib/check.h index 8384b2d87..dd591781c 100644 --- a/lib/check.h +++ b/lib/check.h @@ -146,7 +146,7 @@ protected: ErrorLogger::ErrorMessage::FileLocation loc; loc.line = (*it)->linenr(); - loc.file = _tokenizer->file(*it); + loc.setfile(_tokenizer->file(*it)); locationList.push_back(loc); } diff --git a/lib/checkmemoryleak.cpp b/lib/checkmemoryleak.cpp index 21d47adf6..fe3f25607 100644 --- a/lib/checkmemoryleak.cpp +++ b/lib/checkmemoryleak.cpp @@ -320,7 +320,7 @@ void CheckMemoryLeak::reportErr(const std::list &callstack, Sever ErrorLogger::ErrorMessage::FileLocation loc; loc.line = tok->linenr(); - loc.file = tokenizer->file(tok); + loc.setfile(tokenizer->file(tok)); locations.push_back(loc); } diff --git a/lib/checkunusedfunctions.cpp b/lib/checkunusedfunctions.cpp index 5645c7e56..92c3a556c 100644 --- a/lib/checkunusedfunctions.cpp +++ b/lib/checkunusedfunctions.cpp @@ -187,7 +187,7 @@ void CheckUnusedFunctions::unusedFunctionError(ErrorLogger * const errorLogger, if (!filename.empty()) { ErrorLogger::ErrorMessage::FileLocation fileLoc; - fileLoc.file = filename; + fileLoc.setfile(filename); fileLoc.line = 1; locationList.push_back(fileLoc); } diff --git a/lib/errorlogger.cpp b/lib/errorlogger.cpp index f91d14806..694d600b6 100644 --- a/lib/errorlogger.cpp +++ b/lib/errorlogger.cpp @@ -100,7 +100,7 @@ bool ErrorLogger::ErrorMessage::deserialize(const std::string &data) } ErrorLogger::ErrorMessage::FileLocation loc; - loc.file = temp.substr(temp.find(':') + 1); + loc.setfile(temp.substr(temp.find(':') + 1)); temp = temp.substr(0, temp.find(':')); std::istringstream fiss(temp); fiss >> loc.line; @@ -217,7 +217,7 @@ std::string ErrorLogger::callStackToString(const std::list &callStack, Severity::SeverityType severity, const std::string &msg, const std::string &id); diff --git a/lib/preprocessor.cpp b/lib/preprocessor.cpp index 09d45ae50..232d203dd 100644 --- a/lib/preprocessor.cpp +++ b/lib/preprocessor.cpp @@ -46,7 +46,7 @@ void Preprocessor::writeError(const std::string &fileName, const int linenr, Err std::list locationList; ErrorLogger::ErrorMessage::FileLocation loc; loc.line = linenr; - loc.file = fileName; + loc.setfile(fileName); locationList.push_back(loc); errorLogger->reportErr(ErrorLogger::ErrorMessage(locationList, Severity::error, @@ -754,7 +754,7 @@ std::list Preprocessor::getcfgs(const std::string &filedata, const ErrorLogger::ErrorMessage errmsg; ErrorLogger::ErrorMessage::FileLocation loc; - loc.file = filename; + loc.setfile(filename); loc.line = linenr; errmsg._callStack.push_back(loc); errmsg._severity = Severity::fromString("error"); @@ -899,7 +899,7 @@ std::list Preprocessor::getcfgs(const std::string &filedata, const ErrorLogger::ErrorMessage errmsg; ErrorLogger::ErrorMessage::FileLocation loc; - loc.file = filename; + loc.setfile(filename); loc.line = 1; errmsg._callStack.push_back(loc); errmsg._severity = Severity::fromString("error"); diff --git a/lib/tokenize.cpp b/lib/tokenize.cpp index fbb8eea11..9ffc24700 100644 --- a/lib/tokenize.cpp +++ b/lib/tokenize.cpp @@ -408,10 +408,10 @@ void Tokenizer::duplicateTypedefError(const Token *tok1, const Token *tok2, cons std::list locationList; ErrorLogger::ErrorMessage::FileLocation loc; loc.line = tok1->linenr(); - loc.file = file(tok1); + loc.setfile(file(tok1)); locationList.push_back(loc); loc.line = tok2->linenr(); - loc.file = file(tok2); + loc.setfile(file(tok2)); locationList.push_back(loc); const ErrorLogger::ErrorMessage errmsg(locationList, @@ -434,10 +434,10 @@ void Tokenizer::duplicateDeclarationError(const Token *tok1, const Token *tok2, std::list locationList; ErrorLogger::ErrorMessage::FileLocation loc; loc.line = tok1->linenr(); - loc.file = file(tok1); + loc.setfile(file(tok1)); locationList.push_back(loc); loc.line = tok2->linenr(); - loc.file = file(tok2); + loc.setfile(file(tok2)); locationList.push_back(loc); const ErrorLogger::ErrorMessage errmsg(locationList, @@ -2284,7 +2284,7 @@ void Tokenizer::simplifyTemplates() std::list locationList; ErrorLogger::ErrorMessage::FileLocation loc; loc.line = tok2->linenr(); - loc.file = file(tok2); + loc.setfile(file(tok2)); locationList.push_back(loc); const ErrorLogger::ErrorMessage errmsg(locationList, @@ -6177,10 +6177,10 @@ void Tokenizer::duplicateEnumError(const Token * tok1, const Token * tok2, const std::list locationList; ErrorLogger::ErrorMessage::FileLocation loc; loc.line = tok1->linenr(); - loc.file = file(tok1); + loc.setfile(file(tok1)); locationList.push_back(loc); loc.line = tok2->linenr(); - loc.file = file(tok2); + loc.setfile(file(tok2)); locationList.push_back(loc); const ErrorLogger::ErrorMessage errmsg(locationList, @@ -6926,7 +6926,7 @@ void Tokenizer::syntaxError(const Token *tok, char c) { ErrorLogger::ErrorMessage::FileLocation loc; loc.line = tok->linenr(); - loc.file = file(tok); + loc.setfile(file(tok)); locationList.push_back(loc); } @@ -6969,7 +6969,7 @@ void Tokenizer::cppcheckError(const Token *tok) const { ErrorLogger::ErrorMessage::FileLocation loc; loc.line = tok->linenr(); - loc.file = file(tok); + loc.setfile(file(tok)); locationList.push_back(loc); } diff --git a/test/testcppcheck.cpp b/test/testcppcheck.cpp index 9795f936e..a881db5f4 100644 --- a/test/testcppcheck.cpp +++ b/test/testcppcheck.cpp @@ -382,7 +382,7 @@ private: { ErrorLogger::ErrorMessage errorMessage; ErrorLogger::ErrorMessage::FileLocation loc; - loc.file = "ab/cd/../ef.h"; + loc.setfile("ab/cd/../ef.h"); errorMessage._callStack.push_back(loc); ASSERT_EQUALS("", errorMessage.toXML()); ASSERT_EQUALS("[ab/ef.h:0]: ", errorMessage.toString()); @@ -392,7 +392,7 @@ private: { ErrorLogger::ErrorMessage errorMessage; ErrorLogger::ErrorMessage::FileLocation loc; - loc.file = "some/{file}file.cpp"; + loc.setfile("some/{file}file.cpp"); loc.line = 10; errorMessage._callStack.push_back(loc); errorMessage._id = "testId";