From cf00714bcfd875fadfcf415f1e9519365f5383ae Mon Sep 17 00:00:00 2001 From: bangerth Date: Fri, 1 Jul 2011 03:10:05 +0000 Subject: [PATCH] Fix a problem where we access an element past the end of the array because we 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 | 40 +++++++++++++++++++++++++++++-- 1 file changed, 38 insertions(+), 2 deletions(-) diff --git a/deal.II/source/base/polynomial.cc b/deal.II/source/base/polynomial.cc index 8a505e9279..3567f6e84a 100644 --- a/deal.II/source/base/polynomial.cc +++ b/deal.II/source/base/polynomial.cc @@ -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 > 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) { -- 2.39.5