]> https://gitweb.dealii.org/ - dealii.git/commitdiff
Make sure to not call memset with a nullptr 5248/head
authorDaniel Arndt <daniel.arndt@iwr.uni-heidelberg.de>
Sun, 15 Oct 2017 12:20:54 +0000 (14:20 +0200)
committerDaniel Arndt <daniel.arndt@iwr.uni-heidelberg.de>
Sun, 15 Oct 2017 20:44:42 +0000 (22:44 +0200)
include/deal.II/lac/la_parallel_vector.templates.h
include/deal.II/lac/read_write_vector.templates.h
include/deal.II/lac/vector.templates.h
include/deal.II/lac/vector_operations_internal.h

index 3128f13299ccd77780239010116e71b22f28fe02..7511e5f02a9064abddc685d7d7844d0b3c6a8744 100644 (file)
@@ -237,9 +237,14 @@ namespace LinearAlgebra
       reinit (v, true);
 
       thread_loop_partitioner = v.thread_loop_partitioner;
-      dealii::internal::VectorOperations::Vector_copy<Number,Number> copier(v.val, val);
-      internal::VectorOperations::parallel_for(copier, 0, partitioner->local_size(),
-                                               thread_loop_partitioner);
+
+      const size_type this_size = local_size();
+      if (this_size>0)
+        {
+          dealii::internal::VectorOperations::Vector_copy<Number,Number> copier(v.val, val);
+          internal::VectorOperations::parallel_for(copier, 0, partitioner->local_size(),
+                                                   thread_loop_partitioner);
+        }
     }
 
 
@@ -378,9 +383,14 @@ namespace LinearAlgebra
         must_update_ghost_values |= vector_is_ghosted;
 
       thread_loop_partitioner = c.thread_loop_partitioner;
-      dealii::internal::VectorOperations::Vector_copy<Number,Number2> copier(c.val, val);
-      internal::VectorOperations::parallel_for(copier, 0, partitioner->local_size(),
-                                               thread_loop_partitioner);
+
+      const size_type this_size = local_size();
+      if (this_size>0)
+        {
+          dealii::internal::VectorOperations::Vector_copy<Number,Number2> copier(c.val, val);
+          internal::VectorOperations::parallel_for(copier, 0, this_size,
+                                                   thread_loop_partitioner);
+        }
 
       if (must_update_ghost_values)
         update_ghost_values();
@@ -930,10 +940,14 @@ namespace LinearAlgebra
     Vector<Number> &
     Vector<Number>::operator = (const Number s)
     {
-      internal::VectorOperations::Vector_set<Number> setter(s, val);
+      const size_type this_size = local_size();
+      if (this_size>0)
+        {
+          internal::VectorOperations::Vector_set<Number> setter(s, val);
 
-      internal::VectorOperations::parallel_for(setter, 0, partitioner->local_size(),
-                                               thread_loop_partitioner);
+          internal::VectorOperations::parallel_for(setter, 0, this_size,
+                                                   thread_loop_partitioner);
+        }
 
       // if we call Vector::operator=0, we want to zero out all the entries
       // plus ghosts.
index 7ee68d7021aff2f996f0c6c5961280c4e6e941c2..75cfc9ec55ef59b6219ea4917862bf27f7276584 100644 (file)
@@ -220,8 +220,12 @@ namespace LinearAlgebra
     Assert(s==static_cast<Number>(0), ExcMessage("Only 0 can be assigned to a vector."));
     (void)s;
 
-    dealii::internal::VectorOperations::Vector_set<Number> setter(Number(), val);
-    dealii::internal::VectorOperations::parallel_for(setter, 0, n_elements(), thread_loop_partitioner);
+    const size_type this_size = n_elements();
+    if (this_size>0)
+      {
+        dealii::internal::VectorOperations::Vector_set<Number> setter(Number(), val);
+        dealii::internal::VectorOperations::parallel_for(setter, 0, this_size, thread_loop_partitioner);
+      }
 
     return *this;
   }
index 816296e02968f2808fe7f16e3789a78b96dbf810..385d8945bc83ec8c5dc982d30912703472fc0369 100644 (file)
@@ -205,8 +205,11 @@ Vector<Number>::operator= (const Vector<Number> &v)
   if (vec_size != v.vec_size)
     reinit (v, true);
 
-  dealii::internal::VectorOperations::Vector_copy<Number,Number> copier(v.val, val);
-  internal::VectorOperations::parallel_for(copier,0,vec_size,thread_loop_partitioner);
+  if (vec_size>0)
+    {
+      dealii::internal::VectorOperations::Vector_copy<Number,Number> copier(v.val, val);
+      internal::VectorOperations::parallel_for(copier,0,vec_size,thread_loop_partitioner);
+    }
 
   return *this;
 }
@@ -358,9 +361,11 @@ Vector<Number>::operator= (const Number s)
   if (s != Number())
     Assert (vec_size!=0, ExcEmptyObject());
 
-  internal::VectorOperations::Vector_set<Number> setter(s, val);
-
-  internal::VectorOperations::parallel_for(setter,0,vec_size,thread_loop_partitioner);
+  if (vec_size>0)
+    {
+      internal::VectorOperations::Vector_set<Number> setter(s, val);
+      internal::VectorOperations::parallel_for(setter,0,vec_size,thread_loop_partitioner);
+    }
 
   return *this;
 }
index 3211f8d72e7fe21943987b7521677d139c086ad5..517ef3f76edeafbb8655c4403d985ae5c7e87e13 100644 (file)
@@ -203,18 +203,22 @@ namespace internal
         :
         value(value),
         dst(dst)
-      {}
+      {
+        Assert(dst != nullptr, ExcInternalError());
+      }
 
       void operator() (const size_type begin, const size_type end) const
       {
+        Assert (end>=begin, ExcInternalError());
+
         if (value == Number())
           std::memset (dst+begin,0,(end-begin)*sizeof(Number));
         else
           std::fill (dst+begin, dst+end, value);
       }
 
-      Number value;
-      Number *dst;
+      const Number value;
+      Number *const dst;
     };
 
     template <typename Number, typename OtherNumber>
@@ -224,10 +228,15 @@ namespace internal
         :
         src(src),
         dst(dst)
-      {}
+      {
+        Assert(src!=nullptr, ExcInternalError());
+        Assert(dst!=nullptr, ExcInternalError());
+      }
 
       void operator() (const size_type begin, const size_type end) const
       {
+        Assert (end>=begin, ExcInternalError());
+
         if (std::is_same<Number,OtherNumber>::value)
           std::memcpy(dst+begin, src+begin, (end-begin)*sizeof(Number));
         else
@@ -238,8 +247,8 @@ namespace internal
           }
       }
 
-      const OtherNumber *src;
-      Number *dst;
+      const OtherNumber *const src;
+      Number *const dst;
     };
 
     template <typename Number>

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.