]> https://gitweb.dealii.org/ - dealii-svn.git/commitdiff
fix memory overwrite in step-42
authorfrohne <frohne@0785d39b-7218-0410-832d-ea1e28bc413d>
Tue, 12 Feb 2013 21:08:22 +0000 (21:08 +0000)
committerfrohne <frohne@0785d39b-7218-0410-832d-ea1e28bc413d>
Tue, 12 Feb 2013 21:08:22 +0000 (21:08 +0000)
git-svn-id: https://svn.dealii.org/trunk@28343 0785d39b-7218-0410-832d-ea1e28bc413d

deal.II/examples/step-42/step-42.cc

index d29261436ca3aefb45454ac42583f7769f2239b0..02da110ff749f34f25a47b69be1160da78e19b8f 100644 (file)
@@ -177,7 +177,7 @@ namespace Step42
 
       double hv(int i, int j);
 
-      double& set_height(int i, int j);
+      void set_height(int i, int j,double val);
 
       double mikro_height(double x,double y, double z);
 
@@ -196,13 +196,22 @@ namespace Step42
   template <int dim>
   double Input<dim>::hv(int i, int j)
   {
+    assert(i>=0 && i<nx);
+    assert(j>=0 && j<ny);
     return HV[nx*j+i];  // i indiziert x-werte, j indiziert y-werte
   }
 
   template <int dim>
-  double& Input<dim>::set_height(int i, int j)
+  void Input<dim>::set_height(int i, int j, double val)
   {
-    return HV[nx*j+i];  // i indiziert x-werte, j indiziert y-werte
+    if (i>=nx || j>=ny)
+      {
+       std::cout << "invalid:" << i << " " << j << " " << nx*j+i << std::endl;
+    return;
+      }
+    assert(i>=0 && i<nx);
+    assert(j>=0 && j<ny);
+    HV[nx*j+i]=val;  // i indiziert x-werte, j indiziert y-werte
   }
 
   template <int dim>
@@ -330,7 +339,7 @@ namespace Step42
             if (hlp < min_hlp)
               min_hlp=hlp;
 
-            set_height (k, ny - 1 - j) = hlp;
+            set_height (k, ny - 1 - j, hlp);
             int pos = strcspn (zeile, ",");
             if (!strpbrk (zeile, ","))
               {

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.