Commit cab4bca
abacus_fixer
fix(klist): restore nkstot loop bound in pack_kpts to fix heap overflow
bee21a3 changed the kvec_c_full loop in pack_kpts from `nkstot` to
`kvec_c_full.size()`, but the aux buffer is still allocated as
`nkstot_nospin * 3` (which equals `nkstot * 3` at the assignment point
in klist.cpp:291, before spin doubling).
For nspin=2 cases (spin_mult=2), kvec_c_full has been resized to
`nkstot * 2` by renew(), so the new loop writes 2x past the end of
kvec_c_full_aux, corrupting the heap and causing `free(): invalid
pointer` when ESolver_FP is destroyed.
Restore the original `nkstot` bound so the behavior matches the
pre-refactor code exactly. The aux buffer (allocated as
`nkstot_nospin * 3`) and bcast length (`nkstot_nospin * 3`) are
unchanged; only the loop upper bound is restored.
Verified: 12 failed 01_PW tests (003, 007, 028, 030, 034, 036, 037,
050, 055, 063, 078, 079, 097x2, 206, 815, scf_deltaspin2) all pass
again; valgrind reports no Invalid write from ABACUS code.1 parent f23ff32 commit cab4bca
1 file changed
Lines changed: 0 additions & 4 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
273 | 273 | | |
274 | 274 | | |
275 | 275 | | |
276 | | - | |
277 | | - | |
278 | | - | |
279 | | - | |
280 | 276 | | |
281 | 277 | | |
282 | 278 | | |
| |||
0 commit comments