]> https://gitweb.dealii.org/ - dealii.git/commitdiff
Be more careful with streams. 3437/head
authorWolfgang Bangerth <bangerth@colostate.edu>
Thu, 3 Nov 2016 17:56:41 +0000 (11:56 -0600)
committerWolfgang Bangerth <bangerth@colostate.edu>
Thu, 3 Nov 2016 17:56:41 +0000 (11:56 -0600)
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.

source/grid/grid_in.cc

index b101d3274220bea24af2129d81be08caaad65421..9a06ab8156088914693c7030cb709e63345d0c73 100644 (file)
@@ -293,7 +293,7 @@ void GridIn<dim, spacedim>::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] == '*')

In the beginning the Universe was created. This has made a lot of people very angry and has been widely regarded as a bad move.

Douglas Adams


Typeset in Trocchi and Trocchi Bold Sans Serif.