@@ -22,18 +22,7 @@ std::string Config::load(const std::filesystem::path &path)
22
22
if (ifs.fail ())
23
23
return std::strerror (errno);
24
24
25
- std::streampos length;
26
- ifs.seekg (0 , std::ios::end);
27
- length = ifs.tellg ();
28
- ifs.seekg (0 , std::ios::beg);
29
-
30
- std::vector<char > buffer (length);
31
- ifs.read (&buffer[0 ], length);
32
-
33
- if (ifs.fail ())
34
- return std::strerror (errno);
35
-
36
- const std::string text = buffer.data ();
25
+ const std::string text (std::istreambuf_iterator<char >(ifs), {});
37
26
38
27
// Parse JSON
39
28
picojson::value data;
@@ -104,25 +93,23 @@ std::string Config::command() const
104
93
{
105
94
std::string cmd;
106
95
107
- cmd += m_cppcheck;
96
+ cmd += " \" " + m_cppcheck + " \" " ;
108
97
109
98
for (const auto &arg : m_args)
110
- cmd += " " + arg;
99
+ cmd += " \" " + arg + " \" " ;
111
100
112
101
if (!m_projectFilePath.empty ()) {
113
-
114
- std::string filter = m_filename.string ();
115
- if (std::strchr (filter.c_str (), ' ' ))
116
- filter = " \" " + filter + " \" " ;
117
-
118
- cmd += " --project=" + m_projectFilePath.string () + " --file-filter=" + filter;
119
-
102
+ cmd += " \" --project=" + m_projectFilePath.string () + " \" \" --file-filter=" + m_filename.string () + " \" " ;
120
103
} else {
121
- cmd += " " + m_filename.string ();
104
+ cmd += " \" " + m_filename.string () + " \" " ;
122
105
}
123
106
124
107
cmd += " 2>&1" ;
125
108
109
+ #ifdef _WIN32
110
+ cmd = " \" " + cmd + " \" " ;
111
+ #endif
112
+
126
113
return cmd;
127
114
}
128
115
@@ -184,7 +171,7 @@ std::string Config::parseArgs(int argc, char **argv)
184
171
m_configPath = findConfig (m_filename);
185
172
186
173
if (m_configPath.empty ())
187
- return " Failed to find config file" ;
174
+ return " Failed to find 'run-cppcheck- config.json' in any parent directory of analyzed file" ;
188
175
189
176
const std::string err = load (m_configPath);
190
177
if (!err.empty ())
0 commit comments