From: Marco Costalba Date: Sat, 4 Dec 2010 20:19:22 +0000 (+0100) Subject: Fix a crash due to a broken Book::open() X-Git-Url: https://git.sesse.net/?p=stockfish;a=commitdiff_plain;h=97a6e1559e78dd31a5ecec9f3b35181f82942823;hp=8a858aea34940920f9cd44e3006a632077e9f6ab Fix a crash due to a broken Book::open() Bug introduced in 9dcc2aad98b9703 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 --- diff --git a/src/book.cpp b/src/book.cpp index 95ccd690..9528e47c 100644 --- a/src/book.cpp +++ b/src/book.cpp @@ -365,18 +365,20 @@ void Book::open(const string& fName) { fileName = fName; ifstream::open(fileName.c_str(), ifstream::in | ifstream::binary); - if (is_open()) - { - // Get the book size in number of entries - seekg(0, ios::end); - bookSize = long(tellg()) / EntrySize; - seekg(0, ios::beg); + // Silently return when asked to open a non-exsistent file + if (!is_open()) + return; + + // Get the book size in number of entries + seekg(0, ios::end); + bookSize = long(tellg()) / EntrySize; + seekg(0, ios::beg); - if (good()) - return; + if (!good()) + { + cerr << "Failed to open book file " << fileName << endl; + exit(EXIT_FAILURE); } - cerr << "Failed to open book file " << fileName << endl; - exit(EXIT_FAILURE); }