Memory corruption when calling BCRSMatrix::setSize with three arguments
Something fishy goes on when calling BCRSMatrix::setSize with three arguments (the third is the number of nonzeros). To reproduce, simply run matrixtest under valgrind:
~/dune/dune-istl/build-cmake/dune/istl/test(master)> valgrind ./matrixtest
==4936== Memcheck, a memory error detector
==4936== Copyright (C) 2002-2017, and GNU GPL'd, by Julian Seward et al.
==4936== Using Valgrind-3.13.0 and LibVEX; rerun with -h for copyright info
==4936== Command: ./matrixtest
==4936==
==4936== Conditional jump or move depends on uninitialised value(s)
==4936== at 0x16D7DD: Dune::Imp::compressed_base_array_unmanaged<Dune::FieldMatrix<double, 2, 2>, std::allocator<Dune::FieldMatrix<double, 2, 2> > >::RealIterator<Dune::FieldMatrix<double, 2, 2> >::equals(Dune::Imp::compressed_base_array_unmanaged<Dune::FieldMatrix<double, 2, 2>, std::allocator<Dune::FieldMatrix<double, 2, 2> > >::RealIterator<Dune::FieldMatrix<double, 2, 2> > const&) const (basearray.hh:611)
==4936== by 0x15CA46: std::enable_if<std::is_convertible<Dune::Imp::compressed_base_array_unmanaged<Dune::FieldMatrix<double, 2, 2>, std::allocator<Dune::FieldMatrix<double, 2, 2> > >::RealIterator<Dune::FieldMatrix<double, 2, 2> >, Dune::Imp::compressed_base_array_unmanaged<Dune::FieldMatrix<double, 2, 2>, std::allocator<Dune::FieldMatrix<double, 2, 2> > >::RealIterator<Dune::FieldMatrix<double, 2, 2> > >::value, bool>::type Dune::operator==<Dune::Imp::compressed_base_array_unmanaged<Dune::FieldMatrix<double, 2, 2>, std::allocator<Dune::FieldMatrix<double, 2, 2> > >::RealIterator<Dune::FieldMatrix<double, 2, 2> >, Dune::FieldMatrix<double, 2, 2>, Dune::FieldMatrix<double, 2, 2>&, long, Dune::Imp::compressed_base_array_unmanaged<Dune::FieldMatrix<double, 2, 2>, std::allocator<Dune::FieldMatrix<double, 2, 2> > >::RealIterator<Dune::FieldMatrix<double, 2, 2> >, Dune::FieldMatrix<double, 2, 2>, Dune::FieldMatrix<double, 2, 2>&>(Dune::BidirectionalIteratorFacade<Dune::Imp::compressed_base_array_unmanaged<Dune::FieldMatrix<double, 2, 2>, std::allocator<Dune::FieldMatrix<double, 2, 2> > >::RealIterator<Dune::FieldMatrix<double, 2, 2> >, Dune::FieldMatrix<double, 2, 2>, Dune::FieldMatrix<double, 2, 2>&, long> const&, Dune::BidirectionalIteratorFacade<Dune::Imp::compressed_base_array_unmanaged<Dune::FieldMatrix<double, 2, 2>, std::allocator<Dune::FieldMatrix<double, 2, 2> > >::RealIterator<Dune::FieldMatrix<double, 2, 2> >, Dune::FieldMatrix<double, 2, 2>, Dune::FieldMatrix<double, 2, 2>&, long> const&) (iteratorfacades.hh:381)
==4936== by 0x1557A3: Dune::EnableIfInterOperable<Dune::Imp::compressed_base_array_unmanaged<Dune::FieldMatrix<double, 2, 2>, std::allocator<Dune::FieldMatrix<double, 2, 2> > >::RealIterator<Dune::FieldMatrix<double, 2, 2> >, Dune::Imp::compressed_base_array_unmanaged<Dune::FieldMatrix<double, 2, 2>, std::allocator<Dune::FieldMatrix<double, 2, 2> > >::RealIterator<Dune::FieldMatrix<double, 2, 2> >, bool>::type Dune::operator!=<Dune::Imp::compressed_base_array_unmanaged<Dune::FieldMatrix<double, 2, 2>, std::allocator<Dune::FieldMatrix<double, 2, 2> > >::RealIterator<Dune::FieldMatrix<double, 2, 2> >, Dune::FieldMatrix<double, 2, 2>, Dune::FieldMatrix<double, 2, 2>&, long, Dune::Imp::compressed_base_array_unmanaged<Dune::FieldMatrix<double, 2, 2>, std::allocator<Dune::FieldMatrix<double, 2, 2> > >::RealIterator<Dune::FieldMatrix<double, 2, 2> >, Dune::FieldMatrix<double, 2, 2>, Dune::FieldMatrix<double, 2, 2>&>(Dune::BidirectionalIteratorFacade<Dune::Imp::compressed_base_array_unmanaged<Dune::FieldMatrix<double, 2, 2>, std::allocator<Dune::FieldMatrix<double, 2, 2> > >::RealIterator<Dune::FieldMatrix<double, 2, 2> >, Dune::FieldMatrix<double, 2, 2>, Dune::FieldMatrix<double, 2, 2>&, long> const&, Dune::BidirectionalIteratorFacade<Dune::Imp::compressed_base_array_unmanaged<Dune::FieldMatrix<double, 2, 2>, std::allocator<Dune::FieldMatrix<double, 2, 2> > >::RealIterator<Dune::FieldMatrix<double, 2, 2> >, Dune::FieldMatrix<double, 2, 2>, Dune::FieldMatrix<double, 2, 2>&, long> const&) (iteratorfacades.hh:419)
==4936== by 0x155338: Dune::BCRSMatrix<Dune::FieldMatrix<double, 2, 2>, std::allocator<Dune::FieldMatrix<double, 2, 2> > >::endindices() (bcrsmatrix.hh:1233)
==4936== by 0x151697: main (matrixtest.cc:391)
==4936==
==4936==
==4936== HEAP SUMMARY:
==4936== in use at exit: 8 bytes in 1 blocks
==4936== total heap usage: 196 allocs, 195 frees, 265,272 bytes allocated
==4936==
==4936== LEAK SUMMARY:
==4936== definitely lost: 0 bytes in 0 blocks
==4936== indirectly lost: 0 bytes in 0 blocks
==4936== possibly lost: 0 bytes in 0 blocks
==4936== still reachable: 8 bytes in 1 blocks
==4936== suppressed: 0 bytes in 0 blocks
==4936== Rerun with --leak-check=full to see details of leaked memory
==4936==
==4936== For counts of detected and suppressed errors, rerun with: -v
==4936== Use --track-origins=yes to see where uninitialised values come from
==4936== ERROR SUMMARY: 6 errors from 1 contexts (suppressed: 0 from 0)