1
0
Fork 0
mirror of https://github.com/sockspls/badfish synced 2025-05-01 01:03:09 +00:00

Fix a crash due to a broken Book::open()

Bug introduced in 9dcc2aad98

We can be asked to open a non-exsistent file,
in this case we should gracefully handle the
case and silently return instead of exiting.

Bug discovered and bisected down by Joona.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
This commit is contained in:
Marco Costalba 2010-12-04 21:19:22 +01:00
parent 8a858aea34
commit 97a6e1559e

View file

@ -365,19 +365,21 @@ void Book::open(const string& fName) {
fileName = fName; fileName = fName;
ifstream::open(fileName.c_str(), ifstream::in | ifstream::binary); ifstream::open(fileName.c_str(), ifstream::in | ifstream::binary);
if (is_open()) // Silently return when asked to open a non-exsistent file
{ if (!is_open())
return;
// Get the book size in number of entries // Get the book size in number of entries
seekg(0, ios::end); seekg(0, ios::end);
bookSize = long(tellg()) / EntrySize; bookSize = long(tellg()) / EntrySize;
seekg(0, ios::beg); seekg(0, ios::beg);
if (good()) if (!good())
return; {
}
cerr << "Failed to open book file " << fileName << endl; cerr << "Failed to open book file " << fileName << endl;
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }
}
/// Book::file_name() returns the file name of the currently active book, /// Book::file_name() returns the file name of the currently active book,