[cgma-dev] r2160 - cgm/trunk/geom/OCC

kraftche at mcs.anl.gov kraftche at mcs.anl.gov
Mon Oct 20 15:22:33 CDT 2008


Author: kraftche
Date: 2008-10-20 15:22:33 -0500 (Mon, 20 Oct 2008)
New Revision: 2160

Modified:
   cgm/trunk/geom/OCC/OCCShapeAttributeSet.cpp
Log:
fix buffer overflows, memory leaks, non-portable code, assumption that attributes will never contain more than 10 numerical values, and other nastiness in parsing routine

Modified: cgm/trunk/geom/OCC/OCCShapeAttributeSet.cpp
===================================================================
--- cgm/trunk/geom/OCC/OCCShapeAttributeSet.cpp	2008-10-20 20:01:05 UTC (rev 2159)
+++ cgm/trunk/geom/OCC/OCCShapeAttributeSet.cpp	2008-10-20 20:22:33 UTC (rev 2160)
@@ -416,91 +416,57 @@
                                           Standard_IStream&   IS,
                                           TDF_Label& l_attr)
 {
-  char buffer[255];
+  std::string buffer, type, stringdata;
   DLIList<CubitString*> strings;
   DLIList<double> doubles;
   DLIList<int> ints;
   do {
     IS >> buffer; 
-    int i = 0;
-    while(buffer[i] != '*')
-      i++;
-    strings.clean_out(); 
-    char type[i];
-  
-    i = 0;
-    while(buffer[i] != '*')
-    {
-      type[i] = buffer[i];
-      i++;
-    }
-    CubitString string(type);
-    string = string.substr(0, i );
-    CubitString* string_prt = new CubitString(string);
+    std::string::size_type i = buffer.find_first_of("*");
+    type = buffer.substr( 0, i );
+
+    CubitString* string_prt = new CubitString(type.c_str());
     strings.append(string_prt);
 
     IS >> buffer;
     //consider there's only one string in the stringdata field
-    i = 0;
-    while(buffer[i] != '*')
-      i++;
-    char* stringdata = NULL;
+    i = buffer.find_first_of("*");
     if(i > 0)
     {
-      stringdata = new char[i];
-      i = 0;
-      while(buffer[i] != '*')
-      {
-        stringdata[i] = buffer[i];
-        i++;
-      }
-      CubitString string2(stringdata);
-      string2 = string2.substr(0, i );
-      CubitString* string_prt2 = new CubitString(string2);
+      stringdata = buffer.substr( 0, i );
+      CubitString* string_prt2 = new CubitString(stringdata.c_str());
       strings.append(string_prt2);
     }
 
     IS.get(); //' '
-    int  ints_[10];
-    double  doubles_[10]; 
+    int tmp_int;
+    double  tmp_dbl; 
     doubles.clean_out();
     ints.clean_out();
     char s;
     IS.get(s); //either '*' or 'number'
-    i = 0;
     while (s != '\n')
     {
       while(s != '*') // integer attributes
       {
         IS.unget(); 
-        IS >> ints_[i];
-        i++;
+        IS >> tmp_int;
+        ints.append( tmp_int );
         IS.get(); //' '
         IS.get(s); //either '*' or 'number'
       }
 
-      if(i > 0)
-      {
-        for(int j = 0; j < i; j++)
-          ints.append( ints_[j] );
-      }
-      i = 0;
       IS.get(); //' '
       IS.get(s); //either '*' or 'number'
       while(s != '*') // double attributes
       {
         IS.unget();
-        IS >> doubles_[i];
-        i++;
+        IS >> tmp_dbl;
+        doubles.append( tmp_dbl );
         IS.get(); //' '
         IS.get(s); //either '*' or 'number' 
       }
 
-      if(i > 0)
-      {
-        for(int j = 0; j < i; j++)
-          doubles.append(doubles_[j]);
-      }
       IS.get(s); //'\n' 
     }
     




More information about the cgma-dev mailing list