[MOAB-dev] r3075 - MOAB/trunk

kraftche at cae.wisc.edu kraftche at cae.wisc.edu
Thu Jul 30 12:22:08 CDT 2009


Author: kraftche
Date: 2009-07-30 12:22:08 -0500 (Thu, 30 Jul 2009)
New Revision: 3075

Modified:
   MOAB/trunk/ReadHDF5.cpp
Log:
fix minor bug (not encountered unless explicitly changing buffer size using file read option, which is only done by testing code.)

Modified: MOAB/trunk/ReadHDF5.cpp
===================================================================
--- MOAB/trunk/ReadHDF5.cpp	2009-07-30 17:02:55 UTC (rev 3074)
+++ MOAB/trunk/ReadHDF5.cpp	2009-07-30 17:22:08 UTC (rev 3075)
@@ -2109,13 +2109,25 @@
   long sets_per_buffer = bufferSize / (sizeof(long) + (avg_set_len+1)*sizeof(MBEntityHandle));
     // round to down multiple of 8 to avoid alignment issues
   sets_per_buffer = 8 * (sets_per_buffer / 8);
-  if (sets_per_buffer < 10) // just in case there's one huge set
+  if (sets_per_buffer < 10) { // just in case there's one huge set
     sets_per_buffer = 10;  
+    if (sets_per_buffer * (long)sizeof(long) > bufferSize) 
+      sets_per_buffer = bufferSize/(sizeof(long)+2*sizeof(MBEntityHandle));
+  }
   long* offset_buffer = (long*)dataBuffer;
   MBEntityHandle* content_buffer = (MBEntityHandle*)(offset_buffer + sets_per_buffer);
   assert(bufferSize % sizeof(long) == 0);
   long content_size = (MBEntityHandle*)(dataBuffer + bufferSize) - content_buffer;
   assert(dataBuffer + bufferSize >= (char*)(content_buffer + content_size));
+    // content_size must be an even number or we might end up with half of a 
+    // range pair in the buffer, which will break code below
+  if (content_size % 2)
+    --content_size;
+    
+  if (!sets_per_buffer || !content_size) {
+      // buffer is too small to be usable
+    return MB_FAILURE;
+  }
  
   MBRange ranged_ids(ranged_ids_in);
   MBEntityHandle h = start_handle;



More information about the moab-dev mailing list