From: Wolfgang Bangerth Date: Thu, 3 Nov 2016 17:56:41 +0000 (-0600) Subject: Be more careful with streams. X-Git-Tag: v8.5.0-rc1~485^2 X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=34d0b1c07f3b978a17981b78a7b898e743f474fe;p=dealii.git Be more careful with streams. In particular, stop also if in.fail() is true, not just if in.eof() is true. I suspect that it matters little in practice, but who knows. --- diff --git a/source/grid/grid_in.cc b/source/grid/grid_in.cc index b101d32742..9a06ab8156 100644 --- a/source/grid/grid_in.cc +++ b/source/grid/grid_in.cc @@ -293,7 +293,7 @@ void GridIn::read_vtk(std::istream &in) { in.ignore(256, '\n'); - while (!in.eof()) + while (!in.fail() && !in.eof()) { in>>keyword; if (keyword != "12" && keyword != "9") @@ -2988,7 +2988,7 @@ namespace std::string line; std::getline (input_stream, line); - while (!input_stream.eof()) + while (!input_stream.fail() && !input_stream.eof()) { std::transform(line.begin(), line.end(), line.begin(), ::toupper); @@ -2997,7 +2997,7 @@ namespace line.compare (0, 5, "*PART") == 0) { // Skip header and comments - while (!input_stream.eof()) + while (!input_stream.fail() && !input_stream.eof()) { std::getline (input_stream, line); if (line[0] == '*') @@ -3013,7 +3013,7 @@ namespace // Contains lines in the form: // Index, x, y, z - while (!input_stream.eof()) + while (!input_stream.fail() && !input_stream.eof()) { std::getline (input_stream, line); if (line[0] == '*') @@ -3054,7 +3054,7 @@ namespace // Read ELEMENT definition std::getline (input_stream, line); - while (!input_stream.eof()) + while (!input_stream.fail() && !input_stream.eof()) { if (line[0] == '*') goto cont; @@ -3102,7 +3102,7 @@ namespace // definition of each "set" of faces that comprise the surface // These are either marked by an "S" or "E" in 3d or 2d respectively. std::getline (input_stream, line); - while (!input_stream.eof()) + while (!input_stream.fail() && !input_stream.eof()) { if (line[0] == '*') goto cont; @@ -3202,7 +3202,7 @@ namespace { // Option (2) std::getline (input_stream, line); - while (!input_stream.eof()) + while (!input_stream.fail() && !input_stream.eof()) { if (line[0] == '*') break; @@ -3227,7 +3227,7 @@ namespace else if (line.compare (0, 5, "*NSET") == 0) { // Skip nodesets; we have no use for them - while (!input_stream.eof()) + while (!input_stream.fail() && !input_stream.eof()) { std::getline (input_stream, line); if (line[0] == '*')