From 3247ca347196d7874ab282284c087ca7caecdce5 Mon Sep 17 00:00:00 2001
From: Lukas Cejka <lukas.ostatek@gmail.com>
Date: Mon, 24 Jun 2019 23:22:17 +0200
Subject: [PATCH] Added checking for negative number of elements

---
 src/TNL/Matrices/EllpackSymmetricGraph_impl.h | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/src/TNL/Matrices/EllpackSymmetricGraph_impl.h b/src/TNL/Matrices/EllpackSymmetricGraph_impl.h
index 1abb1e98bc..9b12ab1f70 100644
--- a/src/TNL/Matrices/EllpackSymmetricGraph_impl.h
+++ b/src/TNL/Matrices/EllpackSymmetricGraph_impl.h
@@ -813,6 +813,11 @@ template< typename Real,
           typename Index >
 void EllpackSymmetricGraph< Real, Device, Index >::allocateElements()
 {
+   IndexType numberOfMatrixElements = this->alignedRows * this->rowLengths;
+   
+   TNL_ASSERT_TRUE( this->alignedRows != 0 && numberOfMatrixElements / this->alignedRows == this->rowLengths, 
+           "Ellpack cannot store this matrix. The number of matrix elements has overflown the value that IndexType is capable of storing" );
+   
    Sparse< Real, Device, Index >::allocateMatrixElements( this->alignedRows * this->rowLengths );
 }
 
-- 
GitLab