From 942bb517faf77144d9d16407a9d5c31f9037c155 Mon Sep 17 00:00:00 2001
From: Dominic Kempf <dominic.kempf@iwr.uni-heidelberg.de>
Date: Fri, 12 Jul 2013 13:50:15 +0200
Subject: [PATCH] add checking whether allocated array size is exceeded

---
 dune/istl/bcrsmatrix.hh | 13 ++++++++++++-
 1 file changed, 12 insertions(+), 1 deletion(-)

diff --git a/dune/istl/bcrsmatrix.hh b/dune/istl/bcrsmatrix.hh
index a6cf48be7..9239abf10 100644
--- a/dune/istl/bcrsmatrix.hh
+++ b/dune/istl/bcrsmatrix.hh
@@ -1089,7 +1089,7 @@ namespace Dune {
      *  performs compression of index and data arrays with linear
      *  complexity
      *
-     *  An object with some statistics about the compression form
+     *  An object with some statistics about the compression for
      *  future optimization is returned.
      */
     CompressionStatistics<size_type> compress()
@@ -1136,6 +1136,9 @@ namespace Dune {
           //check whether there are elements in the overflow area which take precedence
           while ((oit!=overflow.end()) && (oit->first < std::make_pair(i,**it)))
           {
+            //check whether allocated size is reached
+            if (jiit == j.get() + allocationSize)
+              DUNE_THROW(Dune::ISTLError,"Allocated Size for BCRSMatrix was not sufficient!");
             //copy and element from the overflow area to the insertion position in a and j
             *(++jiit) = oit->first.second;
             *(++aiit) = oit->second;
@@ -1143,6 +1146,10 @@ namespace Dune {
             r[i].setsize(r[i].getsize()+1);
           }
 
+          //check whether allocated size is reached
+          if (jiit == j.get() + allocationSize)
+            DUNE_THROW(Dune::ISTLError,"Allocated Size for BCRSMatrix was not sufficient!");
+
           //copy element from array
           *(++jiit) = **it;
           B* apos = *it-j.get()+a;
@@ -1152,6 +1159,10 @@ namespace Dune {
         //copy remaining elements from the overflow area
         while ((oit!=overflow.end()) && (oit->first.first == i))
         {
+          //check whether allocated size is reached
+          if (jiit == j.get() + allocationSize)
+            DUNE_THROW(Dune::ISTLError,"Allocated Size for BCRSMatrix was not sufficient!");
+
           //copy and element from the overflow area to the insertion position in a and j
           *(++jiit) = oit->first.second;
           *(++aiit) = oit->second;
-- 
GitLab