Skip to content

Commit 81c5067

Browse files
linpeizePeizeLin
andauthored
Refactor: add nullptr for uninitialized pointer (#7027)
* Refactor: add nullptr for uninitialized pointer * remove nullptr in MatrixBlock --------- Co-authored-by: linpz <linpz@mail.ustc.edu.cn>
1 parent a10e537 commit 81c5067

72 files changed

Lines changed: 181 additions & 181 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

source/source_base/intarray.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ namespace ModuleBase
1919
class IntArray
2020
{
2121
public:
22-
int *ptr;
22+
int * ptr = nullptr;
2323

2424
/**
2525
* @brief Construct a new Int Array object

source/source_base/math_chebyshev.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -249,7 +249,7 @@ class FFTW<double>
249249
~FFTW();
250250
void execute_fftw();
251251
double* dcoef; //[norder2]
252-
fftw_complex* ccoef;
252+
fftw_complex* ccoef = nullptr;
253253
fftw_plan coef_plan;
254254
};
255255

@@ -262,7 +262,7 @@ class FFTW<float>
262262
~FFTW();
263263
void execute_fftw();
264264
float* dcoef; //[norder2]
265-
fftwf_complex* ccoef;
265+
fftwf_complex* ccoef = nullptr;
266266
fftwf_plan coef_plan;
267267
};
268268
#endif

source/source_base/mathzone_add1.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ void Mathzone_Add1::SplineD2 // modified by pengfei 13-8-8 add second derivative
6464
ModuleBase::timer::tick("Mathzone_Add1","SplineD2");
6565

6666
double dx1, dx2, dy1, dy2, p, qn, sig, un;
67-
double *u;
67+
double * u = nullptr;
6868

6969
u = new double[mesh-1];
7070
const double ypmax = 99999.00;

source/source_base/matrix_wrapper.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ class Matrix_Wrapper
2121
public:
2222
int nr;
2323
int nc;
24-
double *c;
24+
double * c = nullptr;
2525
bool flag_delete_c;
2626

2727
Matrix_Wrapper(): nr(0), nc(0), c(nullptr), flag_delete_c(false){}

source/source_base/matrix_wrapper_tianhe2.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ namespace ModuleBase
1616
class Matrix_Wrapper
1717
{
1818
public:
19-
double *c;
19+
double * c = nullptr;
2020
int nr;
2121
int nc;
2222

source/source_base/mcd.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -514,7 +514,7 @@ char *MCD_strdup(const char*s,char*fun,char*file,int line)
514514
char *MCD_strdup(char*s,char*fun,char*file,int line)
515515
#endif
516516
{
517-
char *n;
517+
char * n = nullptr;
518518

519519
#ifdef MCD_FASTFREE
520520
n=(char*)malloc(sizeof(char)*strlen(s)+1+sizeof(Chunk));
@@ -542,7 +542,7 @@ char *MCD_strndup(const char*s, int z,char*fun,char*file,int line)
542542
char *MCD_strndup(char*s, int z,char*fun,char*file,int line)
543543
#endif
544544
{
545-
char *n;
545+
char * n = nullptr;
546546
int size;
547547
if((signed)strlen(s)>z)
548548
size=z;
@@ -575,7 +575,7 @@ int MCD_asprintf(char **ptr,const char *fmt,char *fun, char*file, int line,...)
575575
int retval;
576576
va_list argptr;
577577
#ifdef MCD_FASTFREE
578-
void *fc;
578+
void * fc = nullptr;
579579
#endif
580580

581581
va_start(argptr,line);
@@ -610,7 +610,7 @@ int MCD_vasprintf(char **ptr,const char *fmt,va_list argptr,char *fun, char*file
610610
{
611611
int retval;
612612
#ifdef MCD_FASTFREE
613-
void *fc;
613+
void * fc = nullptr;
614614
#endif
615615

616616
if((retval=vasprintf(ptr, fmt, argptr))<0)
@@ -781,7 +781,7 @@ void showMemStats()
781781
Chunk*c=MemoryChunks;
782782
int total=0;
783783

784-
FILE *o;
784+
FILE * o = nullptr;
785785

786786
if(MemStatLog)
787787
o=MemStatLog;

source/source_base/module_container/ATen/core/tensor_accessor.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,9 +58,9 @@ class TensorAccessorBase {
5858
}
5959

6060
protected:
61-
T* data_;
62-
const index_t* sizes_;
63-
const index_t* strides_;
61+
T* data_ = nullptr;
62+
const index_t* sizes_ = nullptr;
63+
const index_t* strides_ = nullptr;
6464
};
6565

6666
template <typename T, size_t N, typename index_t = int64_t,

source/source_base/module_container/base/core/gpu_allocator.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ namespace base {
1818
namespace core {
1919
// Allocate a block of memory with the given size and default alignment on GPU.
2020
void *GPUAllocator::allocate(size_t size) {
21-
void *ptr;
21+
void * ptr = nullptr;
2222
device_result_t result = device_malloc(&ptr, size);
2323
if (result != device_success) {
2424
return nullptr;
@@ -29,7 +29,7 @@ void *GPUAllocator::allocate(size_t size) {
2929

3030
// Allocate a block of CPU memory with the given size and alignment.
3131
void *GPUAllocator::allocate(size_t size, size_t alignment) {
32-
void *ptr;
32+
void * ptr = nullptr;
3333
device_result_t result = device_malloc(&ptr, size);
3434
if (result != device_success) {
3535
return nullptr;

source/source_base/module_container/base/third_party/cusolver.h

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ void potri (cusolverDnHandle_t& cusolver_handle, const char& uplo, const char& d
5353
{
5454
int lwork;
5555
CHECK_CUSOLVER(cusolverDnSpotri_bufferSize(cusolver_handle, cublas_fill_mode(uplo), n, A, n, &lwork));
56-
float* work;
56+
float* work = nullptr;
5757
CHECK_CUDA(cudaMalloc((void**)&work, lwork * sizeof(float)));
5858
// Perform Cholesky decomposition
5959
CHECK_CUSOLVER(cusolverDnSpotri(cusolver_handle, cublas_fill_mode(uplo), n, A, n, work, lwork, nullptr));
@@ -64,7 +64,7 @@ void potri (cusolverDnHandle_t& cusolver_handle, const char& uplo, const char& d
6464
{
6565
int lwork;
6666
CHECK_CUSOLVER(cusolverDnDpotri_bufferSize(cusolver_handle, cublas_fill_mode(uplo), n, A, n, &lwork));
67-
double* work;
67+
double* work = nullptr;
6868
CHECK_CUDA(cudaMalloc((void**)&work, lwork * sizeof(double)));
6969
// Perform Cholesky decomposition
7070
CHECK_CUSOLVER(cusolverDnDpotri(cusolver_handle, cublas_fill_mode(uplo), n, A, n, work, lwork, nullptr));
@@ -75,7 +75,7 @@ void potri (cusolverDnHandle_t& cusolver_handle, const char& uplo, const char& d
7575
{
7676
int lwork;
7777
CHECK_CUSOLVER(cusolverDnCpotri_bufferSize(cusolver_handle, cublas_fill_mode(uplo), n, reinterpret_cast<cuComplex *>(A), n, &lwork));
78-
cuComplex* work;
78+
cuComplex* work = nullptr;
7979
CHECK_CUDA(cudaMalloc((void**)&work, lwork * sizeof(cuComplex)));
8080
// Perform Cholesky decomposition
8181
CHECK_CUSOLVER(cusolverDnCpotri(cusolver_handle, cublas_fill_mode(uplo), n, reinterpret_cast<cuComplex *>(A), n, work, lwork, nullptr));
@@ -86,7 +86,7 @@ void potri (cusolverDnHandle_t& cusolver_handle, const char& uplo, const char& d
8686
{
8787
int lwork;
8888
CHECK_CUSOLVER(cusolverDnZpotri_bufferSize(cusolver_handle, cublas_fill_mode(uplo), n, reinterpret_cast<cuDoubleComplex *>(A), n, &lwork));
89-
cuDoubleComplex* work;
89+
cuDoubleComplex* work = nullptr;
9090
CHECK_CUDA(cudaMalloc((void**)&work, lwork * sizeof(cuDoubleComplex)));
9191
// Perform Cholesky decomposition
9292
CHECK_CUSOLVER(cusolverDnZpotri(cusolver_handle, cublas_fill_mode(uplo), n, reinterpret_cast<cuDoubleComplex *>(A), n, work, lwork, nullptr));
@@ -101,7 +101,7 @@ void potrf (cusolverDnHandle_t& cusolver_handle, const char& uplo, const int& n,
101101
int *info = nullptr;
102102
CHECK_CUDA(cudaMalloc((void**)&info, 1 * sizeof(int)));
103103
CHECK_CUSOLVER(cusolverDnSpotrf_bufferSize(cusolver_handle, cublas_fill_mode(uplo), n, A, n, &lwork));
104-
float* work;
104+
float* work = nullptr;
105105
CHECK_CUDA(cudaMalloc((void**)&work, lwork * sizeof(float)));
106106
// Perform Cholesky decomposition
107107
CHECK_CUSOLVER(cusolverDnSpotrf(cusolver_handle, cublas_fill_mode(uplo), n, A, n, work, lwork, info));
@@ -115,7 +115,7 @@ void potrf (cusolverDnHandle_t& cusolver_handle, const char& uplo, const int& n,
115115
int *info = nullptr;
116116
CHECK_CUDA(cudaMalloc((void**)&info, 1 * sizeof(int)));
117117
CHECK_CUSOLVER(cusolverDnDpotrf_bufferSize(cusolver_handle, cublas_fill_mode(uplo), n, A, n, &lwork));
118-
double* work;
118+
double* work = nullptr;
119119
CHECK_CUDA(cudaMalloc((void**)&work, lwork * sizeof(double)));
120120
// Perform Cholesky decomposition
121121
CHECK_CUSOLVER(cusolverDnDpotrf(cusolver_handle, cublas_fill_mode(uplo), n, A, n, work, lwork, info));
@@ -129,7 +129,7 @@ void potrf (cusolverDnHandle_t& cusolver_handle, const char& uplo, const int& n,
129129
int *info = nullptr;
130130
CHECK_CUDA(cudaMalloc((void**)&info, 1 * sizeof(int)));
131131
CHECK_CUSOLVER(cusolverDnCpotrf_bufferSize(cusolver_handle, cublas_fill_mode(uplo), n, reinterpret_cast<cuComplex*>(A), lda, &lwork));
132-
cuComplex* work;
132+
cuComplex* work = nullptr;
133133
CHECK_CUDA(cudaMalloc((void**)&work, lwork * sizeof(cuComplex)));
134134
// Perform Cholesky decomposition
135135
CHECK_CUSOLVER(cusolverDnCpotrf(cusolver_handle, cublas_fill_mode(uplo), n, reinterpret_cast<cuComplex*>(A), lda, work, lwork, info));
@@ -143,7 +143,7 @@ void potrf (cusolverDnHandle_t& cusolver_handle, const char& uplo, const int& n,
143143
int *info = nullptr;
144144
CHECK_CUDA(cudaMalloc((void**)&info, 1 * sizeof(int)));
145145
CHECK_CUSOLVER(cusolverDnZpotrf_bufferSize(cusolver_handle, cublas_fill_mode(uplo), n, reinterpret_cast<cuDoubleComplex*>(A), lda, &lwork));
146-
cuDoubleComplex* work;
146+
cuDoubleComplex* work = nullptr;
147147
CHECK_CUDA(cudaMalloc((void**)&work, lwork * sizeof(cuDoubleComplex)));
148148
// Perform Cholesky decomposition
149149
CHECK_CUSOLVER(cusolverDnZpotrf(cusolver_handle, cublas_fill_mode(uplo), n, reinterpret_cast<cuDoubleComplex*>(A), lda, work, lwork, info));

source/source_base/module_container/base/third_party/hipsolver.h

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ void potri (hipsolverHandle_t& hipsolver_handle, const char& uplo, const char& d
4343
{
4444
int lwork;
4545
hipsolverErrcheck(hipsolverDnSpotri_bufferSize(hipsolver_handle, hipsolver_fill_mode(uplo), n, A, n, &lwork));
46-
float* work;
46+
float* work = nullptr;
4747
hipErrcheck(hipMalloc((void**)&work, lwork * sizeof(float)));
4848
// Perform Cholesky decomposition
4949
hipsolverErrcheck(hipsolverDnSpotri(hipsolver_handle, hipsolver_fill_mode(uplo), n, A, n, work, lwork, nullptr));
@@ -54,7 +54,7 @@ void potri (hipsolverHandle_t& hipsolver_handle, const char& uplo, const char& d
5454
{
5555
int lwork;
5656
hipsolverErrcheck(hipsolverDnDpotri_bufferSize(hipsolver_handle, hipsolver_fill_mode(uplo), n, A, n, &lwork));
57-
double* work;
57+
double* work = nullptr;
5858
hipErrcheck(hipMalloc((void**)&work, lwork * sizeof(double)));
5959
// Perform Cholesky decomposition
6060
hipsolverErrcheck(hipsolverDnDpotri(hipsolver_handle, hipsolver_fill_mode(uplo), n, A, n, work, lwork, nullptr));
@@ -65,7 +65,7 @@ void potri (hipsolverHandle_t& hipsolver_handle, const char& uplo, const char& d
6565
{
6666
int lwork;
6767
hipsolverErrcheck(hipsolverDnCpotri_bufferSize(hipsolver_handle, hipsolver_fill_mode(uplo), n, reinterpret_cast<hipFloatComplex *>(A), n, &lwork));
68-
hipFloatComplex* work;
68+
hipFloatComplex* work = nullptr;
6969
hipErrcheck(hipMalloc((void**)&work, lwork * sizeof(hipFloatComplex)));
7070
// Perform Cholesky decomposition
7171
hipsolverErrcheck(hipsolverDnCpotri(hipsolver_handle, hipsolver_fill_mode(uplo), n, reinterpret_cast<hipFloatComplex *>(A), n, work, lwork, nullptr));
@@ -76,7 +76,7 @@ void potri (hipsolverHandle_t& hipsolver_handle, const char& uplo, const char& d
7676
{
7777
int lwork;
7878
hipsolverErrcheck(hipsolverDnZpotri_bufferSize(hipsolver_handle, hipsolver_fill_mode(uplo), n, reinterpret_cast<hipDoubleComplex *>(A), n, &lwork));
79-
hipDoubleComplex* work;
79+
hipDoubleComplex* work = nullptr;
8080
hipErrcheck(hipMalloc((void**)&work, lwork * sizeof(hipDoubleComplex)));
8181
// Perform Cholesky decomposition
8282
hipsolverErrcheck(hipsolverDnZpotri(hipsolver_handle, hipsolver_fill_mode(uplo), n, reinterpret_cast<hipDoubleComplex *>(A), n, work, lwork, nullptr));
@@ -89,7 +89,7 @@ void potrf (hipsolverHandle_t& hipsolver_handle, const char& uplo, const int& n,
8989
{
9090
int lwork;
9191
hipsolverErrcheck(hipsolverDnSpotrf_bufferSize(hipsolver_handle, hipsolver_fill_mode(uplo), n, A, n, &lwork));
92-
float* work;
92+
float* work = nullptr;
9393
hipErrcheck(hipMalloc((void**)&work, lwork * sizeof(float)));
9494
// Perform Cholesky decomposition
9595
hipsolverErrcheck(hipsolverDnSpotrf(hipsolver_handle, hipsolver_fill_mode(uplo), n, A, n, work, lwork, nullptr));
@@ -100,7 +100,7 @@ void potrf (hipsolverHandle_t& hipsolver_handle, const char& uplo, const int& n,
100100
{
101101
int lwork;
102102
hipsolverErrcheck(hipsolverDnDpotrf_bufferSize(hipsolver_handle, hipsolver_fill_mode(uplo), n, A, n, &lwork));
103-
double* work;
103+
double* work = nullptr;
104104
hipErrcheck(hipMalloc((void**)&work, lwork * sizeof(double)));
105105
// Perform Cholesky decomposition
106106
hipsolverErrcheck(hipsolverDnDpotrf(hipsolver_handle, hipsolver_fill_mode(uplo), n, A, n, work, lwork, nullptr));
@@ -111,7 +111,7 @@ void potrf (hipsolverHandle_t& hipsolver_handle, const char& uplo, const int& n,
111111
{
112112
int lwork;
113113
hipsolverErrcheck(hipsolverDnCpotrf_bufferSize(hipsolver_handle, hipsolver_fill_mode(uplo), n, reinterpret_cast<hipFloatComplex*>(A), n, &lwork));
114-
hipFloatComplex* work;
114+
hipFloatComplex* work = nullptr;
115115
hipErrcheck(hipMalloc((void**)&work, lwork * sizeof(hipFloatComplex)));
116116
// Perform Cholesky decomposition
117117
hipsolverErrcheck(hipsolverDnCpotrf(hipsolver_handle, hipsolver_fill_mode(uplo), n, reinterpret_cast<hipFloatComplex*>(A), n, work, lwork, nullptr));
@@ -122,7 +122,7 @@ void potrf (hipsolverHandle_t& hipsolver_handle, const char& uplo, const int& n,
122122
{
123123
int lwork;
124124
hipsolverErrcheck(hipsolverDnZpotrf_bufferSize(hipsolver_handle, hipsolver_fill_mode(uplo), n, reinterpret_cast<hipDoubleComplex*>(A), n, &lwork));
125-
hipDoubleComplex* work;
125+
hipDoubleComplex* work = nullptr;
126126
hipErrcheck(hipMalloc((void**)&work, lwork * sizeof(hipDoubleComplex)));
127127
// Perform Cholesky decomposition
128128
hipsolverErrcheck(hipsolverDnZpotrf(hipsolver_handle, hipsolver_fill_mode(uplo), n, reinterpret_cast<hipDoubleComplex*>(A), n, work, lwork, nullptr));

0 commit comments

Comments
 (0)