From f598246ad63a9b5908925db007f599e566e465f7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ludvig=20Gunne=20Lindstr=C3=B6m?= Date: Wed, 5 Mar 2025 12:23:44 +0100 Subject: [PATCH] fix spaces in paths on windows + file reading on windows, better error message on missing config --- config.cpp | 33 ++++++++++----------------------- 1 file changed, 10 insertions(+), 23 deletions(-) diff --git a/config.cpp b/config.cpp index f1549a1..6b451d7 100644 --- a/config.cpp +++ b/config.cpp @@ -22,18 +22,7 @@ std::string Config::load(const std::filesystem::path &path) if (ifs.fail()) return std::strerror(errno); - std::streampos length; - ifs.seekg(0, std::ios::end); - length = ifs.tellg(); - ifs.seekg(0, std::ios::beg); - - std::vector buffer(length); - ifs.read(&buffer[0], length); - - if (ifs.fail()) - return std::strerror(errno); - - const std::string text = buffer.data(); + const std::string text(std::istreambuf_iterator(ifs), {}); // Parse JSON picojson::value data; @@ -104,25 +93,23 @@ std::string Config::command() const { std::string cmd; - cmd += m_cppcheck; + cmd += "\"" + m_cppcheck + "\""; for (const auto &arg : m_args) - cmd += " " + arg; + cmd += " \"" + arg + "\""; if (!m_projectFilePath.empty()) { - - std::string filter = m_filename.string(); - if (std::strchr(filter.c_str(), ' ')) - filter = "\"" + filter + "\""; - - cmd += " --project=" + m_projectFilePath.string() + " --file-filter=" + filter; - + cmd += " \"--project=" + m_projectFilePath.string() + "\" \"--file-filter=" + m_filename.string() + "\""; } else { - cmd += " " + m_filename.string(); + cmd += " \"" + m_filename.string() + "\""; } cmd += " 2>&1"; +#ifdef _WIN32 + cmd = "\"" + cmd + "\""; +#endif + return cmd; } @@ -184,7 +171,7 @@ std::string Config::parseArgs(int argc, char **argv) m_configPath = findConfig(m_filename); if (m_configPath.empty()) - return "Failed to find config file"; + return "Failed to find 'run-cppcheck-config.json' in any parent directory of analyzed file"; const std::string err = load(m_configPath); if (!err.empty())