]> https://gitweb.dealii.org/ - dealii.git/commitdiff
Fix a problem where we were reading past the end of an array.
authorWolfgang Bangerth <bangerth@math.tamu.edu>
Tue, 18 May 2004 19:07:16 +0000 (19:07 +0000)
committerWolfgang Bangerth <bangerth@math.tamu.edu>
Tue, 18 May 2004 19:07:16 +0000 (19:07 +0000)
git-svn-id: https://svn.dealii.org/trunk@9258 0785d39b-7218-0410-832d-ea1e28bc413d

deal.II/base/source/polynomial.cc

index 5f1461512ca8489b01136e073db213c4ca80cace..b7528f8d031048b1484c061e0a4b0c03e532e98a 100644 (file)
@@ -171,13 +171,14 @@ namespace Polynomials
   Polynomial<number>&
   Polynomial<number>::operator += (const Polynomial<number>& p)
   {
-//TODO:[GK] Is resize correct?    
-    if (p.degree() > degree())
-      coefficients.resize(p.coefficients.size());
-    typename std::vector<number>::const_iterator d = p.coefficients.begin();
-    for (typename std::vector<number>::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<p.coefficients.size(); ++i)
+      coefficients[i] += p.coefficients[i];
+
     return *this;
   }
 
@@ -186,12 +187,14 @@ namespace Polynomials
   Polynomial<number>&
   Polynomial<number>::operator -= (const Polynomial<number>& p)
   {
-    if (p.degree() > degree())
-      coefficients.resize(p.coefficients.size());
-    typename std::vector<number>::const_iterator d = p.coefficients.begin();
-    for (typename std::vector<number>::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<p.coefficients.size(); ++i)
+      coefficients[i] -= p.coefficients[i];
+
     return *this;
   }
 

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.