Skip to content

Commit f322aa1

Browse files
linpeizePeizeLin
andauthored
Refactor: add nullptr for uninitialized pointer (#7078)
Co-authored-by: linpz <linpz@mail.ustc.edu.cn>
1 parent 3d1ee0c commit f322aa1

9 files changed

Lines changed: 12 additions & 12 deletions

File tree

source/source_base/mcd.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -705,7 +705,7 @@ int MCD_sscanf(const char *str,const char *fmt,char*fun,char*file,int line,...)
705705
/* scanf etc helper function */
706706
void scan_args(const char *fmt,va_list argptr,char*fun,char*file,int line)
707707
{
708-
char **ptr;
708+
char ** ptr = nullptr;
709709
void * dummy = nullptr; // clear up the unused warning
710710

711711
for(;*fmt;fmt++) {

source/source_lcao/module_deepks/LCAO_deepks.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ class LCAO_Deepks
9090
std::vector<torch::Tensor> pdm;
9191

9292
/// dE/dD, autograd from loaded model(E: Ry)
93-
double** gedm; //[tot_Inl][(2l+1)*(2l+1)]
93+
double** gedm = nullptr; //[tot_Inl][(2l+1)*(2l+1)]
9494

9595
// functions for hr status: 1. get value; 2. set value;
9696
int get_hr_cal()

source/source_lcao/module_gint/gint_rho.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ class Gint_rho : public Gint
3535
const bool is_dm_symm_;
3636

3737
// output
38-
double **rho_;
38+
double ** rho_ = nullptr;
3939

4040
// Intermediate variables
4141
std::vector<HContainer<double>> dm_gint_vec_;

source/source_lcao/module_gint/gint_rho_gpu.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ class Gint_rho_gpu: public Gint
4040
const bool is_dm_symm_;
4141

4242
// output
43-
double **rho_;
43+
double ** rho_ = nullptr;
4444

4545
// Intermediate variables
4646
std::vector<HContainer<double>> dm_gint_vec_;

source/source_lcao/module_gint/gint_tau.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ class Gint_tau : public Gint
2929
const int nspin_;
3030

3131
// output
32-
double **kin_;
32+
double ** kin_ = nullptr;
3333

3434
// Intermediate variables
3535
std::vector<HContainer<double>> dm_gint_vec_;

source/source_lcao/module_gint/gint_tau_gpu.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ class Gint_tau_gpu : public Gint
3535
const int nspin_;
3636

3737
// output
38-
double **kin_;
38+
double ** kin_ = nullptr;
3939

4040
// Intermediate variables
4141
std::vector<HContainer<double>> dm_gint_vec_;

source/source_lcao/module_lr/lr_spectrum.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ ModuleBase::Vector3<double> LR::LR_Spectrum<double>::cal_transition_dipole_istat
5353
for (int is = 0;is < this->nspin_x;++is)
5454
{
5555
// 2. transition density
56-
double** rho_trans;
56+
double** rho_trans = nullptr;
5757
LR_Util::_allocate_2order_nested_ptr(rho_trans, 1, this->rho_basis.nrxx);
5858
ModuleBase::GlobalFunc::ZEROS(rho_trans[0], this->rho_basis.nrxx);
5959
ModuleGint::cal_gint_rho({ DM_trans.get_DMR_vector().at(is) }, 1, rho_trans, false);
@@ -90,8 +90,8 @@ ModuleBase::Vector3<std::complex<double>> LR::LR_Spectrum<std::complex<double>>:
9090
for (int is = 0;is < this->nspin_x;++is)
9191
{
9292
// 2. transition density
93-
double** rho_trans_real;
94-
double** rho_trans_imag;
93+
double** rho_trans_real = nullptr;
94+
double** rho_trans_imag = nullptr;
9595
LR_Util::_allocate_2order_nested_ptr(rho_trans_real, 1, this->rho_basis.nrxx);
9696
LR_Util::_allocate_2order_nested_ptr(rho_trans_imag, 1, this->rho_basis.nrxx);
9797

source/source_lcao/module_lr/operator_casida/operator_lr_hxc.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ namespace LR
5656

5757
// 2. transition electron density
5858
// \f[ \tilde{\rho}(r)=\sum_{\mu_j, \mu_b}\tilde{\rho}_{\mu_j,\mu_b}\phi_{\mu_b}(r)\phi_{\mu_j}(r) \f]
59-
double** rho_trans;
59+
double** rho_trans = nullptr;
6060
const int& nrxx = this->pot.lock()->nrxx;
6161
LR_Util::_allocate_2order_nested_ptr(rho_trans, 1, nrxx); // currently gint_kernel_rho uses PARAM.inp.nspin, it needs refactor
6262
ModuleBase::GlobalFunc::ZEROS(rho_trans[0], nrxx);
@@ -90,7 +90,7 @@ namespace LR
9090

9191

9292
// 2. transition electron density
93-
double** rho_trans;
93+
double** rho_trans = nullptr;
9494
const int& nrxx = this->pot.lock()->nrxx;
9595

9696
LR_Util::_allocate_2order_nested_ptr(rho_trans, 1, nrxx); // nspin=1 for transition density

source/source_lcao/module_lr/potentials/xc_kernel.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ LR::KernelXC::KernelXC(const ModulePW::PW_Basis& rho_basis,
5252
if (lr_init_xc_kernel[0] == "from_charge_file")
5353
{
5454
assert(lr_init_xc_kernel.size() >= 2);
55-
double** rho_for_fxc;
55+
double** rho_for_fxc = nullptr;
5656
LR_Util::_allocate_2order_nested_ptr(rho_for_fxc, nspin, nrxx);
5757
double ef = 0.0;
5858
int prenspin = 1;

0 commit comments

Comments
 (0)