Skip to content

Commit 3cab0f0

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

18 files changed

Lines changed: 42 additions & 42 deletions

File tree

source/source_base/math_bspline.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ class Bspline
3737
int norder; // the order of bezier base; norder >= 0
3838
double Dx; // Dx: the interval of control node
3939
double xi; // xi: the starting point
40-
double *bezier; // bezier[n] = Bk[n]
40+
double * bezier = nullptr; // bezier[n] = Bk[n]
4141

4242
public:
4343
Bspline();

source/source_base/math_chebyshev.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,7 @@ class Chebyshev
210210
std::complex<REAL>* coefc_cpu = nullptr; //[CPU] expansion coefficient of each order
211211

212212
FFTW<REAL> fftw; // use for fftw
213-
REAL* polytrace; //[CPU] w_n = \sum_i v^+ * T_n(A) * v, only
213+
REAL* polytrace = nullptr; //[CPU] w_n = \sum_i v^+ * T_n(A) * v, only
214214

215215
bool getcoef_real; // coef_real has been calculated
216216
bool getcoef_complex; // coef_complex has been calculated
@@ -248,7 +248,7 @@ class FFTW<double>
248248
FFTW(const int norder2_in);
249249
~FFTW();
250250
void execute_fftw();
251-
double* dcoef; //[norder2]
251+
double* dcoef = nullptr; //[norder2]
252252
fftw_complex* ccoef = nullptr;
253253
fftw_plan coef_plan;
254254
};
@@ -261,7 +261,7 @@ class FFTW<float>
261261
FFTW(const int norder2_in);
262262
~FFTW();
263263
void execute_fftw();
264-
float* dcoef; //[norder2]
264+
float* dcoef = nullptr; //[norder2]
265265
fftwf_complex* ccoef = nullptr;
266266
fftwf_plan coef_plan;
267267
};

source/source_base/mcd.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -64,9 +64,9 @@ typedef struct ChunkS
6464
#else
6565
long long id; // 64bit allocation ID
6666
#endif
67-
char *function; //creating function
68-
char *file; //file function is in
69-
void *ptr; //pointer to allocation
67+
char * function = nullptr; //creating function
68+
char * file = nullptr; //file function is in
69+
void * ptr = nullptr; //pointer to allocation
7070
struct ChunkS *next, //next chunk (null if nonw)
7171
*prev; //previous chunk (null if nonw)
7272
}Chunk;
@@ -706,7 +706,7 @@ int MCD_sscanf(const char *str,const char *fmt,char*fun,char*file,int line,...)
706706
void scan_args(const char *fmt,va_list argptr,char*fun,char*file,int line)
707707
{
708708
char **ptr;
709-
void *dummy; // clear up the unused warning
709+
void * dummy = nullptr; // clear up the unused warning
710710

711711
for(;*fmt;fmt++) {
712712
if(*fmt!='%')

source/source_base/module_container/base/core/bfc_allocator.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ class BFCAllocator : public Allocator {
122122
}
123123

124124
private:
125-
BFCAllocator* allocator_; // The parent allocator
125+
BFCAllocator* allocator_ = nullptr; // The parent allocator
126126
};
127127

128128
using free_chunk_set_t = std::set<ChunkHandle, ChunkComparator>;

source/source_basis/module_ao/ORB_nonlocal.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ class Numerical_Nonlocal
4242
const int& nproj_in,
4343
const Numerical_Nonlocal_Lm* ps_orbital_in);
4444

45-
Numerical_Nonlocal_Lm* Proj; ///< length: nproj(only store radial function )
45+
Numerical_Nonlocal_Lm* Proj = nullptr; ///< length: nproj(only store radial function )
4646

4747
const double& get_rcut_max() const { return rcut_max; }
4848
const int& get_nproj() const { return nproj; }

source/source_basis/module_ao/ORB_nonlocal_lm.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,11 +85,11 @@ class Numerical_Nonlocal_Lm
8585
double kcut;
8686
double dk;
8787

88-
double* r_radial; //points of r
88+
double* r_radial = nullptr; //points of r
8989
double* k_radial = nullptr;
9090

9191
double* rab = nullptr;
92-
double* beta_r; // |beta(r) * r>
92+
double* beta_r = nullptr; // |beta(r) * r>
9393
double* beta_k = nullptr;
9494
};
9595

source/source_basis/module_ao/ORB_read.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -466,10 +466,10 @@ void LCAO_Orbitals::read_orb_file(std::ofstream& ofs_in, // GlobalV::ofs_running
466466
{
467467
ofs_in << " " << std::setw(12) << count + 1 << std::setw(3) << L << std::setw(3) << N;
468468

469-
double* radial; // radial mesh
470-
double* psi; // radial local orbital
469+
double* radial = nullptr; // radial mesh
470+
double* psi = nullptr; // radial local orbital
471471
double* psir; // psi * r
472-
double* rab; // dr
472+
double* rab = nullptr; // dr
473473

474474
// set the number of mesh and the interval distance.
475475
ofs_in << std::setw(8) << meshr << std::setw(8) << dr;

source/source_cell/setup_nonlocal.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ class InfoNonlocal
1414
///
1515
///NON-LOCAL part for LCAO
1616
///
17-
Numerical_Nonlocal* Beta;/// nonlocal projectors (1-dimension array)
18-
int *nproj; //mohan add 2010-12-19
17+
Numerical_Nonlocal* Beta = nullptr;/// nonlocal projectors (1-dimension array)
18+
int * nproj = nullptr; //mohan add 2010-12-19
1919
int nprojmax; // mohan add 2010-03-07
2020
double rcutmax_Beta; //caoyu add 2021-05-24
2121
const double& get_rcutmax_Beta(void) const { return rcutmax_Beta; }

source/source_esolver/esolver_fp.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,8 @@ class ESolver_FP: public ESolver
6060
//! charge density and potential are defined on dense grids,
6161
//! but effective potential needs to be interpolated on smooth grids in order to compute Veff|psi>
6262
ModulePW::PW_Basis* pw_rho = nullptr;
63-
ModulePW::PW_Basis* pw_rhod; //! dense grid for USPP
64-
ModulePW::PW_Basis_Big* pw_big; ///< [temp] pw_basis_big class
63+
ModulePW::PW_Basis* pw_rhod = nullptr; //! dense grid for USPP
64+
ModulePW::PW_Basis_Big* pw_big = nullptr; ///< [temp] pw_basis_big class
6565

6666
//! parallel for rho grid
6767
Parallel_Grid Pgrid;

source/source_hsolver/module_genelpa/utils.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ void loadMatrix(const char FileName[], int nFull, double* a, int* desca, int bla
9494
if (myid == ROOT_PROC)
9595
matrixFile.open(FileName);
9696

97-
double* b; // buffer
97+
double* b = nullptr; // buffer
9898
const int MAX_BUFFER_SIZE = 1e9; // max buffer size is 1GB
9999

100100
int N = nFull;
@@ -179,7 +179,7 @@ void saveMatrix(const char FileName[], int nFull, double* a, int* desca, int bla
179179
matrixFile.width(24);
180180
}
181181

182-
double* b; // buffer
182+
double* b = nullptr; // buffer
183183
const int MAX_BUFFER_SIZE = 1e9; // max buffer size is 1GB
184184

185185
int N = nFull;

0 commit comments

Comments
 (0)