Skip to content

Commit f636d74

Browse files
Fix a segfault in rhog_symmetry (#5303)
* 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>
1 parent 255e104 commit f636d74

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

source/module_cell/module_symmetry/symmetry.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1001,7 +1001,7 @@ bool Symmetry::checksym(const ModuleBase::Matrix3& s, ModuleBase::Vector3<double
10011001
// the start atom index.
10021002
bool no_diff = false;
10031003
ModuleBase::Vector3<double> trans(2.0, 2.0, 2.0);
1004-
bool s_flag = 0;
1004+
bool s_flag = false;
10051005

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

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

15661566
// ---------------------------------------------------
15671567
/* This code defines a lambda function called "rotate_recip" that takes
@@ -1629,6 +1629,7 @@ ModuleBase::timer::tick("Symmetry","group fft grids");
16291629
int rot_count=0;
16301630
for (int isym = 0; isym < nrotk; ++isym)
16311631
{
1632+
if (invmap[isym] < 0 || invmap[isym] > nrotk) { continue; }
16321633
//tmp variables
16331634
int ii, jj, kk=0;
16341635
rotate_recip(kgmatrix[invmap[isym]], tmp_gdirect0, ii, jj, kk);
@@ -1750,7 +1751,6 @@ for (int g_index = 0; g_index < group_index; g_index++)
17501751
delete[] symflag;
17511752
delete[] isymflag;
17521753
delete[] table_xyz;
1753-
delete[] invmap;
17541754
delete[] count_xyz;
17551755
ModuleBase::timer::tick("Symmetry","rhog_symmetry");
17561756
}

0 commit comments

Comments
 (0)