@@ -22,18 +22,7 @@ std::string Config::load(const std::filesystem::path &path)
2222 if (ifs.fail ())
2323 return std::strerror (errno);
2424
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), {});
3726
3827 // Parse JSON
3928 picojson::value data;
@@ -104,25 +93,23 @@ std::string Config::command() const
10493{
10594 std::string cmd;
10695
107- cmd += m_cppcheck;
96+ cmd += " \" " + m_cppcheck + " \" " ;
10897
10998 for (const auto &arg : m_args)
110- cmd += " " + arg;
99+ cmd += " \" " + arg + " \" " ;
111100
112101 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 () + " \" " ;
120103 } else {
121- cmd += " " + m_filename.string ();
104+ cmd += " \" " + m_filename.string () + " \" " ;
122105 }
123106
124107 cmd += " 2>&1" ;
125108
109+ #ifdef _WIN32
110+ cmd = " \" " + cmd + " \" " ;
111+ #endif
112+
126113 return cmd;
127114}
128115
@@ -184,7 +171,7 @@ std::string Config::parseArgs(int argc, char **argv)
184171 m_configPath = findConfig (m_filename);
185172
186173 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" ;
188175
189176 const std::string err = load (m_configPath);
190177 if (!err.empty ())
0 commit comments