]> https://gitweb.dealii.org/ - dealii.git/commitdiff
Fix issues reported by Coverity 4014/head
authorDaniel Arndt <daniel.arndt@iwr.uni-heidelberg.de>
Tue, 28 Feb 2017 23:56:23 +0000 (00:56 +0100)
committerDaniel Arndt <daniel.arndt@iwr.uni-heidelberg.de>
Wed, 1 Mar 2017 11:44:27 +0000 (12:44 +0100)
13 files changed:
include/deal.II/lac/solver_cg.h
include/deal.II/lac/trilinos_vector_base.h
source/base/convergence_table.cc
source/base/path_search.cc
source/lac/petsc_parallel_sparse_matrix.cc
source/lac/petsc_parallel_vector.cc
source/lac/trilinos_epetra_vector.cc
source/lac/trilinos_precondition_ml.cc
source/lac/trilinos_precondition_muelu.cc
source/lac/trilinos_sparse_matrix.cc
source/lac/trilinos_sparsity_pattern.cc
source/lac/trilinos_vector.cc
source/lac/trilinos_vector_base.cc

index e044c58b9c852a46317be6b57a946439920b7c75..1170df1539ff8cc1e1a069fc3db31ddd0794aebd 100644 (file)
@@ -327,6 +327,9 @@ SolverCG<VectorType>::SolverCG (SolverControl        &cn,
                                 const AdditionalData     &data)
   :
   Solver<VectorType>(cn,mem),
+  Vr(NULL),
+  Vp(NULL),
+  Vz(NULL),
   additional_data(data)
 {}
 
index cee2271762b9010f44d6d8c0e07bce432e61a94e..5b88511d9660b3d997f3b8c8748f13de254e016b 100644 (file)
@@ -1225,12 +1225,14 @@ namespace TrilinosWrappers
   {
     AssertIsFinite(s);
 
-    const int ierr = vector->PutScalar(s);
-
+    int ierr = vector->PutScalar(s);
     AssertThrow (ierr == 0, ExcTrilinosError(ierr));
 
     if (nonlocal_vector.get() != 0)
-      nonlocal_vector->PutScalar(0.);
+      {
+        ierr = nonlocal_vector->PutScalar(0.);
+        AssertThrow (ierr == 0, ExcTrilinosError(ierr));
+      }
 
     return *this;
   }
@@ -1282,7 +1284,10 @@ namespace TrilinosWrappers
     Assert (!has_ghost_elements(), ExcGhostsPresent());
 
     if (last_action == Add)
-      vector->GlobalAssemble(Add);
+      {
+        const int ierr = vector->GlobalAssemble(Add);
+        AssertThrow (ierr == 0, ExcTrilinosError(ierr));
+      }
 
     if (last_action != Insert)
       last_action = Insert;
