From a00443160570a2f907f9744a1739eb8173912574 Mon Sep 17 00:00:00 2001 From: hellkite500 Date: Wed, 10 Jul 2024 14:31:35 -0600 Subject: [PATCH] chore: remove defensive checks for nullptr --- src/bmi_lgar.cxx | 59 ++++++++++++++++++++++++------------------------ 1 file changed, 29 insertions(+), 30 deletions(-) diff --git a/src/bmi_lgar.cxx b/src/bmi_lgar.cxx index e3fae68..f1b744c 100644 --- a/src/bmi_lgar.cxx +++ b/src/bmi_lgar.cxx @@ -22,8 +22,8 @@ string verbosity="none"; * */ BmiLGAR::~BmiLGAR(){ - if( giuh_ordinates != nullptr ) delete [] giuh_ordinates; - if( giuh_runoff_queue != nullptr ) delete [] giuh_runoff_queue; + delete [] giuh_ordinates; + delete [] giuh_runoff_queue; } /* The `head` pointer stores the address in memory of the first member of the linked list containing @@ -62,10 +62,9 @@ Initialize (std::string config_file) * */ void BmiLGAR::realloc_soil(){ - if(state->lgar_bmi_params.soil_depth_wetting_fronts != nullptr) - delete [] state->lgar_bmi_params.soil_depth_wetting_fronts; - if(state->lgar_bmi_params.soil_moisture_wetting_fronts != nullptr) - delete [] state->lgar_bmi_params.soil_moisture_wetting_fronts; + + delete [] state->lgar_bmi_params.soil_depth_wetting_fronts; + delete [] state->lgar_bmi_params.soil_moisture_wetting_fronts; state->lgar_bmi_params.soil_depth_wetting_fronts = new double[state->lgar_bmi_params.num_wetting_fronts]; state->lgar_bmi_params.soil_moisture_wetting_fronts = new double[state->lgar_bmi_params.num_wetting_fronts]; @@ -631,30 +630,30 @@ void BmiLGAR:: Finalize() { global_mass_balance(); - if( state->head != NULL ) listDelete(state->head); - if( state->state_previous != NULL ) listDelete(state->state_previous); - - if( state->soil_properties != nullptr ) delete [] state->soil_properties; - - if( state->lgar_bmi_params.soil_depth_wetting_fronts != nullptr ) delete [] state->lgar_bmi_params.soil_depth_wetting_fronts; - if( state->lgar_bmi_params.soil_moisture_wetting_fronts != nullptr) delete [] state->lgar_bmi_params.soil_moisture_wetting_fronts; - - if( state->lgar_bmi_params.soil_temperature != nullptr ) delete [] state->lgar_bmi_params.soil_temperature; - if( state->lgar_bmi_params.soil_temperature_z != nullptr) delete [] state->lgar_bmi_params.soil_temperature_z; - if( state->lgar_bmi_params.layer_soil_type != nullptr ) delete [] state->lgar_bmi_params.layer_soil_type; - - if( state->lgar_calib_params.theta_e != nullptr ) delete [] state->lgar_calib_params.theta_e; - if( state->lgar_calib_params.theta_r != nullptr ) delete [] state->lgar_calib_params.theta_r; - if( state->lgar_calib_params.vg_n != nullptr ) delete [] state->lgar_calib_params.vg_n; - if( state->lgar_calib_params.vg_alpha != nullptr ) delete [] state->lgar_calib_params.vg_alpha; - if( state->lgar_calib_params.Ksat != nullptr ) delete [] state->lgar_calib_params.Ksat; - - if( state->lgar_bmi_params.layer_thickness_cm != nullptr ) delete [] state->lgar_bmi_params.layer_thickness_cm; - if( state->lgar_bmi_params.cum_layer_thickness_cm != nullptr ) delete [] state->lgar_bmi_params.cum_layer_thickness_cm; - if( state->lgar_bmi_params.giuh_ordinates != nullptr ) delete [] state->lgar_bmi_params.giuh_ordinates; - if( state->lgar_bmi_params.frozen_factor != nullptr ) delete [] state->lgar_bmi_params.frozen_factor; - if( state->lgar_bmi_input_params != nullptr ) delete state->lgar_bmi_input_params; - if( state != nullptr ) delete state; + listDelete(state->head); + listDelete(state->state_previous); + + delete [] state->soil_properties; + + delete [] state->lgar_bmi_params.soil_depth_wetting_fronts; + delete [] state->lgar_bmi_params.soil_moisture_wetting_fronts; + + delete [] state->lgar_bmi_params.soil_temperature; + delete [] state->lgar_bmi_params.soil_temperature_z; + delete [] state->lgar_bmi_params.layer_soil_type; + + delete [] state->lgar_calib_params.theta_e; + delete [] state->lgar_calib_params.theta_r; + delete [] state->lgar_calib_params.vg_n; + delete [] state->lgar_calib_params.vg_alpha; + delete [] state->lgar_calib_params.Ksat; + + delete [] state->lgar_bmi_params.layer_thickness_cm; + delete [] state->lgar_bmi_params.cum_layer_thickness_cm; + delete [] state->lgar_bmi_params.giuh_ordinates; + delete [] state->lgar_bmi_params.frozen_factor; + delete state->lgar_bmi_input_params; + delete state; }