From 888701c9938dabf3285eefde88ebc7e13558824d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois-David=20Collin?= Date: Mon, 4 May 2020 19:11:29 +0200 Subject: [PATCH] guards for reading files --- src/readreftable.cpp | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/src/readreftable.cpp b/src/readreftable.cpp index 97956aa..75f33f4 100644 --- a/src/readreftable.cpp +++ b/src/readreftable.cpp @@ -29,6 +29,10 @@ Reftable readreftable(string headerpath, string reftablepath, size_t N if (!quiet) cout << "///////////////////////////////////////// read headers" << endl; ifstream headerStream(headerpath,ios::in); + if (headerStream.fail()){ + cout << "No header file, exiting" << endl; + exit(1); + } headerStream >> noskipws; const std::string hS(istream_iterator{headerStream}, {}); @@ -108,6 +112,10 @@ Reftable readreftable(string headerpath, string reftablepath, size_t N ifstream reftableStream(reftablepath,ios::in|ios::binary); + if (reftableStream.fail()){ + cout << "No Reftable, exiting" << endl; + exit(1); + } size_t realnrec = readAndCast(reftableStream); // reftableStream.read(reinterpret_cast(realnrec_i),sizeof(realnr)); size_t nrec = N > 0 ? min(realnrec,N) : realnrec; @@ -161,6 +169,10 @@ Reftable readreftable_scen(string headerpath, string reftablepath, siz if (!quiet) cout << "///////////////////////////////////////// read headers" << endl; ifstream headerStream(headerpath,ios::in); + if (headerStream.fail()){ + cout << "No header file, exiting" << endl; + exit(1); + } headerStream >> noskipws; const std::string hS(istream_iterator{headerStream}, {}); @@ -240,6 +252,10 @@ Reftable readreftable_scen(string headerpath, string reftablepath, siz ifstream reftableStream(reftablepath,ios::in|ios::binary); + if (headerStream.fail()){ + cout << "No Reftable, exiting" << endl; + exit(1); + } size_t realnrec = readAndCast(reftableStream); // reftableStream.read(reinterpret_cast(realnrec_i),sizeof(realnr)); if (N == 0) N = realnrec;