From f636d74d04622d5f3747c5979704a7847dfcae86 Mon Sep 17 00:00:00 2001 From: LUNASEA <33978601+maki49@users.noreply.github.com> Date: Fri, 18 Oct 2024 20:05:11 +0800 Subject: [PATCH] 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> --- source/module_cell/module_symmetry/symmetry.cpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/source/module_cell/module_symmetry/symmetry.cpp b/source/module_cell/module_symmetry/symmetry.cpp index 4cc925fedb..743f2156aa 100644 --- a/source/module_cell/module_symmetry/symmetry.cpp +++ b/source/module_cell/module_symmetry/symmetry.cpp @@ -1001,7 +1001,7 @@ bool Symmetry::checksym(const ModuleBase::Matrix3& s, ModuleBase::Vector3 trans(2.0, 2.0, 2.0); - bool s_flag = 0; + bool s_flag = false; for (int it = 0; it < ntype; it++) { @@ -1123,7 +1123,7 @@ bool Symmetry::checksym(const ModuleBase::Matrix3& s, ModuleBase::Vector3 *rhogtot, assert(nrotk <=48 ); //map the gmatrix to inv - int* invmap = new int[nrotk]; - this->gmatrix_invmap(kgmatrix, nrotk, invmap); + std::vectorinvmap(this->nrotk, -1); + this->gmatrix_invmap(kgmatrix, nrotk, invmap.data()); // --------------------------------------------------- /* This code defines a lambda function called "rotate_recip" that takes @@ -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); @@ -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"); }