From a0bff03560b4413500161c5d45ba38bf41d25341 Mon Sep 17 00:00:00 2001 From: scrawl Date: Sat, 7 Jun 2014 17:58:03 +0200 Subject: [PATCH] Fix not handling failbit/badbit in ifstream (Bug #1355) --- components/translation/translation.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/components/translation/translation.cpp b/components/translation/translation.cpp index 423c3971a..976ae926d 100644 --- a/components/translation/translation.cpp +++ b/components/translation/translation.cpp @@ -32,6 +32,9 @@ namespace Translation boost::filesystem::ifstream stream ( dataFileCollections.getCollection (extension).getPath (fileName)); + // Configure the stream to throw exception upon error + stream.exceptions ( boost::filesystem::ifstream::failbit | boost::filesystem::ifstream::badbit ); + if (!stream.is_open()) throw std::runtime_error ("failed to open translation file: " + fileName); @@ -41,6 +44,7 @@ namespace Translation void Storage::loadDataFromStream(ContainerType& container, std::istream& stream) { + // NOTE: does not handle failbit/badbit. stream must be set up beforehand to throw in these cases. std::string line; while (!stream.eof()) {