Skip to content

windows fixes #8

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 6, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 10 additions & 23 deletions config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<char> 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<char>(ifs), {});

// Parse JSON
picojson::value data;
Expand Down Expand Up @@ -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;
}

Expand Down Expand Up @@ -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())
Expand Down