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.
This commit is contained in:
PKEuS 2014-10-03 10:40:48 +02:00
parent a02712cb66
commit b48bf1dbad
2 changed files with 9 additions and 13 deletions

View File

@ -63,12 +63,14 @@ const char * CppCheck::extraVersion()
unsigned int CppCheck::check(const std::string &path) 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) 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) 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; 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; exitcode = 0;
@ -151,15 +153,9 @@ unsigned int CppCheck::processFile(const std::string& filename, const std::strin
std::list<std::string> configurations; std::list<std::string> configurations;
std::string filedata = ""; 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); 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) { if (_settings.checkConfiguration) {

View File

@ -142,10 +142,10 @@ private:
/** /**
* @brief Process one file. * @brief Process one file.
* @param filename file name * @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 * @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 */ /** @brief Check file */
bool checkFile(const std::string &code, const char FileName[], std::set<unsigned long long>& checksums); bool checkFile(const std::string &code, const char FileName[], std::set<unsigned long long>& checksums);