From b48bf1dbad434798a4d465f133793f1ecac9e849 Mon Sep 17 00:00:00 2001 From: PKEuS Date: Fri, 3 Oct 2014 10:40:48 +0200 Subject: [PATCH] Fixed GUI bug: file test.cpp is loaded from file if scratchpad is empty. The underlying problem was in lib and is fixed by changing the behaviour of CppCheck::check(). Checking is performed on empty content without attempt to load from file. --- lib/cppcheck.cpp | 18 +++++++----------- lib/cppcheck.h | 4 ++-- 2 files changed, 9 insertions(+), 13 deletions(-) diff --git a/lib/cppcheck.cpp b/lib/cppcheck.cpp index 189d0f1c7..d62b76ab0 100644 --- a/lib/cppcheck.cpp +++ b/lib/cppcheck.cpp @@ -63,12 +63,14 @@ const char * CppCheck::extraVersion() unsigned int CppCheck::check(const std::string &path) { - return processFile(path, ""); + std::ifstream fin(path.c_str()); + return processFile(path, fin); } unsigned int CppCheck::check(const std::string &path, const std::string &content) { - return processFile(path, content); + std::istringstream iss(content); + return processFile(path, iss); } void CppCheck::replaceAll(std::string& code, const std::string &from, const std::string &to) @@ -129,7 +131,7 @@ bool CppCheck::findError(std::string code, const char FileName[]) return true; } -unsigned int CppCheck::processFile(const std::string& filename, const std::string& fileContent) +unsigned int CppCheck::processFile(const std::string& filename, std::istream& fileStream) { exitcode = 0; @@ -151,15 +153,9 @@ unsigned int CppCheck::processFile(const std::string& filename, const std::strin std::list configurations; std::string filedata = ""; - if (!fileContent.empty()) { - // File content was given as a string (democlient) - std::istringstream iss(fileContent); - preprocessor.preprocess(iss, filedata, configurations, filename, _settings._includePaths); - } else { - // Only file name was given, read the content from file - std::ifstream fin(filename.c_str()); + { Timer t("Preprocessor::preprocess", _settings._showtime, &S_timerResults); - preprocessor.preprocess(fin, filedata, configurations, filename, _settings._includePaths); + preprocessor.preprocess(fileStream, filedata, configurations, filename, _settings._includePaths); } if (_settings.checkConfiguration) { diff --git a/lib/cppcheck.h b/lib/cppcheck.h index 43ea22722..7ab93b626 100644 --- a/lib/cppcheck.h +++ b/lib/cppcheck.h @@ -142,10 +142,10 @@ private: /** * @brief Process one file. * @param filename file name - * @param fileContent If this is non-empty then the file will not be loaded + * @param fileStream stream the file content can be read from * @return amount of errors found */ - unsigned int processFile(const std::string& filename, const std::string& fileContent); + unsigned int processFile(const std::string& filename, std::istream& fileStream); /** @brief Check file */ bool checkFile(const std::string &code, const char FileName[], std::set& checksums);