]> https://gitweb.dealii.org/ - dealii-svn.git/commitdiff
Fix a problem where we access an element past the end of the array because we
authorbangerth <bangerth@0785d39b-7218-0410-832d-ea1e28bc413d>
Fri, 1 Jul 2011 03:10:05 +0000 (03:10 +0000)
committerbangerth <bangerth@0785d39b-7218-0410-832d-ea1e28bc413d>
Fri, 1 Jul 2011 03:10:05 +0000 (03:10 +0000)
call a function recursively and accidentally step on our own foot.

git-svn-id: https://svn.dealii.org/trunk@23901 0785d39b-7218-0410-832d-ea1e28bc413d

deal.II/source/base/polynomial.cc

index 8a505e9279a440fc05720bcb844ee80651972b7c..3567f6e84a68d6fa4fdbad07863910b69006a02d 100644 (file)
@@ -759,7 +759,25 @@ namespace Polynomials
                                        // no, then generate the
                                        // respective coefficients
       {
-        recursive_coefficients.resize (k+1);
+                                        // make sure that there is enough
+                                        // space in the array for the
+                                        // coefficients, so we have to resize
+                                        // it to size k+1
+       
+                                        // but it's more complicated than
+                                        // that: we call this function
+                                        // recursively, so if we simply
+                                        // resize it to k+1 here, then
+                                        // compute the coefficients for
+                                        // degree k-1 by calling this
+                                        // function recursively, then it will
+                                        // reset the size to k -- not enough
+                                        // for what we want to do below. the
+                                        // solution therefore is to only
+                                        // resize the size if we are going to
+                                        // *increase* it
+       if (recursive_coefficients.size() < k+1)
+         recursive_coefficients.resize (k+1);
 
         if (k<=1)
           {
@@ -995,7 +1013,25 @@ std::vector<Polynomial<double> > Lobatto::generate_complete_basis (const unsigne
                                            // no, then generate the
                                            // respective coefficients
       {
-        recursive_coefficients.resize (k+1);
+                                        // make sure that there is enough
+                                        // space in the array for the
+                                        // coefficients, so we have to resize
+                                        // it to size k+1
+       
+                                        // but it's more complicated than
+                                        // that: we call this function
+                                        // recursively, so if we simply
+                                        // resize it to k+1 here, then
+                                        // compute the coefficients for
+                                        // degree k-1 by calling this
+                                        // function recursively, then it will
+                                        // reset the size to k -- not enough
+                                        // for what we want to do below. the
+                                        // solution therefore is to only
+                                        // resize the size if we are going to
+                                        // *increase* it
+       if (recursive_coefficients.size() < k+1)
+         recursive_coefficients.resize (k+1);
 
         if (k<=1)
           {

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.