From ad3e5a8ecd2bf8a2c982cf5f6dca3d339f6dc452 Mon Sep 17 00:00:00 2001 From: Wolfgang Bangerth Date: Tue, 18 May 2004 19:07:16 +0000 Subject: [PATCH] Fix a problem where we were reading past the end of an array. git-svn-id: https://svn.dealii.org/trunk@9258 0785d39b-7218-0410-832d-ea1e28bc413d --- deal.II/base/source/polynomial.cc | 29 ++++++++++++++++------------- 1 file changed, 16 insertions(+), 13 deletions(-) diff --git a/deal.II/base/source/polynomial.cc b/deal.II/base/source/polynomial.cc index 5f1461512c..b7528f8d03 100644 --- a/deal.II/base/source/polynomial.cc +++ b/deal.II/base/source/polynomial.cc @@ -171,13 +171,14 @@ namespace Polynomials Polynomial& Polynomial::operator += (const Polynomial& p) { -//TODO:[GK] Is resize correct? - if (p.degree() > degree()) - coefficients.resize(p.coefficients.size()); - typename std::vector::const_iterator d = p.coefficients.begin(); - for (typename std::vector::iterator c = coefficients.begin(); - c != coefficients.end(); ++c, ++d) - *c += *d; + // if necessary expand the number + // of coefficients we store + if (p.coefficients.size() > coefficients.size()) + coefficients.resize (p.coefficients.size(), 0.); + + for (unsigned int i=0; i& Polynomial::operator -= (const Polynomial& p) { - if (p.degree() > degree()) - coefficients.resize(p.coefficients.size()); - typename std::vector::const_iterator d = p.coefficients.begin(); - for (typename std::vector::iterator c = coefficients.begin(); - c != coefficients.end(); ++c, ++d) - *c -= *d; + // if necessary expand the number + // of coefficients we store + if (p.coefficients.size() > coefficients.size()) + coefficients.resize (p.coefficients.size(), 0.); + + for (unsigned int i=0; i