index b61b24b603eadf71c055d58ede972181add46da5..e023df44627f75c56d7fe4fe770d1d0c570b1be7 100644 (file)
@@ -60,8 +60,7 @@ void ConvergenceTable::evaluate_convergence_rates(const std::string &data_column
 
   switch (rate_mode)
     {
-    case none:
-      break;
+    // case none: already considered above
     case reduction_rate:
       rate_key += "red.rate";
       no_rate_entries = columns[rate_key].entries.size();
index 91745afc294b345c5ea792502cff97d8baff513c..bb4e7f6b522d15d5f21a4f4145ea6c0ec52659fe 100644 (file)
@@ -187,7 +187,7 @@ PathSearch::find (const std::string &filename,
         {
           return find(filename, *suffix, open_mode);
         }
-      catch (ExcFileNotFound)
+      catch (ExcFileNotFound &)
         {
           continue;
         }
index 87626f8eaa7cfcd21408eb55eefd70a86aa15df6..5443ca5f4cd19e9bc86183d8e66218d4c40c49c9 100644 (file)
@@ -31,6 +31,7 @@ namespace PETScWrappers
   namespace MPI
   {
     SparseMatrix::SparseMatrix ()
+      : communicator(MPI_COMM_SELF)
     {
       // just like for vectors: since we
       // create an empty matrix, we can as
index bd519019c8c367c66d9fe7436a0e7448f0361acb..659e47e325d0074efe67541bed7e5e0441122cf9 100644 (file)
@@ -30,6 +30,7 @@ namespace PETScWrappers
   {
 
     Vector::Vector ()
+      : communicator (MPI_COMM_SELF)
     {
       // this is an invalid empty vector, so we can just as well create a
       // sequential one to avoid all the overhead incurred by parallelism
index b42db82a2193a6bdb156df392fc070e4bbdfa2f7..f57a05d11114f894000cff0237fcc04d2d6d0c93 100644 (file)
@@ -170,7 +170,11 @@ namespace LinearAlgebra
       const Vector &down_V = dynamic_cast<const Vector &>(V);
       // If the maps are the same we can Update right away.
       if (vector->Map().SameAs(down_V.trilinos_vector().Map()))
-        vector->Update(1., down_V.trilinos_vector(), 1.);
+        {
+          const int ierr = vector->Update(1., down_V.trilinos_vector(), 1.);
+          Assert(ierr==0, ExcTrilinosError(ierr));
+          (void) ierr;
+        }
       else
         {
           Assert(this->size()==down_V.size(),
@@ -178,7 +182,8 @@ namespace LinearAlgebra
 
 #if DEAL_II_TRILINOS_VERSION_GTE(11,11,0)
           Epetra_Import data_exchange (vector->Map(), down_V.trilinos_vector().Map());
-          int ierr = vector->Import(down_V.trilinos_vector(), data_exchange, Epetra_AddLocalAlso);
+          const int ierr = vector->Import(down_V.trilinos_vector(),
+                                          data_exchange, Epetra_AddLocalAlso);
           Assert(ierr==0, ExcTrilinosError(ierr));
           (void) ierr;
 #else
@@ -190,7 +195,6 @@ namespace LinearAlgebra
 
           int ierr = dummy.Import(down_V.trilinos_vector(), data_exchange, Insert);
           Assert(ierr==0, ExcTrilinosError(ierr));
-          (void) ierr;
 
           ierr = vector->Update(1.0, dummy, 1.0);
           Assert(ierr==0, ExcTrilinosError(ierr));
@@ -427,6 +431,7 @@ namespace LinearAlgebra
     {
       const Epetra_MpiComm *epetra_comm
         = dynamic_cast<const Epetra_MpiComm *>(&(vector->Comm()));
+      Assert (epetra_comm != 0, ExcInternalError());
       return epetra_comm->GetMpiComm();
     }
 
index 9b5021661b223f3f3395f3d1302cc3890ad37f1a..5f9fbcb6d665fa75f754917d9c16603258be9e85 100644 (file)
@@ -313,7 +313,7 @@ namespace TrilinosWrappers
   PreconditionAMG::size_type
   PreconditionAMG::memory_consumption() const
   {
-    unsigned int memory = sizeof(this);
+    unsigned int memory = sizeof(*this);
 
     // todo: find a way to read out ML's data
     // sizes
index 834bf228acffe32897df18dd6656eefde0ee8736..d85ab3e5cd2e430a200e0409668dcc69fbda95b3 100644 (file)
@@ -313,7 +313,7 @@ namespace TrilinosWrappers
   PreconditionAMGMueLu::size_type
   PreconditionAMGMueLu::memory_consumption() const
   {
-    unsigned int memory = sizeof(this);
+    unsigned int memory = sizeof(*this);
 
     // todo: find a way to read out ML's data
     // sizes
index 9c4a13ee26982529d5ad53ac32680685151993ac..d27b798aa730d5390b503aa1617c5b5e6644e01c 100644 (file)
@@ -2386,7 +2386,7 @@ namespace TrilinosWrappers
   SparseMatrix::size_type
   SparseMatrix::memory_consumption () const
   {
-    size_type static_memory = sizeof(this) + sizeof (*matrix)
+    size_type static_memory = sizeof(*this) + sizeof (*matrix)
                               + sizeof(*matrix->Graph().DataPtr());
     return ((sizeof(TrilinosScalar)+sizeof(TrilinosWrappers::types::int_type))*
             matrix->NumMyNonzeros() + sizeof(int)*local_size() + static_memory);
@@ -2433,6 +2433,7 @@ namespace TrilinosWrappers
 
     const Epetra_MpiComm *mpi_comm
       = dynamic_cast<const Epetra_MpiComm *>(&matrix->RangeMap().Comm());
+    Assert(mpi_comm != 0, ExcInternalError());
     return mpi_comm->Comm();
 #else
 
index df5a99c610659d0ca4583b812801cc30d89ef005..329ec58f9ade206cfaff00e196e8a1a4fd264700 100644 (file)
@@ -1051,6 +1051,7 @@ namespace TrilinosWrappers
 
     const Epetra_MpiComm *mpi_comm
       = dynamic_cast<const Epetra_MpiComm *>(&graph->RangeMap().Comm());
+    Assert (mpi_comm != 0, ExcInternalError());
     return mpi_comm->Comm();
 #else
 
index 586913aeeac3446ac727359fa7dec38076965ddd..c24c8105df19b33d37b3dcb7aa9dafae39440588 100644 (file)
@@ -238,10 +238,11 @@ namespace TrilinosWrappers
             }
         }
 #if defined(DEBUG) && defined(DEAL_II_WITH_MPI)
-      const MPI_Comm mpi_communicator
-        = dynamic_cast<const Epetra_MpiComm *>(&(vector->Comm()))->Comm();
+      const Epetra_MpiComm *comm_ptr
+        = dynamic_cast<const Epetra_MpiComm *>(&(vector->Comm()));
+      Assert (comm_ptr != 0, ExcInternalError());
       const size_type n_elements_global
-        = Utilities::MPI::sum (owned_elements.n_elements(), mpi_communicator);
+        = Utilities::MPI::sum (owned_elements.n_elements(), comm_ptr->Comm());
 
       Assert (has_ghosts || n_elements_global == size(), ExcInternalError());
 #endif
@@ -358,10 +359,11 @@ namespace TrilinosWrappers
           last_action = Insert;
         }
 #if defined(DEBUG) && defined(DEAL_II_WITH_MPI)
-      const MPI_Comm mpi_communicator
-        = dynamic_cast<const Epetra_MpiComm *>(&(vector->Comm()))->Comm();
+      const Epetra_MpiComm *comm_ptr
+        = dynamic_cast<const Epetra_MpiComm *>(&(vector->Comm()));
+      Assert (comm_ptr != 0, ExcInternalError());
       const size_type n_elements_global
-        = Utilities::MPI::sum (owned_elements.n_elements(), mpi_communicator);
+        = Utilities::MPI::sum (owned_elements.n_elements(), comm_ptr->Comm());
 
       Assert (has_ghosts || n_elements_global == size(), ExcInternalError());
 #endif
@@ -436,10 +438,11 @@ namespace TrilinosWrappers
           last_action = Insert;
         }
 #if defined(DEBUG) && defined(DEAL_II_WITH_MPI)
-      const MPI_Comm mpi_communicator
-        = dynamic_cast<const Epetra_MpiComm *>(&(vector->Comm()))->Comm();
+      const Epetra_MpiComm *comm_ptr
+        = dynamic_cast<const Epetra_MpiComm *>(&(vector->Comm()));
+      Assert (comm_ptr != 0, ExcInternalError());
       const size_type n_elements_global
-        = Utilities::MPI::sum (owned_elements.n_elements(), mpi_communicator);
+        = Utilities::MPI::sum (owned_elements.n_elements(), comm_ptr->Comm());
 
       Assert (has_ghosts || n_elements_global == size(), ExcInternalError());
 #endif
index 5bfcf9b55a738e2af5269ec5b79236eb7adc1036..c33ccceb46586c5e746cd6d3565b7c60ee5ed805 100644 (file)
@@ -210,10 +210,11 @@ namespace TrilinosWrappers
     // otherwise result in undefined behaviour in the call to
     // GlobalAssemble().
     double double_mode = mode;
+    const Epetra_MpiComm *comm_ptr
+      = dynamic_cast<const Epetra_MpiComm *>(&(vector_partitioner().Comm()));
+    Assert (comm_ptr != 0, ExcInternalError());
     Utilities::MPI::MinMaxAvg result
-      = Utilities::MPI::min_max_avg (double_mode,
-                                     dynamic_cast<const Epetra_MpiComm *>
-                                     (&vector_partitioner().Comm())->GetMpiComm());
+      = Utilities::MPI::min_max_avg (double_mode, comm_ptr->GetMpiComm());
     Assert(result.max-result.min<1e-5,
            ExcMessage ("Not all processors agree whether the last operation on "
                        "this vector was an addition or a set operation. This will "
@@ -230,7 +231,8 @@ namespace TrilinosWrappers
       {
         Epetra_Export exporter(nonlocal_vector->Map(), vector->Map());
         ierr = vector->Export(*nonlocal_vector, exporter, mode);
-        nonlocal_vector->PutScalar(0.);
+        AssertThrow (ierr == 0, ExcTrilinosError(ierr));
+        ierr = nonlocal_vector->PutScalar(0.);
       }
     AssertThrow (ierr == 0, ExcTrilinosError(ierr));
     last_action = Zero;
@@ -368,6 +370,7 @@ namespace TrilinosWrappers
     // is zero on _all_ processors.
     const Epetra_MpiComm *mpi_comm
       = dynamic_cast<const Epetra_MpiComm *>(&vector->Map().Comm());
+    Assert(mpi_comm != 0, ExcInternalError());
     unsigned int num_nonzero = Utilities::MPI::sum(flag, mpi_comm->Comm());
     return num_nonzero == 0;
 #else

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.