Skip to content

Commit

Permalink
Merge pull request #6 from PlasmaFAIR/bugfix/avoid-potential-out-of-b…
Browse files Browse the repository at this point in the history
…ounds-index

Avoid any potential out-of-bounds indexing in neasyf_type
  • Loading branch information
ZedThree authored Apr 4, 2023
2 parents 5a7b585 + 1a14b84 commit af71a7c
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 8 deletions.
28 changes: 21 additions & 7 deletions src/neasyf.f90
Original file line number Diff line number Diff line change
Expand Up @@ -280,43 +280,57 @@ end function neasyf_type_scalar
function neasyf_type_rank1(variable) result(nf_type)
integer(nf_kind) :: nf_type
class(*), dimension(:), intent(in) :: variable
nf_type = neasyf_type(variable(1))
class(*), dimension(:), allocatable :: local
allocate(local(1), mold=variable)
nf_type = neasyf_type(local(1))
end function neasyf_type_rank1

function neasyf_type_rank2(variable) result(nf_type)
integer(nf_kind) :: nf_type
class(*), dimension(:, :), intent(in) :: variable
nf_type = neasyf_type(variable(1, 1))
class(*), dimension(:, :), allocatable :: local
allocate(local(1, 1), mold=variable)
nf_type = neasyf_type(local(1, 1))
end function neasyf_type_rank2

function neasyf_type_rank3(variable) result(nf_type)
integer(nf_kind) :: nf_type
class(*), dimension(:, :, :), intent(in) :: variable
nf_type = neasyf_type(variable(1, 1, 1))
class(*), dimension(:, :, :), allocatable :: local
allocate(local(1, 1, 1), mold=variable)
nf_type = neasyf_type(local(1, 1, 1))
end function neasyf_type_rank3

function neasyf_type_rank4(variable) result(nf_type)
integer(nf_kind) :: nf_type
class(*), dimension(:, :, :, :), intent(in) :: variable
nf_type = neasyf_type(variable(1, 1, 1, 1))
class(*), dimension(:, :, :, :), allocatable :: local
allocate(local(1, 1, 1, 1), mold=variable)
nf_type = neasyf_type(local(1, 1, 1, 1))
end function neasyf_type_rank4

function neasyf_type_rank5(variable) result(nf_type)
integer(nf_kind) :: nf_type
class(*), dimension(:, :, :, :, :), intent(in) :: variable
nf_type = neasyf_type(variable(1, 1, 1, 1, 1))
class(*), dimension(:, :, :, :, :), allocatable :: local
allocate(local(1, 1, 1, 1, 1), mold=variable)
nf_type = neasyf_type(local(1, 1, 1, 1, 1))
end function neasyf_type_rank5

function neasyf_type_rank6(variable) result(nf_type)
integer(nf_kind) :: nf_type
class(*), dimension(:, :, :, :, :, :), intent(in) :: variable
nf_type = neasyf_type(variable(1, 1, 1, 1, 1, 1))
class(*), dimension(:, :, :, :, :, :), allocatable :: local
allocate(local(1, 1, 1, 1, 1, 1), mold=variable)
nf_type = neasyf_type(local(1, 1, 1, 1, 1, 1))
end function neasyf_type_rank6

function neasyf_type_rank7(variable) result(nf_type)
integer(nf_kind) :: nf_type
class(*), dimension(:, :, :, :, :, :, :), intent(in) :: variable
nf_type = neasyf_type(variable(1, 1, 1, 1, 1, 1, 1))
class(*), dimension(:, :, :, :, :, :, :), allocatable :: local
allocate(local(1, 1, 1, 1, 1, 1, 1), mold=variable)
nf_type = neasyf_type(local(1, 1, 1, 1, 1, 1, 1))
end function neasyf_type_rank7


Expand Down
4 changes: 3 additions & 1 deletion src/neasyf.type.in.f90
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
function neasyf_type_rank{n}(variable) result(nf_type)
integer(nf_kind) :: nf_type
class(*), dimension({array(n)}), intent(in) :: variable
nf_type = neasyf_type(variable({slice(n)}))
class(*), dimension({array(n)}), allocatable :: local
allocate(local({slice(n)}), mold=variable)
nf_type = neasyf_type(local({slice(n)}))
end function neasyf_type_rank{n}

0 comments on commit af71a7c

Please sign in to comment.