From 7076a54dfbcdbe62d64bfc472e8fbc7a1ff82285 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Basg=C3=B6ze?= Date: Wed, 15 Apr 2020 21:19:09 +0200 Subject: [PATCH] Add error checking to C style io --- .../storage/dd/sylvan/InternalSylvanAdd.cpp | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/src/storm/storage/dd/sylvan/InternalSylvanAdd.cpp b/src/storm/storage/dd/sylvan/InternalSylvanAdd.cpp index 2eddadd3a..5a3cdc954 100644 --- a/src/storm/storage/dd/sylvan/InternalSylvanAdd.cpp +++ b/src/storm/storage/dd/sylvan/InternalSylvanAdd.cpp @@ -803,16 +803,26 @@ namespace storm { void InternalAdd::exportToDot(std::string const& filename, std::vector const&, bool) const { // Open the file, dump the DD and close it again. FILE* filePointer = fopen(filename.c_str() , "a+"); - this->sylvanMtbdd.PrintDot(filePointer); - fclose(filePointer); + // fopen returns a nullptr on failure + if (filePointer == nullptr) { + STORM_LOG_ERROR("Failure to open file: " << filename); + } else { + this->sylvanMtbdd.PrintDot(filePointer); + fclose(filePointer); + } } template void InternalAdd::exportToText(std::string const& filename) const { // Open the file, dump the DD and close it again. FILE* filePointer = fopen(filename.c_str() , "a+"); - this->sylvanMtbdd.PrintText(filePointer); - fclose(filePointer); + // fopen returns a nullptr on failure + if (filePointer == nullptr) { + STORM_LOG_ERROR("Failure to open file: " << filename); + } else { + this->sylvanMtbdd.PrintText(filePointer); + fclose(filePointer); + } } template