From 1c7caca81f0b4872cf8aa2594b5f84355a976fc9 Mon Sep 17 00:00:00 2001
From: Christophe Geuzaine <cgeuzaine@ulg.ac.be>
Date: Thu, 16 Jul 2009 20:22:19 +0000
Subject: [PATCH] don't crash if >9 comps

---
 Plugin/Evaluate.cpp | 20 ++++++++++----------
 Plugin/Extract.cpp  |  2 +-
 2 files changed, 11 insertions(+), 11 deletions(-)

diff --git a/Plugin/Evaluate.cpp b/Plugin/Evaluate.cpp
index 442ecfd933..f8ede37a7a 100644
--- a/Plugin/Evaluate.cpp
+++ b/Plugin/Evaluate.cpp
@@ -3,6 +3,7 @@
 // See the LICENSE.txt file for license information. Please report all
 // bugs and problems to <gmsh@geuz.org>.
 
+#include <vector>
 #include "GmshConfig.h"
 #include "Evaluate.h"
 #include "OctreePost.h"
@@ -189,26 +190,25 @@ PView *GMSH_EvaluatePlugin::execute(PView *v)
     for(int ent = 0; ent < data1->getNumEntities(step); ent++){
       for(int ele = 0; ele < data1->getNumElements(step, ent); ele++){
 	if(data1->skipElement(step, ent, ele)) continue;
+        int numComp = data1->getNumComponents(step, ent, ele);
+        int numComp2 = data2->getNumComponents(step2, ent, ele);
         for(int nod = 0; nod < data1->getNumNodes(step, ent, ele); nod++){
           double x, y, z;
           int tag = data1->getNode(step, ent, ele, nod, x, y, z);
           if(tag) continue; // node has already been modified
-
-          double v[9] = {0., 0., 0., 0., 0., 0., 0., 0., 0.};
-	  for(int comp = 0; comp < data1->getNumComponents(step, ent, ele); comp++)
+          std::vector<double> v(numComp, 0.), w(numComp2, 0.);
+	  for(int comp = 0; comp < numComp; comp++)
 	    data1->getValue(step, ent, ele, nod, comp, v[comp]);
-
-          double w[9] = {0., 0., 0., 0., 0., 0., 0., 0., 0.};
           if(octree){
-            if(!octree->searchScalar(x, y, z, w, step2))
-              if(!octree->searchVector(x, y, z, w, step2))
-                octree->searchTensor(x, y, z, w, step2);
+            if(!octree->searchScalar(x, y, z, &w[0], step2))
+              if(!octree->searchVector(x, y, z, &w[0], step2))
+                octree->searchTensor(x, y, z, &w[0], step2);
           }
           else
-            for(int comp = 0; comp < data2->getNumComponents(step2, ent, ele); comp++)
+            for(int comp = 0; comp < numComp2; comp++)
               data2->getValue(step2, ent, ele, nod, comp, w[comp]);
           
-	  for(int comp = 0; comp < data1->getNumComponents(step, ent, ele); comp++){
+	  for(int comp = 0; comp < numComp; comp++){
             if(component >= 0 && component != comp) continue;
             char *names[] = 
               {"x", "y", "z", "Time", "TimeStep",
diff --git a/Plugin/Extract.cpp b/Plugin/Extract.cpp
index 99afe6518b..febc5a1152 100644
--- a/Plugin/Extract.cpp
+++ b/Plugin/Extract.cpp
@@ -246,7 +246,7 @@ PView *GMSH_ExtractPlugin::execute(PView *v)
       int timeEnd = (timeStep < 0) ? -timeStep : timeStep + 1;
       for(int step = timeBeg; step < timeEnd; step++){
         for(int nod = 0; nod < numNodes; nod++){
-          double v[9] = {0., 0., 0., 0., 0., 0., 0., 0., 0.};
+          std::vector<double> v(numComp);
           for(int comp = 0; comp < numComp; comp++)
 	    data1->getValue(step, ent, ele, nod, comp, v[comp]);
           for(int comp = 0; comp < numComp2; comp++){
-- 
GitLab