Skip to content

Commit

Permalink
Fix a segfault in rhog_symmetry (#5303)
Browse files Browse the repository at this point in the history
* fix a segfault in rhog_symmetry

* [pre-commit.ci lite] apply automatic fixes

---------

Co-authored-by: pre-commit-ci-lite[bot] <117423508+pre-commit-ci-lite[bot]@users.noreply.github.com>
  • Loading branch information
maki49 and pre-commit-ci-lite[bot] authored Oct 18, 2024
1 parent 255e104 commit f636d74
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions source/module_cell/module_symmetry/symmetry.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1001,7 +1001,7 @@ bool Symmetry::checksym(const ModuleBase::Matrix3& s, ModuleBase::Vector3<double
// the start atom index.
bool no_diff = false;
ModuleBase::Vector3<double> trans(2.0, 2.0, 2.0);
bool s_flag = 0;
bool s_flag = false;

for (int it = 0; it < ntype; it++)
{
Expand Down Expand Up @@ -1123,7 +1123,7 @@ bool Symmetry::checksym(const ModuleBase::Matrix3& s, ModuleBase::Vector3<double
//the current test is successful
if (no_diff == true)
{
s_flag = 1;
s_flag = true;
//save the detected translation std::vector temporarily
trans.x = gtrans.x;
trans.y = gtrans.y;
Expand Down Expand Up @@ -1560,8 +1560,8 @@ void Symmetry::rhog_symmetry(std::complex<double> *rhogtot,
assert(nrotk <=48 );

//map the gmatrix to inv
int* invmap = new int[nrotk];
this->gmatrix_invmap(kgmatrix, nrotk, invmap);
std::vector<int>invmap(this->nrotk, -1);
this->gmatrix_invmap(kgmatrix, nrotk, invmap.data());

// ---------------------------------------------------
/* This code defines a lambda function called "rotate_recip" that takes
Expand Down Expand Up @@ -1629,6 +1629,7 @@ ModuleBase::timer::tick("Symmetry","group fft grids");
int rot_count=0;
for (int isym = 0; isym < nrotk; ++isym)
{
if (invmap[isym] < 0 || invmap[isym] > nrotk) { continue; }
//tmp variables
int ii, jj, kk=0;
rotate_recip(kgmatrix[invmap[isym]], tmp_gdirect0, ii, jj, kk);
Expand Down Expand Up @@ -1750,7 +1751,6 @@ for (int g_index = 0; g_index < group_index; g_index++)
delete[] symflag;
delete[] isymflag;
delete[] table_xyz;
delete[] invmap;
delete[] count_xyz;
ModuleBase::timer::tick("Symmetry","rhog_symmetry");
}
Expand Down

0 comments on commit f636d74

Please sign in to comment.