]> https://gitweb.dealii.org/ - dealii.git/commitdiff
Ensure we get no segmentation faults for empty matrices.
authorWolfgang Bangerth <bangerth@colostate.edu>
Wed, 21 Mar 2018 20:09:12 +0000 (14:09 -0600)
committerWolfgang Bangerth <bangerth@colostate.edu>
Wed, 21 Mar 2018 20:09:12 +0000 (14:09 -0600)
source/lac/sparsity_pattern.cc

index c71504eee0059965fb51063199a60bbda2f9bfb7..5c0a2f04b965df17c2595327599b19bfd2a45e9f 100644 (file)
@@ -572,8 +572,12 @@ void SparsityPattern::copy_from (const FullMatrix<number> &matrix)
   // but there are cases where it matters -- so we may as well be
   // gentler and hand over a whole row of entries at a time
   std::vector<size_type> column_indices;
-  column_indices.reserve (*std::max_element (entries_per_row.begin(),
-                                             entries_per_row.end()));
+  column_indices.reserve (entries_per_row.size() > 0
+                          ?
+                          *std::max_element (entries_per_row.begin(),
+                                             entries_per_row.end())
+                          :
+                          0);
   for (size_type row=0; row<matrix.m(); ++row)
     {
       column_indices.resize(entries_per_row[row]);

In the beginning the Universe was created. This has made a lot of people very angry and has been widely regarded as a bad move.

Douglas Adams


Typeset in Trocchi and Trocchi Bold Sans Serif.