@@ -281,6 +281,7 @@ static void createDumpFile(const Settings& settings,
281281
282282 {
283283 std::ofstream fout (getCtuInfoFileName (dumpFile));
284+ fout.exceptions (std::ios_base::failbit | std::ios_base::badbit);
284285 }
285286
286287 std::string language;
@@ -505,6 +506,7 @@ unsigned int CppCheck::check(const std::string &path)
505506 const std::string redirect2 = analyzerInfo.empty () ? std::string (" 2>&1" ) : (" 2> " + clangStderr);
506507 if (!mSettings .buildDir .empty ()) {
507508 std::ofstream fout (clangcmd);
509+ fout.exceptions (std::ios_base::failbit | std::ios_base::badbit);
508510 fout << exe << " " << args2 << " " << redirect2 << std::endl;
509511 } else if (mSettings .verbose && !mSettings .quiet ) {
510512 mErrorLogger .reportOut (exe + " " + args2);
@@ -536,6 +538,7 @@ unsigned int CppCheck::check(const std::string &path)
536538
537539 if (!mSettings .buildDir .empty ()) {
538540 std::ofstream fout (clangAst);
541+ fout.exceptions (std::ios_base::failbit | std::ios_base::badbit);
539542 fout << output2 << std::endl;
540543 }
541544
@@ -555,6 +558,7 @@ unsigned int CppCheck::check(const std::string &path)
555558
556559 // create dumpfile
557560 std::ofstream fdump;
561+ fdump.exceptions (std::ios_base::failbit | std::ios_base::badbit);
558562 std::string dumpFile;
559563 createDumpFile (mSettings , path, fdump, dumpFile);
560564 if (fdump.is_open ()) {
@@ -773,6 +777,7 @@ unsigned int CppCheck::checkFile(const std::string& filename, const std::string
773777
774778 // write dump file xml prolog
775779 std::ofstream fdump;
780+ fdump.exceptions (std::ios_base::failbit | std::ios_base::badbit);
776781 std::string dumpFile;
777782 createDumpFile (mSettings , filename, fdump, dumpFile);
778783 if (fdump.is_open ()) {
@@ -1423,6 +1428,7 @@ void CppCheck::executeAddons(const std::vector<std::string>& files)
14231428 if (files.size () >= 2 || endsWith (files[0 ], " .ctu-info" )) {
14241429 fileList = Path::getPathFromFilename (files[0 ]) + FILELIST;
14251430 std::ofstream fout (fileList);
1431+ fout.exceptions (std::ios_base::failbit | std::ios_base::badbit);
14261432 for (const std::string& f: files)
14271433 fout << f << std::endl;
14281434 }
@@ -1682,6 +1688,7 @@ void CppCheck::analyseClangTidy(const ImportProject::FileSettings &fileSettings)
16821688 if (!mSettings .buildDir .empty ()) {
16831689 const std::string analyzerInfoFile = AnalyzerInformation::getAnalyzerInfoFile (mSettings .buildDir , fileSettings.filename , emptyString);
16841690 std::ofstream fcmd (analyzerInfoFile + " .clang-tidy-cmd" );
1691+ fcmd.exceptions (std::ios_base::failbit | std::ios_base::badbit);
16851692 fcmd << istr.str ();
16861693 }
16871694
0 commit comments