From cdd32c7f9b0f53a6a9e24e69ca4a01c7c13094ac Mon Sep 17 00:00:00 2001 From: Robert Wakim Date: Thu, 22 Jul 2021 15:13:51 +0100 Subject: [PATCH 1/4] cppcheck options: add --output-file-type option When used with tools such as cmake, cppcheck doesn't provide an convenient way to output into files. I've added two values for new --output-file-type option: uniq: this will create a output file name based on the --output-file and the current file(s) that are analyzed append: this will open the --output-file file in append mode and add the content to it example: Not using the new option: $ cppcheck --enable=all --xml --xml-version=2 --output-file=output_files/cppcheck.xml cli/cmdlineparser.cpp $ ls -la output_files/ total 12 drwxrwxr-x 2 user user 4096 Jul 22 14:47 . drwxrwxr-x 26 user user 4096 Jul 22 14:36 .. -rw-rw-r-- 1 user user 1283 Jul 22 14:47 cppcheck.xml Using the option with value "uniq" for one file: $ cppcheck --enable=all --xml --xml-version=2 --output-file=output_files/cppcheck.xml --output-file-type=uniq cli/cmdlineparser.cpp $ ls -la output_files/ total 12 drwxrwxr-x 2 user user 4096 Jul 22 14:48 . drwxrwxr-x 26 user user 4096 Jul 22 14:36 .. -rw-rw-r-- 1 user user 1283 Jul 22 14:48 cppcheck_cmdlineparser_cpp.xml Using the option with value "uniq" for two files: $ cppcheck --enable=all --xml --xml-version=2 --output-file=output_files/cppcheck.xml --output-file-type=uniq cli/cmdlineparser.cpp cli/cppcheckexecutor.cpp $ ls -la output_files/ total 16 drwxrwxr-x 2 user user 4096 Jul 22 14:49 . drwxrwxr-x 26 user user 4096 Jul 22 14:36 .. -rw-rw-r-- 1 user user 4308 Jul 22 14:49 cppcheck_cmdlineparser_cpp_cppcheckexecutor_cpp.xml Using the option with value "append" for one file on a empty/non-existing file: $ cppcheck --enable=all --xml --xml-version=2 --output-file=output_files/cppcheck.xml --output-file-type=append cli/cmdlineparser.cpp $ ls -la output_files/ total 12 drwxrwxr-x 2 user user 4096 Jul 22 14:51 . drwxrwxr-x 26 user user 4096 Jul 22 14:36 .. -rw-rw-r-- 1 user user 1283 Jul 22 14:51 cppcheck.xml Using the option with value "append" for two files on a empty/non-existing file: $ cppcheck --enable=all --xml --xml-version=2 --output-file=output_files/cppcheck.xml --output-file-type=append cli/cmdlineparser.cpp cli/cppcheckexecutor.cpp $ ls -la output_files/ total 16 drwxrwxr-x 2 user user 4096 Jul 22 14:53 . drwxrwxr-x 26 user user 4096 Jul 22 14:36 .. -rw-rw-r-- 1 user user 4308 Jul 22 14:53 cppcheck.xml Using the option with value twise "append" for one file on a empty/non-existing file: $ cppcheck --enable=all --xml --xml-version=2 --output-file=output_files/cppcheck.xml --output-file-type=append cli/cmdlineparser.cpp $ cppcheck --enable=all --xml --xml-version=2 --output-file=output_files/cppcheck.xml --output-file-type=append cli/cppcheckexecutor.cpp $ ls -la output_files/ total 16 drwxrwxr-x 2 user user 4096 Jul 22 14:54 . drwxrwxr-x 26 user user 4096 Jul 22 14:36 .. -rw-rw-r-- 1 user user 5613 Jul 22 14:55 cppcheck.xml /!\ the file is a pure concatenation of the files created without the "append" value which means that it's no more a valid XML file as it will have twice the "" entry $ cat output_files/cppcheck.xml [...] [...] Signed-off-by: Robert Wakim --- cli/cmdlineparser.cpp | 7 +++++++ cli/cppcheckexecutor.cpp | 21 ++++++++++++++++++++- lib/settings.h | 3 +++ 3 files changed, 30 insertions(+), 1 deletion(-) diff --git a/cli/cmdlineparser.cpp b/cli/cmdlineparser.cpp index 964fd55e7d6..ac4da192776 100644 --- a/cli/cmdlineparser.cpp +++ b/cli/cmdlineparser.cpp @@ -545,6 +545,10 @@ bool CmdLineParser::parseFromArgs(int argc, const char* const argv[]) else if (std::strncmp(argv[i], "--max-ctu-depth=", 16) == 0) mSettings->maxCtuDepth = std::atoi(argv[i] + 16); + // output file management + else if (std::strncmp(argv[i], "--output-file-type=", 19) == 0) + mSettings->outputFileType = Path::simplifyPath(Path::fromNativeSeparators(argv[i] + 19)); + // Write results in file else if (std::strncmp(argv[i], "--output-file=", 14) == 0) mSettings->outputFile = Path::simplifyPath(Path::fromNativeSeparators(argv[i] + 14)); @@ -1109,6 +1113,9 @@ void CmdLineParser::printHelp() " is 2. A larger value will mean more errors can be found\n" " but also means the analysis will be slower.\n" " --output-file= Write results to file, rather than standard error.\n" + " --output-file-type=\n" + " append: will append to file if it exists\n" + " uniq: will generate a filename base on --output-file and the files being analyzed\n" " --project= Run Cppcheck on project. The can be a Visual\n" " Studio Solution (*.sln), Visual Studio Project\n" " (*.vcxproj), compile database (compile_commands.json),\n" diff --git a/cli/cppcheckexecutor.cpp b/cli/cppcheckexecutor.cpp index 5066ff3d386..fa12abef875 100644 --- a/cli/cppcheckexecutor.cpp +++ b/cli/cppcheckexecutor.cpp @@ -893,7 +893,26 @@ int CppCheckExecutor::check_internal(CppCheck& cppcheck, int /*argc*/, const cha mLatestProgressOutputTime = std::time(nullptr); if (!settings.outputFile.empty()) { - mErrorOutput = new std::ofstream(settings.outputFile); + + if (settings.outputFileType == "append") { + using std::ios; + + mErrorOutput = new std::ofstream(settings.outputFile, ios::app); // open it in append mode + } else if (settings.outputFileType == "uniq") { + std::size_t extensionOffset = settings.outputFile.find_last_of("."); + std::string filename = settings.outputFile.substr(0, extensionOffset); + + for (std::map::const_iterator i = mFiles.begin(); i != mFiles.end(); ++i) { + std::size_t curFileNameOffset = i->first.find_last_of("/\\"); + std::string tmp = i->first.substr(curFileNameOffset + 1); + std::replace(tmp.begin(), tmp.end(), '.', '_'); + filename += "_" + tmp; + } + filename += settings.outputFile.substr(extensionOffset); + mErrorOutput = new std::ofstream(filename); // open it in uniq mode + } else { + mErrorOutput = new std::ofstream(settings.outputFile); + } } if (settings.xml) { diff --git a/lib/settings.h b/lib/settings.h index 2cfc2d60f65..b5979dabe13 100644 --- a/lib/settings.h +++ b/lib/settings.h @@ -246,6 +246,9 @@ class CPPCHECKLIB Settings : public cppcheck::Platform { /** @brief suppress message (--suppressions) */ Suppressions nomsg; + /** @brief write results type (--output-file-type=<None|append|uniq>) */ + std::string outputFileType; + /** @brief write results (--output-file=<file>) */ std::string outputFile; From 099fbe8be4ed0c3658555cfacd35acc6279d0112 Mon Sep 17 00:00:00 2001 From: Robert Wakim Date: Thu, 22 Jul 2021 15:13:51 +0100 Subject: [PATCH 2/4] cppcheck options: add --output-file-type option When used with tools such as cmake, cppcheck doesn't provide an convenient way to output into files. I've added two values for new --output-file-type option: uniq: this will create a output file name based on the --output-file and the current file(s) that are analyzed append: this will open the --output-file file in append mode and add the content to it example: Not using the new option: $ cppcheck --enable=all --xml --xml-version=2 --output-file=output_files/cppcheck.xml cli/cmdlineparser.cpp $ ls -la output_files/ total 12 drwxrwxr-x 2 user user 4096 Jul 22 14:47 . drwxrwxr-x 26 user user 4096 Jul 22 14:36 .. -rw-rw-r-- 1 user user 1283 Jul 22 14:47 cppcheck.xml Using the option with value "uniq" for one file: $ cppcheck --enable=all --xml --xml-version=2 --output-file=output_files/cppcheck.xml --output-file-type=uniq cli/cmdlineparser.cpp $ ls -la output_files/ total 12 drwxrwxr-x 2 user user 4096 Jul 22 14:48 . drwxrwxr-x 26 user user 4096 Jul 22 14:36 .. -rw-rw-r-- 1 user user 1283 Jul 22 14:48 cppcheck_cmdlineparser_cpp.xml Using the option with value "uniq" for two files: $ cppcheck --enable=all --xml --xml-version=2 --output-file=output_files/cppcheck.xml --output-file-type=uniq cli/cmdlineparser.cpp cli/cppcheckexecutor.cpp $ ls -la output_files/ total 16 drwxrwxr-x 2 user user 4096 Jul 22 14:49 . drwxrwxr-x 26 user user 4096 Jul 22 14:36 .. -rw-rw-r-- 1 user user 4308 Jul 22 14:49 cppcheck_cmdlineparser_cpp_cppcheckexecutor_cpp.xml Using the option with value "append" for one file on a empty/non-existing file: $ cppcheck --enable=all --xml --xml-version=2 --output-file=output_files/cppcheck.xml --output-file-type=append cli/cmdlineparser.cpp $ ls -la output_files/ total 12 drwxrwxr-x 2 user user 4096 Jul 22 14:51 . drwxrwxr-x 26 user user 4096 Jul 22 14:36 .. -rw-rw-r-- 1 user user 1283 Jul 22 14:51 cppcheck.xml Using the option with value "append" for two files on a empty/non-existing file: $ cppcheck --enable=all --xml --xml-version=2 --output-file=output_files/cppcheck.xml --output-file-type=append cli/cmdlineparser.cpp cli/cppcheckexecutor.cpp $ ls -la output_files/ total 16 drwxrwxr-x 2 user user 4096 Jul 22 14:53 . drwxrwxr-x 26 user user 4096 Jul 22 14:36 .. -rw-rw-r-- 1 user user 4308 Jul 22 14:53 cppcheck.xml Using the option with value twise "append" for one file on a empty/non-existing file: $ cppcheck --enable=all --xml --xml-version=2 --output-file=output_files/cppcheck.xml --output-file-type=append cli/cmdlineparser.cpp $ cppcheck --enable=all --xml --xml-version=2 --output-file=output_files/cppcheck.xml --output-file-type=append cli/cppcheckexecutor.cpp $ ls -la output_files/ total 16 drwxrwxr-x 2 user user 4096 Jul 22 14:54 . drwxrwxr-x 26 user user 4096 Jul 22 14:36 .. -rw-rw-r-- 1 user user 5613 Jul 22 14:55 cppcheck.xml /!\ the file is a pure concatenation of the files created without the "append" value which means that it's no more a valid XML file as it will have twice the "" entry $ cat output_files/cppcheck.xml [...] [...] Signed-off-by: Robert Wakim --- cli/cmdlineparser.cpp | 7 +++++++ cli/cppcheckexecutor.cpp | 20 +++++++++++++++++++- lib/settings.h | 3 +++ 3 files changed, 29 insertions(+), 1 deletion(-) diff --git a/cli/cmdlineparser.cpp b/cli/cmdlineparser.cpp index 964fd55e7d6..ac4da192776 100644 --- a/cli/cmdlineparser.cpp +++ b/cli/cmdlineparser.cpp @@ -545,6 +545,10 @@ bool CmdLineParser::parseFromArgs(int argc, const char* const argv[]) else if (std::strncmp(argv[i], "--max-ctu-depth=", 16) == 0) mSettings->maxCtuDepth = std::atoi(argv[i] + 16); + // output file management + else if (std::strncmp(argv[i], "--output-file-type=", 19) == 0) + mSettings->outputFileType = Path::simplifyPath(Path::fromNativeSeparators(argv[i] + 19)); + // Write results in file else if (std::strncmp(argv[i], "--output-file=", 14) == 0) mSettings->outputFile = Path::simplifyPath(Path::fromNativeSeparators(argv[i] + 14)); @@ -1109,6 +1113,9 @@ void CmdLineParser::printHelp() " is 2. A larger value will mean more errors can be found\n" " but also means the analysis will be slower.\n" " --output-file= Write results to file, rather than standard error.\n" + " --output-file-type=\n" + " append: will append to file if it exists\n" + " uniq: will generate a filename base on --output-file and the files being analyzed\n" " --project= Run Cppcheck on project. The can be a Visual\n" " Studio Solution (*.sln), Visual Studio Project\n" " (*.vcxproj), compile database (compile_commands.json),\n" diff --git a/cli/cppcheckexecutor.cpp b/cli/cppcheckexecutor.cpp index 5066ff3d386..5c0f845ccbb 100644 --- a/cli/cppcheckexecutor.cpp +++ b/cli/cppcheckexecutor.cpp @@ -893,7 +893,26 @@ int CppCheckExecutor::check_internal(CppCheck& cppcheck, int /*argc*/, const cha mLatestProgressOutputTime = std::time(nullptr); if (!settings.outputFile.empty()) { + + if (settings.outputFileType == "append") { + using std::ios; + + mErrorOutput = new std::ofstream(settings.outputFile, ios::app); // open it in append mode + } else if (settings.outputFileType == "uniq") { + std::size_t extensionOffset = settings.outputFile.find_last_of("."); + std::string filename = settings.outputFile.substr(0, extensionOffset); + + for (std::map::const_iterator i = mFiles.begin(); i != mFiles.end(); ++i) { + std::size_t curFileNameOffset = i->first.find_last_of("/\\"); + std::string tmp = i->first.substr(curFileNameOffset + 1); + std::replace(tmp.begin(), tmp.end(), '.', '_'); + filename += "_" + tmp; + } + filename += settings.outputFile.substr(extensionOffset); + mErrorOutput = new std::ofstream(filename); // open it in uniq mode + } else { mErrorOutput = new std::ofstream(settings.outputFile); + } } if (settings.xml) { @@ -1207,4 +1226,3 @@ bool CppCheckExecutor::executeCommand(std::string exe, std::vector *output_ += buffer; return true; } - diff --git a/lib/settings.h b/lib/settings.h index 2cfc2d60f65..b5979dabe13 100644 --- a/lib/settings.h +++ b/lib/settings.h @@ -246,6 +246,9 @@ class CPPCHECKLIB Settings : public cppcheck::Platform { /** @brief suppress message (--suppressions) */ Suppressions nomsg; + /** @brief write results type (--output-file-type=<None|append|uniq>) */ + std::string outputFileType; + /** @brief write results (--output-file=<file>) */ std::string outputFile; From 2c14929bee322f93b6de3b71f3ee0d2a72ff726e Mon Sep 17 00:00:00 2001 From: Robert Wakim Date: Thu, 29 Jul 2021 09:52:23 +0100 Subject: [PATCH 3/4] cppcheck options: add --output-file-type option When used with tools such as cmake, cppcheck doesn't provide an convenient way to output into files. I've added two values for new --output-file-type option: uniq: this will create a output file name based on the --output-file and the current file(s) that are analyzed append: this will open the --output-file file in append mode and add the content to it example: Not using the new option: $ cppcheck --enable=all --xml --xml-version=2 --output-file=output_files/cppcheck.xml cli/cmdlineparser.cpp $ ls -la output_files/ total 12 drwxrwxr-x 2 user user 4096 Jul 22 14:47 . drwxrwxr-x 26 user user 4096 Jul 22 14:36 .. -rw-rw-r-- 1 user user 1283 Jul 22 14:47 cppcheck.xml Using the option with value "uniq" for one file: $ cppcheck --enable=all --xml --xml-version=2 --output-file=output_files/cppcheck.xml --output-file-type=uniq cli/cmdlineparser.cpp $ ls -la output_files/ total 12 drwxrwxr-x 2 user user 4096 Jul 22 14:48 . drwxrwxr-x 26 user user 4096 Jul 22 14:36 .. -rw-rw-r-- 1 user user 1283 Jul 22 14:48 cppcheck_cmdlineparser_cpp.xml Using the option with value "uniq" for one file without extension: $ cppcheck --enable=all --xml --xml-version=2 --output-file=output_files/cppcheck --output-file-type=uniq cli/cmdlineparser.cpp $ ls -la output_files/ total 12 drwxrwxr-x 2 user user 4096 Jul 22 14:48 . drwxrwxr-x 26 user user 4096 Jul 22 14:36 .. -rw-rw-r-- 1 user user 1283 Jul 22 14:48 cppcheck_cmdlineparser_cpp Using the option with value "uniq" for two files: $ cppcheck --enable=all --xml --xml-version=2 --output-file=output_files/cppcheck.xml --output-file-type=uniq cli/cmdlineparser.cpp cli/cppcheckexecutor.cpp $ ls -la output_files/ total 16 drwxrwxr-x 2 user user 4096 Jul 22 14:49 . drwxrwxr-x 26 user user 4096 Jul 22 14:36 .. -rw-rw-r-- 1 user user 4308 Jul 22 14:49 cppcheck_cmdlineparser_cpp_cppcheckexecutor_cpp.xml Using the option with value "append" for one file on a empty/non-existing file: $ cppcheck --enable=all --xml --xml-version=2 --output-file=output_files/cppcheck.xml --output-file-type=append cli/cmdlineparser.cpp $ ls -la output_files/ total 12 drwxrwxr-x 2 user user 4096 Jul 22 14:51 . drwxrwxr-x 26 user user 4096 Jul 22 14:36 .. -rw-rw-r-- 1 user user 1283 Jul 22 14:51 cppcheck.xml Using the option with value "append" for two files on a empty/non-existing file: $ cppcheck --enable=all --xml --xml-version=2 --output-file=output_files/cppcheck.xml --output-file-type=append cli/cmdlineparser.cpp cli/cppcheckexecutor.cpp $ ls -la output_files/ total 16 drwxrwxr-x 2 user user 4096 Jul 22 14:53 . drwxrwxr-x 26 user user 4096 Jul 22 14:36 .. -rw-rw-r-- 1 user user 4308 Jul 22 14:53 cppcheck.xml Using the option with value twise "append" for one file on a empty/non-existing file: $ cppcheck --enable=all --xml --xml-version=2 --output-file=output_files/cppcheck.xml --output-file-type=append cli/cmdlineparser.cpp $ cppcheck --enable=all --xml --xml-version=2 --output-file=output_files/cppcheck.xml --output-file-type=append cli/cppcheckexecutor.cpp $ ls -la output_files/ total 16 drwxrwxr-x 2 user user 4096 Jul 22 14:54 . drwxrwxr-x 26 user user 4096 Jul 22 14:36 .. -rw-rw-r-- 1 user user 5613 Jul 22 14:55 cppcheck.xml /!\ the file is a pure concatenation of the files created without the "append" value which means that it's no more a valid XML file as it will have twice the "" entry $ cat output_files/cppcheck.xml [...] [...] Signed-off-by: Robert Wakim --- cli/cmdlineparser.cpp | 7 +++++++ cli/cppcheckexecutor.cpp | 23 ++++++++++++++++++++++- lib/settings.h | 3 +++ 3 files changed, 32 insertions(+), 1 deletion(-) diff --git a/cli/cmdlineparser.cpp b/cli/cmdlineparser.cpp index 964fd55e7d6..ac4da192776 100644 --- a/cli/cmdlineparser.cpp +++ b/cli/cmdlineparser.cpp @@ -545,6 +545,10 @@ bool CmdLineParser::parseFromArgs(int argc, const char* const argv[]) else if (std::strncmp(argv[i], "--max-ctu-depth=", 16) == 0) mSettings->maxCtuDepth = std::atoi(argv[i] + 16); + // output file management + else if (std::strncmp(argv[i], "--output-file-type=", 19) == 0) + mSettings->outputFileType = Path::simplifyPath(Path::fromNativeSeparators(argv[i] + 19)); + // Write results in file else if (std::strncmp(argv[i], "--output-file=", 14) == 0) mSettings->outputFile = Path::simplifyPath(Path::fromNativeSeparators(argv[i] + 14)); @@ -1109,6 +1113,9 @@ void CmdLineParser::printHelp() " is 2. A larger value will mean more errors can be found\n" " but also means the analysis will be slower.\n" " --output-file= Write results to file, rather than standard error.\n" + " --output-file-type=\n" + " append: will append to file if it exists\n" + " uniq: will generate a filename base on --output-file and the files being analyzed\n" " --project= Run Cppcheck on project. The can be a Visual\n" " Studio Solution (*.sln), Visual Studio Project\n" " (*.vcxproj), compile database (compile_commands.json),\n" diff --git a/cli/cppcheckexecutor.cpp b/cli/cppcheckexecutor.cpp index 5066ff3d386..ada93ffc096 100644 --- a/cli/cppcheckexecutor.cpp +++ b/cli/cppcheckexecutor.cpp @@ -893,7 +893,29 @@ int CppCheckExecutor::check_internal(CppCheck& cppcheck, int /*argc*/, const cha mLatestProgressOutputTime = std::time(nullptr); if (!settings.outputFile.empty()) { + + if (settings.outputFileType == "append") { + using std::ios; + + mErrorOutput = new std::ofstream(settings.outputFile, ios::app); // open it in append mode + } else if (settings.outputFileType == "uniq") { + std::string filename = settings.outputFile; + std::size_t extensionOffset = settings.outputFile.find_last_of("."); + if (extensionOffset != -1) + filename = filename.substr(0, extensionOffset); + + for (std::map::const_iterator i = mFiles.begin(); i != mFiles.end(); ++i) { + std::size_t curFileNameOffset = i->first.find_last_of("/\\"); + std::string tmp = i->first.substr(curFileNameOffset + 1); + std::replace(tmp.begin(), tmp.end(), '.', '_'); + filename += "_" + tmp; + } + if (extensionOffset != -1) + filename += settings.outputFile.substr(extensionOffset); + mErrorOutput = new std::ofstream(filename); // open it in uniq mode + } else { mErrorOutput = new std::ofstream(settings.outputFile); + } } if (settings.xml) { @@ -1207,4 +1229,3 @@ bool CppCheckExecutor::executeCommand(std::string exe, std::vector *output_ += buffer; return true; } - diff --git a/lib/settings.h b/lib/settings.h index 2cfc2d60f65..b5979dabe13 100644 --- a/lib/settings.h +++ b/lib/settings.h @@ -246,6 +246,9 @@ class CPPCHECKLIB Settings : public cppcheck::Platform { /** @brief suppress message (--suppressions) */ Suppressions nomsg; + /** @brief write results type (--output-file-type=<None|append|uniq>) */ + std::string outputFileType; + /** @brief write results (--output-file=<file>) */ std::string outputFile; From 165868308970ede80ae3015d718e7d7a4cd81797 Mon Sep 17 00:00:00 2001 From: Robert Wakim Date: Thu, 29 Jul 2021 09:52:23 +0100 Subject: [PATCH 4/4] cppcheck options: add --output-file-type option When used with tools such as cmake, cppcheck doesn't provide an convenient way to output into files. I've added two values for new --output-file-type option: uniq: this will create a output file name based on the --output-file and the current file(s) that are analyzed append: this will open the --output-file file in append mode and add the content to it example: Not using the new option: $ cppcheck --enable=all --xml --xml-version=2 --output-file=output_files/cppcheck.xml cli/cmdlineparser.cpp $ ls -la output_files/ total 12 drwxrwxr-x 2 user user 4096 Jul 22 14:47 . drwxrwxr-x 26 user user 4096 Jul 22 14:36 .. -rw-rw-r-- 1 user user 1283 Jul 22 14:47 cppcheck.xml Using the option with value "uniq" for one file: $ cppcheck --enable=all --xml --xml-version=2 --output-file=output_files/cppcheck.xml --output-file-type=uniq cli/cmdlineparser.cpp $ ls -la output_files/ total 12 drwxrwxr-x 2 user user 4096 Jul 22 14:48 . drwxrwxr-x 26 user user 4096 Jul 22 14:36 .. -rw-rw-r-- 1 user user 1283 Jul 22 14:48 cppcheck_cmdlineparser_cpp.xml Using the option with value "uniq" for one file without extension: $ cppcheck --enable=all --xml --xml-version=2 --output-file=output_files/cppcheck --output-file-type=uniq cli/cmdlineparser.cpp $ ls -la output_files/ total 12 drwxrwxr-x 2 user user 4096 Jul 22 14:48 . drwxrwxr-x 26 user user 4096 Jul 22 14:36 .. -rw-rw-r-- 1 user user 1283 Jul 22 14:48 cppcheck_cmdlineparser_cpp Using the option with value "uniq" for two files: $ cppcheck --enable=all --xml --xml-version=2 --output-file=output_files/cppcheck.xml --output-file-type=uniq cli/cmdlineparser.cpp cli/cppcheckexecutor.cpp $ ls -la output_files/ total 16 drwxrwxr-x 2 user user 4096 Jul 22 14:49 . drwxrwxr-x 26 user user 4096 Jul 22 14:36 .. -rw-rw-r-- 1 user user 4308 Jul 22 14:49 cppcheck_cmdlineparser_cpp_cppcheckexecutor_cpp.xml Using the option with value "append" for one file on a empty/non-existing file: $ cppcheck --enable=all --xml --xml-version=2 --output-file=output_files/cppcheck.xml --output-file-type=append cli/cmdlineparser.cpp $ ls -la output_files/ total 12 drwxrwxr-x 2 user user 4096 Jul 22 14:51 . drwxrwxr-x 26 user user 4096 Jul 22 14:36 .. -rw-rw-r-- 1 user user 1283 Jul 22 14:51 cppcheck.xml Using the option with value "append" for two files on a empty/non-existing file: $ cppcheck --enable=all --xml --xml-version=2 --output-file=output_files/cppcheck.xml --output-file-type=append cli/cmdlineparser.cpp cli/cppcheckexecutor.cpp $ ls -la output_files/ total 16 drwxrwxr-x 2 user user 4096 Jul 22 14:53 . drwxrwxr-x 26 user user 4096 Jul 22 14:36 .. -rw-rw-r-- 1 user user 4308 Jul 22 14:53 cppcheck.xml Using the option with value twise "append" for one file on a empty/non-existing file: $ cppcheck --enable=all --xml --xml-version=2 --output-file=output_files/cppcheck.xml --output-file-type=append cli/cmdlineparser.cpp $ cppcheck --enable=all --xml --xml-version=2 --output-file=output_files/cppcheck.xml --output-file-type=append cli/cppcheckexecutor.cpp $ ls -la output_files/ total 16 drwxrwxr-x 2 user user 4096 Jul 22 14:54 . drwxrwxr-x 26 user user 4096 Jul 22 14:36 .. -rw-rw-r-- 1 user user 5613 Jul 22 14:55 cppcheck.xml /!\ the file is a pure concatenation of the files created without the "append" value which means that it's no more a valid XML file as it will have twice the "" entry $ cat output_files/cppcheck.xml [...] [...] Signed-off-by: Robert Wakim --- cli/cppcheckexecutor.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/cli/cppcheckexecutor.cpp b/cli/cppcheckexecutor.cpp index ada93ffc096..269a869eab9 100644 --- a/cli/cppcheckexecutor.cpp +++ b/cli/cppcheckexecutor.cpp @@ -901,7 +901,7 @@ int CppCheckExecutor::check_internal(CppCheck& cppcheck, int /*argc*/, const cha } else if (settings.outputFileType == "uniq") { std::string filename = settings.outputFile; std::size_t extensionOffset = settings.outputFile.find_last_of("."); - if (extensionOffset != -1) + if (extensionOffset != std::string::npos) filename = filename.substr(0, extensionOffset); for (std::map::const_iterator i = mFiles.begin(); i != mFiles.end(); ++i) { @@ -910,7 +910,7 @@ int CppCheckExecutor::check_internal(CppCheck& cppcheck, int /*argc*/, const cha std::replace(tmp.begin(), tmp.end(), '.', '_'); filename += "_" + tmp; } - if (extensionOffset != -1) + if (extensionOffset != std::string::npos) filename += settings.outputFile.substr(extensionOffset); mErrorOutput = new std::ofstream(filename); // open it in uniq mode } else {