Skip to content
Draft
Show file tree
Hide file tree
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
1 change: 0 additions & 1 deletion .clang-tidy
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@ Checks: >
-modernize-use-nodiscard,
-modernize-use-scoped-lock,
-modernize-use-trailing-return-type,
-performance-avoid-endl,
-performance-inefficient-string-concatenation,
-performance-no-automatic-move,
-portability-avoid-pragma-once,
Expand Down
1 change: 0 additions & 1 deletion clang-tidy.md
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,6 @@ Does not improve the readability.
`bugprone-signed-char-misuse`<br/>
`concurrency-mt-unsafe`<br/>
`misc-use-anonymous-namespace`<br/>
`performance-avoid-endl`<br/>
`bugprone-switch-missing-default-case`<br/>
`bugprone-empty-catch`<br/>
`readability-avoid-nested-conditional-operator`<br/>
Expand Down
6 changes: 3 additions & 3 deletions cli/cmdlineparser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ namespace {
{
void reportOut(const std::string & outmsg, Color /*c*/ = Color::Reset) override
{
std::cout << outmsg << std::endl;
std::cout << outmsg << '\n';
}

void reportErr(const ErrorMessage &msg) override
Expand Down Expand Up @@ -179,7 +179,7 @@ bool CmdLineParser::fillSettingsFromArgs(int argc, const char* const argv[])
// TODO: this bypasses the template format and other settings
// If the include path is not found, warn user and remove the non-existing path from the list.
if (mSettings.severity.isEnabled(Severity::information))
std::cout << "(information) Couldn't find path given by -I '" << path << '\'' << std::endl;
std::cout << "(information) Couldn't find path given by -I '" << path << '\'' << '\n';
iter = mSettings.includePaths.erase(iter);
}
}
Expand Down Expand Up @@ -377,7 +377,7 @@ CmdLineParser::Result CmdLineParser::parseFromArgs(int argc, const char* const a
XMLErrorMessagesLogger xmlLogger;
std::cout << ErrorMessage::getXMLHeader(mSettings.cppcheckCfgProductName, 2);
CppCheck::getErrorMessages(xmlLogger);
std::cout << ErrorMessage::getXMLFooter(2) << std::endl;
std::cout << ErrorMessage::getXMLFooter(2) << '\n';
}
return Result::Exit;
}
Expand Down
16 changes: 8 additions & 8 deletions cli/cppcheckexecutor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ namespace {

void printRaw(const std::string &message) override
{
std::cout << message << std::endl; // TODO: should not append newline
std::cout << message << '\n'; // TODO: should not append newline
}
};

Expand Down Expand Up @@ -592,18 +592,18 @@ static inline std::string ansiToOEM(const std::string &msg, bool doConvert)
void StdLogger::reportErr(const std::string &errmsg)
{
if (mErrorOutput)
*mErrorOutput << errmsg << std::endl;
*mErrorOutput << errmsg << '\n';
else {
std::cerr << ansiToOEM(errmsg, mSettings.outputFormat != Settings::OutputFormat::xml) << std::endl;
std::cerr << ansiToOEM(errmsg, mSettings.outputFormat != Settings::OutputFormat::xml) << '\n';
}
}

void StdLogger::reportOut(const std::string &outmsg, Color c)
{
if (c == Color::Reset)
std::cout << ansiToOEM(outmsg, true) << std::endl;
std::cout << ansiToOEM(outmsg, true) << '\n';
else
std::cout << c << ansiToOEM(outmsg, true) << Color::Reset << std::endl;
std::cout << c << ansiToOEM(outmsg, true) << Color::Reset << '\n';
}

