Skip to content

Commit

Permalink
Fixed integer overflow in excit_gen memory allocation (mostly affects…
Browse files Browse the repository at this point in the history
… printing.
  • Loading branch information
ajwt committed Mar 20, 2019
1 parent ab278af commit ac34819
Showing 1 changed file with 21 additions and 12 deletions.
33 changes: 21 additions & 12 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,13 +386,15 @@ 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=(int(len_one,int_64)*len_two)*len_three

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)

Expand All @@ -403,15 +407,17 @@ 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_two = array_two(2) - array_two(1) + 1
len_tot=(int(len_one,int_64)*len_two)*len_three

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)

Expand All @@ -424,13 +430,16 @@ 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=((int(len_one,int_64)*len_two)*len_three)*len_four

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)

Expand Down

0 comments on commit ac34819

Please sign in to comment.