Skip to content

Commit 59ce37b

Browse files
author
dyzheng
committed
Fix(lcao): fix uninitialized local variables in hamilt2rho_single
Commit a0c6474 introduced self-referencing local variable declarations (e.g., const int nspin = nspin) which read uninitialized stack memory. This caused SIGSEGV in LCAO tests (01_LCAO_SPIN_S2_Z, 03_LCAO_DFTU_S2_Z). Fixed by properly initializing from PARAM.inp values.
1 parent 54ab2bd commit 59ce37b

1 file changed

Lines changed: 11 additions & 11 deletions

File tree

source/source_esolver/esolver_ks_lcao.cpp

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -413,18 +413,18 @@ void ESolver_KS_LCAO<TK, TR>::hamilt2rho_single(UnitCell& ucell, int istep, int
413413
{
414414
ModuleBase::TITLE("ESolver_KS_LCAO", "hamilt2rho_single");
415415

416-
const int nspin = nspin;
417-
const bool ds_mag_switch = ds_mag_switch;
418-
const bool ds_dir_only = ds_dir_only;
419-
const std::string& ds_scf_mode = ds_scf_mode;
420-
const double ds_scf_thr = ds_scf_thr;
421-
const int ds_phase1_steps = ds_phase1_steps;
422-
const std::string& ds_accel_mode = ds_accel_mode;
423-
const std::string& ds_lambda_strat = ds_lambda_strat;
416+
const int nspin = PARAM.inp.nspin;
417+
const bool ds_mag_switch = PARAM.inp.sc_mag_switch;
418+
const bool ds_dir_only = PARAM.inp.sc_direction_only;
419+
const std::string& ds_scf_mode = PARAM.inp.sc_scf_thr_mode;
420+
const double ds_scf_thr = PARAM.inp.sc_scf_thr;
421+
const int ds_phase1_steps = PARAM.inp.sc_dir_phase1_steps;
422+
const std::string& ds_accel_mode = PARAM.inp.sc_acceleration_mode;
423+
const std::string& ds_lambda_strat = PARAM.inp.sc_lambda_strategy;
424424
const int scf_nmax = PARAM.inp.scf_nmax;
425-
const std::string& calc_type = calc_type;
426-
const std::string& basis = basis;
427-
const std::string& ks_solver = ks_solver;
425+
const std::string& calc_type = PARAM.inp.calculation;
426+
const std::string& basis = PARAM.inp.basis_type;
427+
const std::string& ks_solver = PARAM.inp.ks_solver;
428428

429429
// 1) reset energy
430430
this->pelec->f_en.eband = 0.0;

0 commit comments

Comments
 (0)