// TODO: remove filename parameter?
Expand Down Expand Up @@ -710,11 +710,11 @@ int CppCheckExecutor::executeCommand(std::string exe, std::vector<std::string> a
#else
FILE *p = popen(cmd.c_str(), "r");
#endif
//std::cout << "invoking command '" << cmd << "'" << std::endl;
//std::cout << "invoking command '" << cmd << "'" << '\n';
if (!p) {
// TODO: how to provide to caller?
//const int err = errno;
//std::cout << "popen() errno " << std::to_string(err) << std::endl;
//std::cout << "popen() errno " << std::to_string(err) << '\n';
return -1;
}
char buffer[1024];
Expand All @@ -732,7 +732,7 @@ int CppCheckExecutor::executeCommand(std::string exe, std::vector<std::string> a
if (res == -1) { // error occurred
// TODO: how to provide to caller?
//const int err = errno;
//std::cout << "pclose() errno " << std::to_string(err) << std::endl;
//std::cout << "pclose() errno " << std::to_string(err) << '\n';
return res;
}
#if !defined(_WIN32) && !defined(__MINGW32__)
Expand Down
24 changes: 12 additions & 12 deletions cli/processexecutor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -141,12 +141,12 @@ namespace {
const ssize_t bytes_written = write(mWpipe, data, to_write);
if (bytes_written <= 0) {
const int err = errno;
std::cerr << "#### ThreadExecutor::writeToPipeInternal() error for type " << static_cast<unsigned char>(type) << ": " << std::strerror(err) << std::endl;
std::cerr << "#### ThreadExecutor::writeToPipeInternal() error for type " << static_cast<unsigned char>(type) << ": " << std::strerror(err) << '\n';
std::exit(EXIT_FAILURE);
}
// TODO: write until everything is written
if (bytes_written != to_write) {
std::cerr << "#### ThreadExecutor::writeToPipeInternal() error for type " << static_cast<unsigned char>(type) << ": insufficient data written (expected: " << to_write << " / got: " << bytes_written << ")" << std::endl;
std::cerr << "#### ThreadExecutor::writeToPipeInternal() error for type " << static_cast<unsigned char>(type) << ": insufficient data written (expected: " << to_write << " / got: " << bytes_written << ")" << '\n';
std::exit(EXIT_FAILURE);
}
}
Expand Down Expand Up @@ -191,7 +191,7 @@ bool ProcessExecutor::handleRead(int rpipe, unsigned int &result, const std::str
return false;
}
if (bytes_read != bytes_to_read) {
std::cerr << "#### ThreadExecutor::handleRead(" << filename << ") error (type): insufficient data read (expected: " << bytes_to_read << " / got: " << bytes_read << ")" << std::endl;
std::cerr << "#### ThreadExecutor::handleRead(" << filename << ") error (type): insufficient data read (expected: " << bytes_to_read << " / got: " << bytes_read << ")" << '\n';
std::exit(EXIT_FAILURE);
}

Expand All @@ -202,7 +202,7 @@ bool ProcessExecutor::handleRead(int rpipe, unsigned int &result, const std::str
type != PipeWriter::CHILD_END &&
type != PipeWriter::REPORT_METRIC &&
type != PipeWriter::REPORT_TIMER) {
std::cerr << "#### ThreadExecutor::handleRead(" << filename << ") invalid type " << int(type) << std::endl;
std::cerr << "#### ThreadExecutor::handleRead(" << filename << ") invalid type " << int(type) << '\n';
std::exit(EXIT_FAILURE);
}

Expand All @@ -211,11 +211,11 @@ bool ProcessExecutor::handleRead(int rpipe, unsigned int &result, const std::str
bytes_read = read(rpipe, &len, bytes_to_read);
if (bytes_read <= 0) {
const int err = errno;
std::cerr << "#### ThreadExecutor::handleRead(" << filename << ") error (len) for type " << int(type) << ": " << std::strerror(err) << std::endl;
std::cerr << "#### ThreadExecutor::handleRead(" << filename << ") error (len) for type " << int(type) << ": " << std::strerror(err) << '\n';
std::exit(EXIT_FAILURE);
}
if (bytes_read != bytes_to_read) {
std::cerr << "#### ThreadExecutor::handleRead(" << filename << ") error (len) for type" << int(type) << ": insufficient data read (expected: " << bytes_to_read << " / got: " << bytes_read << ")" << std::endl;
std::cerr << "#### ThreadExecutor::handleRead(" << filename << ") error (len) for type" << int(type) << ": insufficient data read (expected: " << bytes_to_read << " / got: " << bytes_read << ")" << '\n';
std::exit(EXIT_FAILURE);
}

Expand All @@ -227,7 +227,7 @@ bool ProcessExecutor::handleRead(int rpipe, unsigned int &result, const std::str
bytes_read = read(rpipe, data_start, bytes_to_read);
if (bytes_read <= 0) {
const int err = errno;
std::cerr << "#### ThreadExecutor::handleRead(" << filename << ") error (buf) for type" << int(type) << ": " << std::strerror(err) << std::endl;
std::cerr << "#### ThreadExecutor::handleRead(" << filename << ") error (buf) for type" << int(type) << ": " << std::strerror(err) << '\n';
std::exit(EXIT_FAILURE);
}
bytes_to_read -= bytes_read;
Expand All @@ -246,7 +246,7 @@ bool ProcessExecutor::handleRead(int rpipe, unsigned int &result, const std::str
try {
msg.deserialize(buf);
} catch (const InternalError& e) {
std::cerr << "#### ThreadExecutor::handleRead(" << filename << ") internal error: " << e.errorMessage << std::endl;
std::cerr << "#### ThreadExecutor::handleRead(" << filename << ") internal error: " << e.errorMessage << '\n';
std::exit(EXIT_FAILURE);
}

Expand Down Expand Up @@ -347,25 +347,25 @@ unsigned int ProcessExecutor::check()
if ((iFile != mFiles.cend() || iFileSettings != mFileSettings.cend()) && nchildren < mSettings.jobs && checkLoadAverage(nchildren)) {
int pipes[2];
if (pipe(pipes) == -1) {
std::cerr << "#### ThreadExecutor::check, pipe() failed: "<< std::strerror(errno) << std::endl;
std::cerr << "#### ThreadExecutor::check, pipe() failed: "<< std::strerror(errno) << '\n';
std::exit(EXIT_FAILURE);
}

const int flags = fcntl(pipes[0], F_GETFL, 0);
if (flags < 0) {
std::cerr << "#### ThreadExecutor::check, fcntl(F_GETFL) failed: "<< std::strerror(errno) << std::endl;
std::cerr << "#### ThreadExecutor::check, fcntl(F_GETFL) failed: "<< std::strerror(errno) << '\n';
std::exit(EXIT_FAILURE);
}

if (fcntl(pipes[0], F_SETFL, flags) < 0) {
std::cerr << "#### ThreadExecutor::check, fcntl(F_SETFL) failed: "<< std::strerror(errno) << std::endl;
std::cerr << "#### ThreadExecutor::check, fcntl(F_SETFL) failed: "<< std::strerror(errno) << '\n';
std::exit(EXIT_FAILURE);
}

const pid_t pid = fork();
if (pid < 0) {
// Error
std::cerr << "#### ThreadExecutor::check, Failed to create child process: "<< std::strerror(errno) << std::endl;
std::cerr << "#### ThreadExecutor::check, Failed to create child process: "<< std::strerror(errno) << '\n';
std::exit(EXIT_FAILURE);
} else if (pid == 0) {
#if defined(__linux__)
Expand Down
2 changes: 1 addition & 1 deletion cli/threadexecutor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ unsigned int ThreadExecutor::check()
threadFutures.emplace_back(std::async(std::launch::async, &threadProc, &data));
}
catch (const std::system_error &e) {
std::cerr << "#### ThreadExecutor::check exception :" << e.what() << std::endl;
std::cerr << "#### ThreadExecutor::check exception :" << e.what() << '\n';
exit(EXIT_FAILURE);
}
}
Expand Down
4 changes: 2 additions & 2 deletions gui/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ static void ShowUsage()
);
(void)msgBox.exec();
#else
std::cout << helpMessage.toStdString() << std::endl;
std::cout << helpMessage.toStdString() << '\n';
#endif
}

Expand All @@ -136,6 +136,6 @@ static void ShowVersion()
if (*extraVersion != 0)
versionMessage += std::string(" (") + extraVersion + ")";

std::cout << versionMessage << std::endl;
std::cout << versionMessage << '\n';
#endif
}
2 changes: 1 addition & 1 deletion lib/analyzerinfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ std::string AnalyzerInformation::getFilesTxt(const std::list<std::string> &sourc
for (const FileSettings &fs : fileSettings) {
const std::string afile = getFilename(fs.filename());
const std::string id = fs.file.fsFileId() > 0 ? std::to_string(fs.file.fsFileId()) : "";
ret << afile << ".a" << (++fileCount[afile]) << sep << fs.cfg << sep << id << sep << Path::simplifyPath(fs.filename()) << std::endl;
ret << afile << ".a" << (++fileCount[afile]) << sep << fs.cfg << sep << id << sep << Path::simplifyPath(fs.filename()) << '\n';
}

return ret.str();
Expand Down
2 changes: 1 addition & 1 deletion lib/check.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ Check::Check(const std::string &aname)

void Check::writeToErrorList(const ErrorMessage &errmsg)
{
std::cout << errmsg.toXML() << std::endl;
std::cout << errmsg.toXML() << '\n';
}


Expand Down
28 changes: 14 additions & 14 deletions lib/checkersreport.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -160,23 +160,23 @@ std::string CheckersReport::getReport(const std::string& criticalErrors) const
{
std::ostringstream fout;

fout << "Critical errors" << std::endl;
fout << "---------------" << std::endl;
fout << "Critical errors" << '\n';
fout << "---------------" << '\n';
if (!criticalErrors.empty()) {
fout << "There were critical errors (" << criticalErrors << ")." << std::endl;
fout << "These cause the analysis of the file to end prematurely." << std::endl;
fout << "There were critical errors (" << criticalErrors << ")." << '\n';
fout << "These cause the analysis of the file to end prematurely." << '\n';
} else {
fout << "No critical errors encountered." << std::endl;
fout << "No critical errors encountered." << '\n';
// TODO: mention "information" and "debug" as source for indications of bailouts
// TODO: still rephrase this - this message does not provides confidence in the results
// TODO: document what a bailout is and why it is done - mention it in the upcoming security/tuning guide
// TODO: make bailouts a separate group - need to differentiate between user bailouts (missing data like configuration/includes) and internal bailouts (e.g. limitations of ValueFlow)
fout << "Note: There might still have been non-critical bailouts which might lead to false negatives." << std::endl;
fout << "Note: There might still have been non-critical bailouts which might lead to false negatives." << '\n';
}

fout << std::endl << std::endl;
fout << "Open source checkers" << std::endl;
fout << "--------------------" << std::endl;
fout << '\n' << '\n';
fout << "Open source checkers" << '\n';
fout << "--------------------" << '\n';

std::size_t maxCheckerSize = 0;
for (const auto& checkReq: checkers::allCheckers) {
Expand All @@ -190,13 +190,13 @@ std::string CheckersReport::getReport(const std::string& criticalErrors) const
fout << (active ? "Yes " : "No ") << checker;
if (!active && !req.empty())
fout << std::string(maxCheckerSize + 4 - checker.size(), ' ') << "require:" + req;
fout << std::endl;
fout << '\n';
}

for (const auto& addonInfo: mSettings.addonInfos) {
if (addonInfo.checkers.empty())
continue;
fout << std::endl << std::endl;
fout << '\n'<< '\n';
std::string title;
if (mSettings.premium && addonInfo.name == "premiumaddon.json")
title = "Cppcheck Premium";
Expand All @@ -206,8 +206,8 @@ std::string CheckersReport::getReport(const std::string& criticalErrors) const
title.erase(title.rfind('.'));
}
title += " checkers";
fout << title << std::endl;
fout << std::string(title.size(), '-') << std::endl;
fout << title << '\n';
fout << std::string(title.size(), '-') << '\n';

maxCheckerSize = 0;
for (const auto& checkReq: addonInfo.checkers) {
Expand All @@ -222,7 +222,7 @@ std::string CheckersReport::getReport(const std::string& criticalErrors) const
fout << (active ? "Yes " : "No ") << checker;
if (!active && !req.empty())
fout << std::string(maxCheckerSize + 4 - checker.size(), ' ') << "require:" << req;
fout << std::endl;
fout << '\n';
}
}

Expand Down
4 changes: 2 additions & 2 deletions lib/clangimport.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -508,12 +508,12 @@ void clangimport::AstNode::dumpAst(int num, int indent) const
std::cout << std::string(indent, ' ') << nodeType;
for (const auto& tok: mExtTokens)
std::cout << " " << tok;
std::cout << std::endl;
std::cout << '\n';
for (int c = 0; c < children.size(); ++c) {
if (children[c])
children[c]->dumpAst(c, indent + 2);
else
std::cout << std::string(indent + 2, ' ') << "<<<<NULL>>>>>" << std::endl;
std::cout << std::string(indent + 2, ' ') << "<<<<NULL>>>>>" << '\n';
}
}

Expand Down
Loading
Loading