Skip to content
Snippets Groups Projects
Commit 8349b4fb authored by Jonathan Youett's avatar Jonathan Youett Committed by Markus Blatt
Browse files

[bugfix] Fixes assignment of BCRSMatrix with nonmatching number of rows.

When assigning a BCRSMatrix to another BCRSMatrix which was setup for
a different size/pattern, it segfaulted and I got the following
Exception:

"InvalidStateException [allocate:.../dune/istl/bcrsmatrix.hh:2108]:
Rows have already been allocated, cannot allocate a second time."

The problem was, that inside the assignment operator the rows (r) were
never deallocated. This commit fixes this and adds a testcase.

Testcase slightly modified by Markus.
parent 01655f01
No related branches found
No related tags found
No related merge requests found
......@@ -30,7 +30,7 @@ Copyright holders:
2013 Bård Skaflestad
2006--2010 Martin Weiser
2011--2012 Matthias Wohlmuth
2014 Jonathan Youett
The DUNE library and headers are licensed under version 2 of the GNU
General Public License (see below), with a special exception for
......
......@@ -875,7 +875,8 @@ namespace Dune {
DUNE_THROW(InvalidStateException,"BCRSMatrix can only be copied when both target and source are empty or fully built)");
// make it simple: ALWAYS throw away memory for a and j
deallocate(false);
// and deallocate rows only if n != Mat.n
deallocate(n!=Mat.n);
// reallocate the rows if required
if (n>0 && n!=Mat.n) {
......
#include <config.h>
#include <dune/istl/bcrsmatrix.hh>
using namespace Dune;
int main (int argc, char** argv)
{
try
{
typedef BCRSMatrix<FieldMatrix<double,2,2> > Mat;
Mat A(1,1, Mat::random);
A.setrowsize(0,1);
A.endrowsizes();
A.addindex(0, 0);
A.endindices();
A = 0;
Mat B(2,2, Mat::random);
B.setrowsize(0,2);
B.setrowsize(1,1);
B.endrowsizes();
B.addindex(0, 0);
B.addindex(0, 1);
B.addindex(1, 1);
B.endindices();
B = 0;
B = A;
} catch(Exception e){
std::cout<<e<<std::endl;
return 1;
}
return 0;
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment