[MOAB-dev] r3180 - MOAB/trunk

kraftche at cae.wisc.edu kraftche at cae.wisc.edu
Wed Sep 30 16:47:12 CDT 2009


Author: kraftche
Date: 2009-09-30 16:47:12 -0500 (Wed, 30 Sep 2009)
New Revision: 3180

Modified:
   MOAB/trunk/ReadSTL.cpp
Log:
fix bug reading binary STL files that require byte swapping

Modified: MOAB/trunk/ReadSTL.cpp
===================================================================
--- MOAB/trunk/ReadSTL.cpp	2009-09-30 21:46:42 UTC (rev 3179)
+++ MOAB/trunk/ReadSTL.cpp	2009-09-30 21:47:12 UTC (rev 3180)
@@ -357,9 +357,9 @@
     // num_tri, resulting in a SEGFAULT. 
   
     // Get expected number of triangles
+  if (swap_bytes)
+    MBSysUtil::byteswap( &header.count, 1 );
   unsigned long num_tri = header.count;
-  if (swap_bytes)
-    MBSysUtil::byteswap( &num_tri, 1 );
   
     // Get the file length
   long filesize = MBSysUtil::filesize( file );
@@ -371,8 +371,9 @@
     {
         // Unless the byte order was specified explicitly in the 
         // tag, try the opposite byte order.
-      unsigned long num_tri_swap = num_tri;
-      MBSysUtil::byteswap( &num_tri_swap, 1 );
+      uint32_t num_tri_tmp = header.count;
+      MBSysUtil::byteswap( &num_tri_tmp, 1 );
+      unsigned long num_tri_swap = num_tri_tmp;
       if (byte_order != STL_UNKNOWN_BYTE_ORDER || // If byte order was specified, fail now
           ULONG_MAX / 50 - 84 < num_tri_swap  || // watch for overflow in next line
           84 + 50 * num_tri_swap != (unsigned long)filesize)



More information about the moab-dev mailing list