]> https://gitweb.dealii.org/ - dealii.git/commitdiff
fix invalid memory access in gridin::read_vtk
authorTimo Heister <timo.heister@gmail.com>
Fri, 24 Jan 2014 16:05:50 +0000 (16:05 +0000)
committerTimo Heister <timo.heister@gmail.com>
Fri, 24 Jan 2014 16:05:50 +0000 (16:05 +0000)
git-svn-id: https://svn.dealii.org/trunk@32299 0785d39b-7218-0410-832d-ea1e28bc413d

deal.II/source/grid/grid_in.cc

index c41f034ca33ed2f3e08743c08d53fb63fea3fe84..c3072c1218d08453f3027fcd06dc7d34fed1e05a 100644 (file)
@@ -84,13 +84,13 @@ void GridIn<dim, spacedim>::read_vtk(std::istream &in)
 
   unsigned int no_vertices, no_quads=0,no_lines=0;
 
-  char keyword_1[7],keyword_2[6],keyword_3[10] ;//keywords for the three types of data
+  std::string keyword;
 
-  in.get(keyword_1, 7);
+  in >> keyword;
 
   //////////////////Processing the POINTS section///////////////
 
-  if (std::strcmp(keyword_1,"POINTS") == 0)//comparing the keyword points
+  if (keyword == "POINTS")
     {
       in>>no_vertices;// taking the no. of vertices
       in.ignore(256, '\n');//ignoring the number beside the total no. of points.
@@ -120,24 +120,19 @@ void GridIn<dim, spacedim>::read_vtk(std::istream &in)
   in.ignore(256, '\n');//this move pointer to the next line ignoring unwanted no.
   no = in.tellg();
   getline(in,checkline);
-  if (checkline.compare("") == 0)
-    {
-      in.get(keyword_2, 6);
-    }
-  else
+  if (checkline.compare("") != 0)
     {
       in.seekg(no);
-      in.get(keyword_2, 6);
     }
 
+  in >> keyword;
 
   unsigned int total_cells, no_cells = 0, type, j = 0;// declaring counters, refer to the order of declaring variables for an idea of what is what!
 
   ///////////////////Processing the CELLS section that contains cells(cells) and bound_quads(subcelldata)///////////////////////
 
-  if (std::strcmp(keyword_2,"CELLS") == 0)//comparing the keyword cells.
+  if (keyword == "CELLS")
     {
-
       in>>total_cells;
       in.ignore(256,'\n');
 
@@ -244,16 +239,16 @@ void GridIn<dim, spacedim>::read_vtk(std::istream &in)
 
       /////////////////////Processing the CELL_TYPES section////////////////////////
 
-      in>>keyword_3;
+      in >> keyword;
 
-      if (std::strcmp(keyword_3,"CELL_TYPES") == 0)//Entering the cell_types section and ignoring data.
+      if (keyword == "CELL_TYPES")//Entering the cell_types section and ignoring data.
         {
           in.ignore(256, '\n');
 
           while (!in.eof())
             {
-              in>>keyword_3;
-              if (std::strcmp(keyword_3,"12") && std::strcmp(keyword_3,"9"))
+              in>>keyword;
+              if (keyword != "12" && keyword != "9")
                 {
                   break;
                 }
@@ -262,7 +257,7 @@ void GridIn<dim, spacedim>::read_vtk(std::istream &in)
 
       ////////////////////////Processing the CELL_DATA section/////////////////////////////
 
-      if (std::strcmp(keyword_3,"CELL_DATA") == 0)
+      if (keyword == "CELL_DATA")
         {
           int no_ids;
           in>>no_ids;

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.