From 3acd94aea73519a24ee25f1d7d079ebd49b6b21c Mon Sep 17 00:00:00 2001 From: Lukas Cejka <lukas.ostatek@gmail.com> Date: Mon, 24 Jun 2019 23:16:28 +0200 Subject: [PATCH] Added checking for negative number of elements, in case of int overflow. Debugging prints included. --- src/TNL/Matrices/Sparse_impl.h | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/src/TNL/Matrices/Sparse_impl.h b/src/TNL/Matrices/Sparse_impl.h index 5886681752..ab32d362da 100644 --- a/src/TNL/Matrices/Sparse_impl.h +++ b/src/TNL/Matrices/Sparse_impl.h @@ -109,6 +109,20 @@ template< typename Real, typename Index > void Sparse< Real, Device, Index >::allocateMatrixElements( const IndexType& numberOfMatrixElements ) { + std::cout << " Allocating matrix elements..." << std::endl; + // CHECKING: if the number of matrix elements is larger than the highest number the IndexType can go to? + // INT OVERFLOW + + // CORRECT? ELL stores certain matrices in such a way, which could cause the number of matrix elements + // to be greater than the maximum value IndexType can store, thus causing int overflow when + // creating the arrays "values" and "indexes". + // PROBLEM: int can overflow in such a way that it is still positive, thus rendering this assert useless. + // HOW FIX? Do we have to create special conditions for every format in its allocation method? We can't + // tell from within this method, if numberOfMatrixElements is an overflown value or not. + TNL_ASSERT_GE( numberOfMatrixElements, 0, "Number of matrix elements must be non-negative." ); + + std::cout << " numberOfMatrixElements = " << numberOfMatrixElements << std::endl; + this->values.setSize( numberOfMatrixElements ); this->columnIndexes.setSize( numberOfMatrixElements ); @@ -118,6 +132,8 @@ void Sparse< Real, Device, Index >::allocateMatrixElements( const IndexType& num */ if( numberOfMatrixElements > 0 ) this->columnIndexes.setValue( this->columns ); + + std::cout << "->END OF allocateMatrixElements!!!" << std::endl; } template< typename Real, -- GitLab