]> https://gitweb.dealii.org/ - dealii.git/commitdiff
PetscWrappers::MatrixBase: add index conversion checks.
authorDavid Wells <drwells@email.unc.edu>
Sun, 11 Aug 2024 20:08:11 +0000 (14:08 -0600)
committerDavid Wells <drwells@email.unc.edu>
Mon, 12 Aug 2024 02:42:37 +0000 (20:42 -0600)
include/deal.II/lac/petsc_matrix_base.h
source/lac/petsc_matrix_base.cc

index 599255ad2992a81be3f690f257c61356be1f229c..9aef3935649c461d679b857d8d374cb953e1706a 100644 (file)
@@ -1480,7 +1480,7 @@ namespace PETScWrappers
 
     prepare_action(VectorOperation::add);
 
-    const auto petsc_row = row;
+    const auto petsc_row = static_cast<PetscInt>(row);
     AssertIntegerConversion(petsc_row, row);
 
     PetscInt n_columns = 0;
index d4afe87756f62334258e14a41bb1d05d0e10a519..17ca8ae36610b0bde0eb48e295648d52818456e4 100644 (file)
@@ -59,6 +59,13 @@ namespace PETScWrappers
       // iterator for an empty line (what
       // would it point to?)
       Assert(ncols != 0, ExcInternalError());
+#    ifdef DEBUG
+      for (PetscInt j = 0; j < ncols; ++j)
+        {
+          const auto column = static_cast<PetscInt>(colnums[j]);
+          AssertIntegerConversion(column, colnums[j]);
+        }
+#    endif
       colnum_cache =
         std::make_shared<std::vector<size_type>>(colnums, colnums + ncols);
       value_cache =
@@ -157,8 +164,14 @@ namespace PETScWrappers
   {
     assert_is_compressed();
 
-    // now set all the entries of these rows
-    // to zero
+    // now set all the entries of these rows to zero
+#  ifdef DEBUG
+    for (size_type i = 0; i < rows.size(); ++i)
+      {
+        const auto row = static_cast<PetscInt>(rows[i]);
+        AssertIntegerConversion(row, rows[i]);
+      }
+#  endif
     const std::vector<PetscInt> petsc_rows(rows.begin(), rows.end());
 
     // call the functions. note that we have
@@ -186,8 +199,14 @@ namespace PETScWrappers
   {
     assert_is_compressed();
 
-    // now set all the entries of these rows
-    // to zero
+    // now set all the entries of these rows to zero
+#  ifdef DEBUG
+    for (size_type i = 0; i < rows.size(); ++i)
+      {
+        const auto row = static_cast<PetscInt>(rows[i]);
+        AssertIntegerConversion(row, rows[i]);
+      }
+#  endif
     const std::vector<PetscInt> petsc_rows(rows.begin(), rows.end());
 
     // call the functions. note that we have
@@ -215,7 +234,10 @@ namespace PETScWrappers
   PetscScalar
   MatrixBase::el(const size_type i, const size_type j) const
   {
-    PetscInt petsc_i = i, petsc_j = j;
+    const auto petsc_i = static_cast<PetscInt>(i);
+    AssertIntegerConversion(petsc_i, i);
+    const auto petsc_j = static_cast<PetscInt>(j);
+    AssertIntegerConversion(petsc_j, j);
 
     PetscScalar value;
 

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.