Skip to content

Commit 2617f37

Browse files
committed
fix a segfault in rhog_symmetry
1 parent 1a11dac commit 2617f37

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

source/module_cell/module_symmetry/symmetry.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -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)