From 4a9ced730311cb75b21cd812bc0a0223ce82ac89 Mon Sep 17 00:00:00 2001 From: Anthony Scemama Date: Tue, 10 Mar 2020 09:44:59 +0100 Subject: [PATCH] Added bounds check --- devel/cc/spatial_to_spin_MO.irp.f | 4 +- .../import_integrals_ao.irp.f | 86 ++++++++++++++++--- .../import_integrals_mo.irp.f | 34 +++++--- 3 files changed, 97 insertions(+), 27 deletions(-) diff --git a/devel/cc/spatial_to_spin_MO.irp.f b/devel/cc/spatial_to_spin_MO.irp.f index 6342f59..048098a 100644 --- a/devel/cc/spatial_to_spin_MO.irp.f +++ b/devel/cc/spatial_to_spin_MO.irp.f @@ -96,7 +96,7 @@ subroutine get_fock_matrix_alpha(det,F) integer :: i,j,k - F(:,:) = fock_operator_closed_shell_ref_bitmask(:,:) + F(:,:) = fock_op_cshell_ref_bitmask(:,:) end @@ -112,7 +112,7 @@ subroutine get_fock_matrix_beta(det,F) integer :: i,j,k - F(:,:) = fock_operator_closed_shell_ref_bitmask(:,:) + F(:,:) = fock_op_cshell_ref_bitmask(:,:) end diff --git a/devel/import_integrals/import_integrals_ao.irp.f b/devel/import_integrals/import_integrals_ao.irp.f index fcc4155..a151154 100644 --- a/devel/import_integrals/import_integrals_ao.irp.f +++ b/devel/import_integrals/import_integrals_ao.irp.f @@ -11,8 +11,8 @@ subroutine run BEGIN_DOC ! Program to import integrals in the AO basis. ! -! one-electron integrals : format is : i j value -! two-electron integrals : format is : i j k l value +! one-electron integrals : format is : i j value +! two-electron integrals : format is : i j k l value ! Dirac's notation is used : is ! ! These files are read: @@ -30,7 +30,7 @@ subroutine run ! W.qp : electron repulsion integrals ! END_DOC - + integer :: iunit integer :: getunitandopen @@ -38,14 +38,14 @@ subroutine run double precision :: integral double precision, allocatable :: A(:,:) - integer :: n_integrals - integer(key_kind), allocatable :: buffer_i(:) + integer :: n_integrals + integer(key_kind), allocatable :: buffer_i(:) real(integral_kind), allocatable :: buffer_values(:) call ezfio_set_ao_basis_ao_num(ao_num) allocate (A(ao_num,ao_num)) - + A(1,1) = huge(1.d0) iunit = getunitandopen('E.qp','r') read (iunit,*,end=9) A(1,1) @@ -57,9 +57,19 @@ subroutine run endif A = 0.d0 + i = 1 + j = 1 iunit = getunitandopen('T.qp','r') - do + do read (iunit,*,end=10) i,j, integral + if (i<0 .or. i>ao_num) then + print *, i + stop 'i out of bounds in T.qp' + endif + if (j<0 .or. j>ao_num) then + print *, j + stop 'j out of bounds in T.qp' + endif A(i,j) = integral enddo 10 continue @@ -68,9 +78,19 @@ subroutine run call ezfio_set_ao_one_e_ints_io_ao_integrals_kinetic('Read') A = 0.d0 + i = 1 + j = 1 iunit = getunitandopen('S.qp','r') - do + do read (iunit,*,end=11) i,j, integral + if (i<0 .or. i>ao_num) then + print *, i + stop 'i out of bounds in S.qp' + endif + if (j<0 .or. j>ao_num) then + print *, j + stop 'j out of bounds in S.qp' + endif A(i,j) = integral enddo 11 continue @@ -79,8 +99,18 @@ subroutine run call ezfio_set_ao_one_e_ints_io_ao_integrals_overlap('Read') A = 0.d0 + i = 1 + j = 1 iunit = getunitandopen('P.qp','r') - do + do + if (i<0 .or. i>ao_num) then + print *, i + stop 'i out of bounds in P.qp' + endif + if (j<0 .or. j>ao_num) then + print *, j + stop 'j out of bounds in P.qp' + endif read (iunit,*,end=14) i,j, integral A(i,j) = integral enddo @@ -90,9 +120,19 @@ subroutine run call ezfio_set_ao_one_e_ints_io_ao_integrals_pseudo('Read') A = 0.d0 + i = 1 + j = 1 iunit = getunitandopen('V.qp','r') - do + do read (iunit,*,end=12) i,j, integral + if (i<0 .or. i>ao_num) then + print *, i + stop 'i out of bounds in V.qp' + endif + if (j<0 .or. j>ao_num) then + print *, j + stop 'j out of bounds in V.qp' + endif A(i,j) = integral enddo 12 continue @@ -103,9 +143,29 @@ subroutine run allocate(buffer_i(ao_num**3), buffer_values(ao_num**3)) iunit = getunitandopen('W.qp','r') n_integrals=0 + i = 1 + j = 1 + k = 1 + l = 1 buffer_values = 0.d0 - do + do read (iunit,*,end=13) i,j,k,l, integral + if (i<0 .or. i>ao_num) then + print *, i + stop 'i out of bounds in W.qp' + endif + if (j<0 .or. j>ao_num) then + print *, j + stop 'j out of bounds in W.qp' + endif + if (k<0 .or. k>ao_num) then + print *, k + stop 'k out of bounds in W.qp' + endif + if (l<0 .or. l>ao_num) then + print *, l + stop 'l out of bounds in W.qp' + endif n_integrals += 1 call two_e_integrals_index(i, j, k, l, buffer_i(n_integrals) ) buffer_values(n_integrals) = integral @@ -116,7 +176,7 @@ subroutine run enddo 13 continue close(iunit) - + if (n_integrals > 0) then call insert_into_ao_integrals_map(n_integrals,buffer_i,buffer_values) endif @@ -126,5 +186,5 @@ subroutine run call map_save_to_disk(trim(ezfio_filename)//'/work/ao_ints',ao_integrals_map) call ezfio_set_ao_two_e_ints_io_ao_two_e_integrals('Read') - + end diff --git a/devel/import_integrals/import_integrals_mo.irp.f b/devel/import_integrals/import_integrals_mo.irp.f index 3129bc3..3f84f76 100644 --- a/devel/import_integrals/import_integrals_mo.irp.f +++ b/devel/import_integrals/import_integrals_mo.irp.f @@ -9,8 +9,8 @@ subroutine run BEGIN_DOC ! Program to import integrals in the MO basis. ! -! one-electron integrals : format is : i j value -! two-electron integrals : format is : i j k l value +! one-electron integrals : format is : i j value +! two-electron integrals : format is : i j k l value ! Dirac's notation is used : is ! ! These files are read: @@ -28,7 +28,7 @@ subroutine run ! Wmo.qp : electron repulsion integrals ! END_DOC - + integer :: iunit integer :: getunitandopen @@ -36,13 +36,13 @@ subroutine run double precision :: integral double precision, allocatable :: A(:,:) - integer :: n_integrals - integer(key_kind), allocatable :: buffer_i(:) + integer :: n_integrals + integer(key_kind), allocatable :: buffer_i(:) real(integral_kind), allocatable :: buffer_values(:) allocate(buffer_i(mo_num**3), buffer_values(mo_num**3)) allocate (A(mo_num,mo_num)) - + A(1,1) = huge(1.d0) iunit = getunitandopen('E.qp','r') read (iunit,*,end=9) A(1,1) @@ -54,8 +54,10 @@ subroutine run endif A = 0.d0 + i = 1 + j = 1 iunit = getunitandopen('Tmo.qp','r') - do + do read (iunit,*,end=10) i,j, integral if (i<0 .or. i>mo_num) then print *, i @@ -73,8 +75,10 @@ subroutine run call ezfio_set_mo_one_e_ints_io_mo_integrals_kinetic('Read') A = 0.d0 + i = 1 + j = 1 iunit = getunitandopen('Pmo.qp','r') - do + do read (iunit,*,end=14) i,j, integral if (i<0 .or. i>mo_num) then print *, i @@ -92,8 +96,10 @@ subroutine run call ezfio_set_mo_one_e_ints_io_mo_integrals_pseudo('Read') A = 0.d0 + i = 1 + j = 1 iunit = getunitandopen('Vmo.qp','r') - do + do read (iunit,*,end=12) i,j, integral if (i<0 .or. i>mo_num) then print *, i @@ -112,8 +118,12 @@ subroutine run iunit = getunitandopen('Wmo.qp','r') n_integrals=0 + i = 1 + j = 1 + k = 1 + l = 1 buffer_values = 0.d0 - do + do read (iunit,*,end=13) i,j,k,l, integral if (i<0 .or. i>mo_num) then print *, i @@ -142,7 +152,7 @@ subroutine run enddo 13 continue close(iunit) - + if (n_integrals > 0) then call insert_into_mo_integrals_map(n_integrals, buffer_i, buffer_values, & real(mo_integrals_threshold,integral_kind)) @@ -152,5 +162,5 @@ subroutine run call map_save_to_disk(trim(ezfio_filename)//'/work/mo_ints',mo_integrals_map) call ezfio_set_mo_two_e_ints_io_mo_two_e_integrals('Read') - + end