Skip to content

Commit

Permalink
Merge pull request #49 from hande-qmc/bug_fix/int_overflow
Browse files Browse the repository at this point in the history
Fixed integer overflow in excit_gen memory allocation (mostly affects…
  • Loading branch information
verena-neufeld authored Mar 21, 2019
2 parents ab278af + 175d0cf commit 4efb802
Showing 1 changed file with 27 additions and 15 deletions.
42 changes: 27 additions & 15 deletions src/excit_gens.f90
Original file line number Diff line number Diff line change
Expand Up @@ -365,13 +365,15 @@ subroutine alloc_alias_table_data_two_ind_t(alias_data, len_two, len_one)
type(alias_table_data_two_ind_t), intent(inout) :: alias_data
integer, intent(in) :: len_one, len_two
integer :: ierr
integer(int_64) :: len_tot
len_tot=int(len_one,int_64)*len_two

allocate(alias_data%weights(len_two, len_one), stat=ierr)
call check_allocate('alias_data%weights', (len_one*len_two), ierr)
call check_allocate('alias_data%weights', (len_tot), ierr)
allocate(alias_data%aliasU(len_two, len_one), stat=ierr)
call check_allocate('alias_data%aliasU', (len_one*len_two), ierr)
call check_allocate('alias_data%aliasU', (len_tot), ierr)
allocate(alias_data%aliasK(len_two, len_one), stat=ierr)
call check_allocate('alias_data%aliasK', (len_one*len_two), ierr)
call check_allocate('alias_data%aliasK', (len_tot), ierr)
allocate(alias_data%weights_tot(len_one), stat=ierr)
call check_allocate('alias_data%weights_tot', len_one, ierr)

Expand All @@ -384,15 +386,18 @@ subroutine alloc_alias_table_data_three_ind_t(alias_data, len_three, len_two, le
type(alias_table_data_three_ind_t), intent(inout) :: alias_data
integer, intent(in) :: len_one, len_two, len_three
integer :: ierr
integer(int_64) :: len_tot, len_tot_2
len_tot=(int(len_one,int_64)*len_two)*len_three
len_tot_2=int(len_one,int_64)*len_two

allocate(alias_data%weights(len_three, len_two, len_one), stat=ierr)
call check_allocate('alias_data%weights', (len_one*len_two*len_three), ierr)
call check_allocate('alias_data%weights', len_tot, ierr)
allocate(alias_data%aliasU(len_three, len_two, len_one), stat=ierr)
call check_allocate('alias_data%aliasU', (len_one*len_two*len_three), ierr)
call check_allocate('alias_data%aliasU', len_tot, ierr)
allocate(alias_data%aliasK(len_three, len_two, len_one), stat=ierr)
call check_allocate('alias_data%aliasK', (len_one*len_two*len_three), ierr)
call check_allocate('alias_data%aliasK', len_tot, ierr)
allocate(alias_data%weights_tot(len_two, len_one), stat=ierr)
call check_allocate('alias_data%weights_tot', (len_one*len_two), ierr)
call check_allocate('alias_data%weights_tot', len_tot_2, ierr)

end subroutine alloc_alias_table_data_three_ind_t

Expand All @@ -403,17 +408,20 @@ subroutine alloc_alias_table_data_2indarray_three_ind_t(alias_data, len_three, a
type(alias_table_data_three_ind_t), intent(inout) :: alias_data
integer, intent(in) :: len_one, array_two(2), len_three
integer :: ierr, len_two
integer(int_64) :: len_tot, len_tot_2

len_two = array_two(2) - array_two(1) + 1
len_tot=(int(len_one,int_64)*len_two)*len_three
len_tot_2=int(len_one,int_64)*len_two

allocate(alias_data%weights(len_three, array_two(1):array_two(2), len_one), stat=ierr)
call check_allocate('alias_data%weights', (len_one*len_two*len_three), ierr)
call check_allocate('alias_data%weights', len_tot, ierr)
allocate(alias_data%aliasU(len_three, array_two(1):array_two(2), len_one), stat=ierr)
call check_allocate('alias_data%aliasU', (len_one*len_two*len_three), ierr)
call check_allocate('alias_data%aliasU', len_tot, ierr)
allocate(alias_data%aliasK(len_three, array_two(1):array_two(2), len_one), stat=ierr)
call check_allocate('alias_data%aliasK', (len_one*len_two*len_three), ierr)
call check_allocate('alias_data%aliasK', len_tot, ierr)
allocate(alias_data%weights_tot(array_two(1):array_two(2), len_one), stat=ierr)
call check_allocate('alias_data%weights_tot', (len_one*len_two), ierr)
call check_allocate('alias_data%weights_tot', len_tot_2, ierr)

end subroutine alloc_alias_table_data_2indarray_three_ind_t

Expand All @@ -424,15 +432,19 @@ subroutine alloc_alias_table_data_four_ind_t(alias_data, len_four, len_three, le
type(alias_table_data_four_ind_t), intent(inout) :: alias_data
integer, intent(in) :: len_one, len_two, len_three, len_four
integer :: ierr
integer(int_64) :: len_tot, len_tot_2

len_tot=((int(len_one,int_64)*len_two)*len_three)*len_four
len_tot_2=(int(len_one,int_64)*len_two)*len_three

allocate(alias_data%weights(len_four, len_three, len_two, len_one), stat=ierr)
call check_allocate('alias_data%weights', (len_one*len_two*len_three*len_four), ierr)
call check_allocate('alias_data%weights', len_tot, ierr)
allocate(alias_data%aliasU(len_four, len_three, len_two, len_one), stat=ierr)
call check_allocate('alias_data%aliasU', (len_one*len_two*len_three*len_four), ierr)
call check_allocate('alias_data%aliasU', len_tot, ierr)
allocate(alias_data%aliasK(len_four, len_three, len_two, len_one), stat=ierr)
call check_allocate('alias_data%aliasK', (len_one*len_two*len_three*len_four), ierr)
call check_allocate('alias_data%aliasK', len_tot, ierr)
allocate(alias_data%weights_tot(len_three, len_two, len_one), stat=ierr)
call check_allocate('alias_data%weights_tot', (len_one*len_two*len_three), ierr)
call check_allocate('alias_data%weights_tot', len_tot_2, ierr)

end subroutine alloc_alias_table_data_four_ind_t
!--------------------------------------------------------------------------------!
Expand Down

0 comments on commit 4efb802

Please sign in to comment.