File tree Expand file tree Collapse file tree
source/source_io/module_wf Expand file tree Collapse file tree Original file line number Diff line number Diff line change 99#include " source_base/timer.h"
1010#include " source_base/vector3.h"
1111
12+ #include < limits>
13+
1214void ModuleIO::read_wfc_pw (const std::string& filename,
1315 const ModulePW::PW_Basis_K* pw_wfc,
1416 const int rank_in_pool,
@@ -195,9 +197,18 @@ void ModuleIO::read_wfc_pw(const std::string& filename,
195197 rfs >> size;
196198 }
197199
200+ const size_t nxyz_sz = static_cast <size_t >(nx) * static_cast <size_t >(ny) * static_cast <size_t >(nz);
201+ if (nx <= 0 || ny <= 0 || nz <= 0
202+ || nxyz_sz > static_cast <size_t >(std::numeric_limits<int >::max ()))
203+ {
204+ ModuleBase::WARNING_QUIT (" ModuleIO::read_wfc_pw" ,
205+ " Invalid FFT grid or nx*ny*nz overflow for glo_order allocation." );
206+ }
207+ const int nxyz = static_cast <int >(nxyz_sz);
208+
198209 // map global index to read ordering for plane waves
199- glo_order = new int [nx * ny * nz ];
200- for (int i = 0 ; i < nx * ny * nz ; i++)
210+ glo_order = new int [nxyz ];
211+ for (int i = 0 ; i < nxyz ; i++)
201212 {
202213 glo_order[i] = -1 ;
203214 }
You can’t perform that action at this time.
0 commit comments