[MOAB-dev] r4127 - MOAB/trunk/src/io

sjackson at cae.wisc.edu sjackson at cae.wisc.edu
Mon Sep 20 11:55:49 CDT 2010


Author: sjackson
Date: 2010-09-20 11:55:48 -0500 (Mon, 20 Sep 2010)
New Revision: 4127

Modified:
   MOAB/trunk/src/io/ReadSmf.cpp
Log:
Fix a bug in the SMF reader, providing better resistance to malformed input.

This fixes an unusual condition in which the SMF reader would get stuck
in an infinite loop (if the failbit of ifstream 'smfFile' became true before
the end of file was reached).  In sufficiently unlucky circumstances, this
could cause the MOAB test suite to hang.

It's not obvious to me that MB_FILE_WRITE_ERROR is the correct error to
return on malformed input, but I have used this error code for
consistency with ReadSmf::parse_line().

Modified: MOAB/trunk/src/io/ReadSmf.cpp
===================================================================
--- MOAB/trunk/src/io/ReadSmf.cpp	2010-09-15 16:58:59 UTC (rev 4126)
+++ MOAB/trunk/src/io/ReadSmf.cpp	2010-09-20 16:55:48 UTC (rev 4127)
@@ -139,16 +139,18 @@
   ivar.next_vertex = 1;
   state.push_back( SMF_State(ivar) );
 
-  while( !smfFile.eof() )
-    {
-	if( smfFile.getline(line, SMF_MAXLINE, '\n').good() )
-        {
-            ++lineNo;
-	    result = parse_line(line);
-            if (MB_SUCCESS != result)
-    		return result;
-	}
-    }
+  while( smfFile.getline(line, SMF_MAXLINE, '\n').good() ){
+    	
+    ++lineNo;
+    result = parse_line(line);
+    if (MB_SUCCESS != result)
+      return result;
+  }
+  
+  if( !smfFile.eof() ){
+    // parsing terminated for a reason other than EOF: signal failure.
+    return MB_FILE_WRITE_ERROR;
+  }
 
   // at this point we have _numNodesInFile vertices and _numElementsInFile triangles
   // the coordinates are in _coords, and connectivities in _connec




















More information about the moab-dev mailing list