Skip to content

Commit 784943f

Browse files
henriquemirandaclaude
authored andcommitted
Fix library-path projection overflow when num_proj > num_wann
The library interface called get_projections(lcount=.false.) directly, allocating input_proj at size num_wann. When the projections block defines more functions than num_wann (valid for disentanglement), the fill loop writes beyond the array bounds. Add the counting pass (lcount=.true.) before the fill pass so that num_proj is updated to the actual projection count before input_proj is allocated. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent 46c1b7b commit 784943f

1 file changed

Lines changed: 6 additions & 0 deletions

File tree

src/wannier90_readwrite.F90

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1606,6 +1606,12 @@ subroutine w90_wannier90_readwrite_read_projections(settings, proj, proj_input,
16061606

16071607
if (atom_data%num_species > 0) then
16081608
! only read projections if atom positions are known
1609+
! Count pass first: num_proj may exceed num_wann when there are more initial
1610+
! projections than target Wannier functions (valid for disentanglement).
1611+
! Without this, input_proj is allocated at size num_wann and overflows.
1612+
call w90_readwrite_get_projections(settings, num_proj, atom_data, num_wann, proj_input, &
1613+
recip_lattice, .true., spinors, bohr, stdout, error, comm)
1614+
if (allocated(error)) return
16091615
call w90_readwrite_get_projections(settings, num_proj, atom_data, num_wann, proj_input, &
16101616
recip_lattice, .false., spinors, bohr, stdout, error, comm)
16111617
if (allocated(error)) return

0 commit comments

Comments
 (0)