]> https://gitweb.dealii.org/ - dealii.git/commitdiff
Add index checks to the noncontiguous partitioner. 11763/head
authorDavid Wells <drwells@email.unc.edu>
Tue, 16 Feb 2021 20:45:41 +0000 (15:45 -0500)
committerDavid Wells <drwells@email.unc.edu>
Tue, 16 Feb 2021 20:57:22 +0000 (15:57 -0500)
include/deal.II/base/mpi_noncontiguous_partitioner.templates.h

index 96aed47bb0475d369f15de1c4ba7085b7f5a15ba..722921e2b30befd382b0add7459b735164291c48 100644 (file)
@@ -302,12 +302,14 @@ namespace Utilities
       Assert(false, ExcNeedsMPI());
 #else
       AssertIndexRange(communication_channel, 10);
+      AssertDimension(requests.size(), recv_ranks.size() + send_ranks.size());
 
       const auto tag =
         communication_channel +
         internal::Tags::noncontiguous_partitioner_update_ghost_values;
 
       // post recv
+      AssertIndexRange(recv_ranks.size(), recv_ptr.size());
       for (types::global_dof_index i = 0; i < recv_ranks.size(); i++)
         {
           const auto ierr =
@@ -322,14 +324,23 @@ namespace Utilities
         }
 
       // post send
+      AssertIndexRange(send_ranks.size(), send_ptr.size());
       for (types::global_dof_index i = 0, k = 0; i < send_ranks.size(); i++)
         {
           // collect data to be send
           for (types::global_dof_index j = send_ptr[i]; j < send_ptr[i + 1];
                j++)
-            buffers[j] = src[send_indices[k++]];
+            {
+              AssertIndexRange(k, send_indices.size());
+              buffers[j] = src[send_indices[k]];
+              ++k;
+            }
 
           // send data
+          Assert((send_ptr[i] < buffers.size()) ||
+                   (send_ptr[i] == buffers.size() &&
+                    send_ptr[i + 1] == send_ptr[i]),
+                 ExcMessage("The input buffer doesn't contain enough entries"));
           const auto ierr =
             MPI_Isend(buffers.data() + send_ptr[i],
                       send_ptr[i + 1] - send_ptr[i],
@@ -369,6 +380,7 @@ namespace Utilities
                                         &status);
           AssertThrowMPI(ierr);
 
+          AssertIndexRange(i + 1, recv_ptr.size());
           for (types::global_dof_index j = recv_ptr[i], c = 0;
                j < recv_ptr[i + 1];
                j++)

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.