From 2617f376c3e04730596e81ce2fd26c9a6481dcd8 Mon Sep 17 00:00:00 2001 From: maki49 <1579492865@qq.com> Date: Fri, 18 Oct 2024 17:00:59 +0800 Subject: [PATCH 1/2] fix a segfault in rhog_symmetry --- source/module_cell/module_symmetry/symmetry.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/source/module_cell/module_symmetry/symmetry.cpp b/source/module_cell/module_symmetry/symmetry.cpp index 4cc925fedb..2ae95436cb 100644 --- a/source/module_cell/module_symmetry/symmetry.cpp +++ b/source/module_cell/module_symmetry/symmetry.cpp @@ -1560,8 +1560,8 @@ void Symmetry::rhog_symmetry(std::complex *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"); } From 8bb6af414fb3d2a1fac0efcb4eafa924432e3843 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci-lite[bot]" <117423508+pre-commit-ci-lite[bot]@users.noreply.github.com> Date: Fri, 18 Oct 2024 10:13:49 +0000 Subject: [PATCH 2/2] [pre-commit.ci lite] apply automatic fixes --- source/module_cell/module_symmetry/symmetry.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/source/module_cell/module_symmetry/symmetry.cpp b/source/module_cell/module_symmetry/symmetry.cpp index 2ae95436cb..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