From 39a70296eb91d8c901598549623b9bfb6b9d9f8e Mon Sep 17 00:00:00 2001
From: Sebastian Eibl <sebastian.eibl@fau.de>
Date: Wed, 28 Aug 2019 10:48:13 +0200
Subject: [PATCH] [CLANG-TIDY] readability-delete-null-pointer

---
 .clang-tidy                                 |  1 +
 src/blockforest/Initialization.cpp          | 10 ++++------
 src/blockforest/loadbalancing/Cartesian.cpp |  4 ++--
 3 files changed, 7 insertions(+), 8 deletions(-)

diff --git a/.clang-tidy b/.clang-tidy
index d00e49d2e..31a7a453d 100644
--- a/.clang-tidy
+++ b/.clang-tidy
@@ -34,6 +34,7 @@ portability-*,
 
 readability-const-return-type,
 readability-container-size-empty,
+readability-delete-null-pointer,
 readability-misleading-indentation,
 readability-misplaced-array-index
 
diff --git a/src/blockforest/Initialization.cpp b/src/blockforest/Initialization.cpp
index eaf25ffbe..8771996fb 100644
--- a/src/blockforest/Initialization.cpp
+++ b/src/blockforest/Initialization.cpp
@@ -222,7 +222,7 @@ createBlockForest(      const AABB& domainAABB,
 
    // if possible, create Cartesian MPI communicator
 
-   std::vector< uint_t >* processIdMap = nullptr;
+   std::vector< uint_t > processIdMap(0);
 
    WALBERLA_MPI_SECTION()
    {
@@ -233,13 +233,13 @@ createBlockForest(      const AABB& domainAABB,
          if ( mpiManager->isCartesianCommValid() ) {
             mpiManager->createCartesianComm( numberOfXProcesses, numberOfYProcesses, numberOfZProcesses, xPeriodic, yPeriodic, zPeriodic );
 
-            processIdMap = new std::vector< uint_t >( numberOfProcesses );
+            processIdMap.resize( numberOfProcesses );
 
             for( uint_t z = 0; z != numberOfZProcesses; ++z ) {
                for( uint_t y = 0; y != numberOfYProcesses; ++y ) {
                   for( uint_t x = 0; x != numberOfXProcesses; ++x ) {
 
-                     (*processIdMap)[ z * numberOfXProcesses * numberOfYProcesses + y * numberOfXProcesses + x ] =
+                     processIdMap[ z * numberOfXProcesses * numberOfYProcesses + y * numberOfXProcesses + x ] =
                            uint_c( MPIManager::instance()->cartesianRank(x,y,z) );
                   }
                }
@@ -256,11 +256,9 @@ createBlockForest(      const AABB& domainAABB,
 
    // calculate process distribution
 
-   sforest.balanceLoad( blockforest::CartesianDistribution( numberOfXProcesses, numberOfYProcesses, numberOfZProcesses, processIdMap ),
+   sforest.balanceLoad( blockforest::CartesianDistribution( numberOfXProcesses, numberOfYProcesses, numberOfZProcesses, &processIdMap ),
                         numberOfXProcesses * numberOfYProcesses * numberOfZProcesses );
 
-   if( processIdMap != nullptr ) delete processIdMap;
-
    // create StructuredBlockForest (encapsulates a newly created BlockForest)
 
    return std::make_shared< BlockForest >( uint_c( MPIManager::instance()->rank() ), sforest, keepGlobalBlockInformation );
diff --git a/src/blockforest/loadbalancing/Cartesian.cpp b/src/blockforest/loadbalancing/Cartesian.cpp
index 13dbf50b7..4645286d5 100644
--- a/src/blockforest/loadbalancing/Cartesian.cpp
+++ b/src/blockforest/loadbalancing/Cartesian.cpp
@@ -48,7 +48,7 @@ uint_t CartesianDistribution::operator()( SetupBlockForest & forest, const uint_
       WALBERLA_ABORT( "Load balancing failed: \'Number of processes in z-direction\' must be in (0," << forest.getZSize() << "]. "
                       "You specified \'" << numberOfZProcesses_ << "\'." );
 
-   if( processIdMap_ != nullptr )
+   if( !processIdMap_->empty() )
       WALBERLA_CHECK_EQUAL( processIdMap_->size(), numberOfProcesses );
 
    uint_t partitions[3];
@@ -84,7 +84,7 @@ uint_t CartesianDistribution::operator()( SetupBlockForest & forest, const uint_
             {
                const uint_t index = z * partitions[0] * partitions[1] + y * partitions[0] + x;
 
-               (*block)->assignTargetProcess( ( processIdMap_ != nullptr ) ? (*processIdMap_)[ index ] : index );
+               (*block)->assignTargetProcess( ( !processIdMap_->empty() ) ? (*processIdMap_)[ index ] : index );
             }
          }
       }
-- 
GitLab