@@ -276,11 +276,16 @@ static void createDumpFile(const Settings& settings,
276
276
dumpFile = getDumpFileName (settings, filename);
277
277
278
278
fdump.open (dumpFile);
279
+
280
+ // TODO: Technically, exceptions are allowed on the file so this is always false,
281
+ // TODO: but the function is not aware of that as this function is not the owner of the file
279
282
if (!fdump.is_open ())
280
283
return ;
281
284
282
285
{
283
- std::ofstream fout (getCtuInfoFileName (dumpFile));
286
+ std::ofstream fout;
287
+ fout.exceptions (std::ios_base::failbit | std::ios_base::badbit);
288
+ fout.open (getCtuInfoFileName (dumpFile));
284
289
}
285
290
286
291
std::string language;
@@ -396,7 +401,9 @@ CppCheck::CppCheck(ErrorLogger &errorLogger,
396
401
, mTooManyConfigs(false )
397
402
, mSimplify(true )
398
403
, mExecuteCommand(std::move(executeCommand))
399
- {}
404
+ {
405
+ mPlistFile .exceptions (std::ios_base::failbit | std::ios_base::badbit);
406
+ }
400
407
401
408
CppCheck::~CppCheck ()
402
409
{
@@ -408,7 +415,16 @@ CppCheck::~CppCheck()
408
415
409
416
if (mPlistFile .is_open ()) {
410
417
mPlistFile << ErrorLogger::plistFooter ();
411
- mPlistFile .close ();
418
+
419
+ try
420
+ {
421
+ mPlistFile .close ();
422
+ }
423
+ catch (const std::ios_base::failure&)
424
+ {
425
+ // TODO report error
426
+ assert (false );
427
+ }
412
428
}
413
429
}
414
430
@@ -504,7 +520,9 @@ unsigned int CppCheck::check(const std::string &path)
504
520
const std::string args2 = " -fsyntax-only -Xclang -ast-dump -fno-color-diagnostics " + flags + path;
505
521
const std::string redirect2 = analyzerInfo.empty () ? std::string (" 2>&1" ) : (" 2> " + clangStderr);
506
522
if (!mSettings .buildDir .empty ()) {
507
- std::ofstream fout (clangcmd);
523
+ std::ofstream fout;
524
+ fout.exceptions (std::ios_base::failbit | std::ios_base::badbit);
525
+ fout.open (clangcmd);
508
526
fout << exe << " " << args2 << " " << redirect2 << std::endl;
509
527
} else if (mSettings .verbose && !mSettings .quiet ) {
510
528
mErrorLogger .reportOut (exe + " " + args2);
@@ -535,7 +553,9 @@ unsigned int CppCheck::check(const std::string &path)
535
553
}
536
554
537
555
if (!mSettings .buildDir .empty ()) {
538
- std::ofstream fout (clangAst);
556
+ std::ofstream fout;
557
+ fout.exceptions (std::ios_base::failbit | std::ios_base::badbit);
558
+ fout.open (clangAst);
539
559
fout << output2 << std::endl;
540
560
}
541
561
@@ -555,6 +575,7 @@ unsigned int CppCheck::check(const std::string &path)
555
575
556
576
// create dumpfile
557
577
std::ofstream fdump;
578
+ fdump.exceptions (std::ios_base::failbit | std::ios_base::badbit);
558
579
std::string dumpFile;
559
580
createDumpFile (mSettings , path, fdump, dumpFile);
560
581
if (fdump.is_open ()) {
@@ -773,6 +794,7 @@ unsigned int CppCheck::checkFile(const std::string& filename, const std::string
773
794
774
795
// write dump file xml prolog
775
796
std::ofstream fdump;
797
+ fdump.exceptions (std::ios_base::failbit | std::ios_base::badbit);
776
798
std::string dumpFile;
777
799
createDumpFile (mSettings , filename, fdump, dumpFile);
778
800
if (fdump.is_open ()) {
@@ -1422,7 +1444,9 @@ void CppCheck::executeAddons(const std::vector<std::string>& files)
1422
1444
1423
1445
if (files.size () >= 2 || endsWith (files[0 ], " .ctu-info" )) {
1424
1446
fileList = Path::getPathFromFilename (files[0 ]) + FILELIST;
1425
- std::ofstream fout (fileList);
1447
+ std::ofstream fout;
1448
+ fout.exceptions (std::ios_base::failbit | std::ios_base::badbit);
1449
+ fout.open (fileList);
1426
1450
for (const std::string& f: files)
1427
1451
fout << f << std::endl;
1428
1452
}
@@ -1681,7 +1705,10 @@ void CppCheck::analyseClangTidy(const ImportProject::FileSettings &fileSettings)
1681
1705
1682
1706
if (!mSettings .buildDir .empty ()) {
1683
1707
const std::string analyzerInfoFile = AnalyzerInformation::getAnalyzerInfoFile (mSettings .buildDir , fileSettings.filename , emptyString);
1684
- std::ofstream fcmd (analyzerInfoFile + " .clang-tidy-cmd" );
1708
+
1709
+ std::ofstream fcmd;
1710
+ fcmd.exceptions (std::ios_base::failbit | std::ios_base::badbit);
1711
+ fcmd.open (analyzerInfoFile + " .clang-tidy-cmd" );
1685
1712
fcmd << istr.str ();
1686
1713
}
1687
1714
0 commit comments