diff --git a/src/TNL/Matrices/MatrixReader_impl.h b/src/TNL/Matrices/MatrixReader_impl.h
index 0415d5f8d1d60af87f82a6efff5f2a5ea4d18ab7..d00fdb9044f18fee40ea339cc29fe534874d6027 100644
--- a/src/TNL/Matrices/MatrixReader_impl.h
+++ b/src/TNL/Matrices/MatrixReader_impl.h
@@ -17,7 +17,7 @@
 #include <TNL/Matrices/MatrixReader.h>
 
 namespace TNL {
-namespace Matrices {   
+namespace Matrices {
 
 template< typename Matrix >
 bool MatrixReader< Matrix >::readMtxFile( const String& fileName,
@@ -68,7 +68,7 @@ bool MatrixReader< Matrix >::readMtxFileHostMatrix( std::istream& file,
 
    if( ! computeCompressedRowLengthsFromMtxFile( file, rowLengths, columns, rows, symmetricMatrix, verbose ) )
       return false;
-   
+
    matrix.setCompressedRowLengths( rowLengths );
 
    if( ! readMatrixElementsFromMtxFile( file, matrix, symmetricMatrix, verbose, symReader ) )
@@ -271,7 +271,7 @@ bool MatrixReader< Matrix >::computeCompressedRowLengthsFromMtxFile( std::istrea
    timer.start();
    while( std::getline( file, line ) )
    {
-      if( line[ 0 ] == '%' ) continue;
+      if( ! line.getSize() || line[ 0 ] == '%' ) continue;
       if( ! dimensionsLine )
       {
          dimensionsLine = true;
@@ -340,10 +340,10 @@ bool MatrixReader< Matrix >::readMatrixElementsFromMtxFile( std::istream& file,
    IndexType processedElements( 0 );
    Timer timer;
    timer.start();
-   
+
    while( std::getline( file, line ) )
    {
-      if( line[ 0 ] == '%' ) continue;
+      if( ! line.getSize() || line[ 0 ] == '%' ) continue;
       if( ! dimensionsLine )
       {
          dimensionsLine = true;
@@ -371,7 +371,7 @@ bool MatrixReader< Matrix >::readMatrixElementsFromMtxFile( std::istream& file,
           processedElements++;
       }
    }
-   
+
    file.clear();
    long int fileSize = file.tellg();
    timer.stop();
@@ -379,7 +379,7 @@ bool MatrixReader< Matrix >::readMatrixElementsFromMtxFile( std::istream& file,
      std::cout << " Reading the matrix elements ... " << processedElements << " / " << matrix.getNumberOfMatrixElements()
               << " -> " << timer.getRealTime()
               << " sec. i.e. " << fileSize / ( timer.getRealTime() * ( 1 << 20 ))  << "MB/s." << std::endl;
-   
+
    return true;
 }