Skip to content

Commit b48bf1d

Browse files
committed
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.
1 parent a02712c commit b48bf1d

File tree

2 files changed

+9
-13
lines changed

2 files changed

+9
-13
lines changed

lib/cppcheck.cpp

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -63,12 +63,14 @@ const char * CppCheck::extraVersion()
6363

6464
unsigned int CppCheck::check(const std::string &path)
6565
{
66-
return processFile(path, "");
66+
std::ifstream fin(path.c_str());
67+
return processFile(path, fin);
6768
}
6869

6970
unsigned int CppCheck::check(const std::string &path, const std::string &content)
7071
{
71-
return processFile(path, content);
72+
std::istringstream iss(content);
73+
return processFile(path, iss);
7274
}
7375

7476
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[])
129131
return true;
130132
}
131133

132-
unsigned int CppCheck::processFile(const std::string& filename, const std::string& fileContent)
134+
unsigned int CppCheck::processFile(const std::string& filename, std::istream& fileStream)
133135
{
134136
exitcode = 0;
135137

@@ -151,15 +153,9 @@ unsigned int CppCheck::processFile(const std::string& filename, const std::strin
151153
std::list<std::string> configurations;
152154
std::string filedata = "";
153155

154-
if (!fileContent.empty()) {
155-
// File content was given as a string (democlient)
156-
std::istringstream iss(fileContent);
157-
preprocessor.preprocess(iss, filedata, configurations, filename, _settings._includePaths);
158-
} else {
159-
// Only file name was given, read the content from file
160-
std::ifstream fin(filename.c_str());
156+
{
161157
Timer t("Preprocessor::preprocess", _settings._showtime, &S_timerResults);
162-
preprocessor.preprocess(fin, filedata, configurations, filename, _settings._includePaths);
158+
preprocessor.preprocess(fileStream, filedata, configurations, filename, _settings._includePaths);
163159
}
164160

165161
if (_settings.checkConfiguration) {

lib/cppcheck.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -142,10 +142,10 @@ class CPPCHECKLIB CppCheck : ErrorLogger {
142142
/**
143143
* @brief Process one file.
144144
* @param filename file name
145-
* @param fileContent If this is non-empty then the file will not be loaded
145+
* @param fileStream stream the file content can be read from
146146
* @return amount of errors found
147147
*/
148-
unsigned int processFile(const std::string& filename, const std::string& fileContent);
148+
unsigned int processFile(const std::string& filename, std::istream& fileStream);
149149

150150
/** @brief Check file */
151151
bool checkFile(const std::string &code, const char FileName[], std::set<unsigned long long>& checksums);

0 commit comments

Comments
 (0)