From 738d05b442640e88619b023a74f735d3551328fc Mon Sep 17 00:00:00 2001 From: Dmitry-Me Date: Thu, 5 Jun 2014 11:28:04 +0400 Subject: [PATCH] Calling std::exit() in the middle of a C++ program subverts stack unwinding and can introduce subtle bugs. --- cli/cppcheckexecutor.cpp | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/cli/cppcheckexecutor.cpp b/cli/cppcheckexecutor.cpp index 6ac4f0dc2..0d351a876 100644 --- a/cli/cppcheckexecutor.cpp +++ b/cli/cppcheckexecutor.cpp @@ -81,10 +81,12 @@ bool CppCheckExecutor::parseFromArgs(CppCheck *cppcheck, int argc, const char* c std::cout << ErrorLogger::ErrorMessage::getXMLFooter(settings._xml_version) << std::endl; } - if (parser.ExitAfterPrinting()) - std::exit(EXIT_SUCCESS); + if (parser.ExitAfterPrinting()) { + settings.terminate(); + return true; + } } else { - std::exit(EXIT_FAILURE); + return false; } // Check that all include paths exist @@ -173,6 +175,9 @@ int CppCheckExecutor::check(int argc, const char* const argv[]) if (!parseFromArgs(&cppCheck, argc, argv)) { return EXIT_FAILURE; } + if (settings.terminated()) { + return EXIT_SUCCESS; + } if (cppCheck.settings().exceptionHandling) { return check_wrapper(cppCheck, argc, argv);