From a3d7e396b41c4006178ac4a24dfee1b52fb2d128 Mon Sep 17 00:00:00 2001 From: evomarc Date: Fri, 5 Dec 2003 05:39:40 +0000 Subject: [PATCH] There was an infinite loop in case of a file without section header on first line! --- eo/src/utils/eoState.cpp | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/eo/src/utils/eoState.cpp b/eo/src/utils/eoState.cpp index 814a4aaa..5d3797ba 100644 --- a/eo/src/utils/eoState.cpp +++ b/eo/src/utils/eoState.cpp @@ -98,8 +98,8 @@ void eoState::load(std::istream& is) string str = "Error while reading stream"; throw runtime_error(str); } - - while(is) + + while(! is.eof()) { // parse section header if (is_section(str, name)) { @@ -125,8 +125,10 @@ void eoState::load(std::istream& is) while (getline(is, str)) { - if (is_section(str, name)) - break; + if (is.eof()) + throw runtime_error("No section in load file"); + if (is_section(str, name)) + break; removeComment(str, getCommentString()); fullstring += str + "\n"; @@ -139,6 +141,12 @@ void eoState::load(std::istream& is) object->readFrom(the_stream); } } + else // if (is_section(str, name)) - what if file empty + { + getline(is, str); // try next line! + // if (is.eof()) + // throw runtime_error("No section in load file"); + } } }