-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Avoid any potential out-of-bounds indexing in neasyf_type
Allocate a local variable with the same type as the input, but with exactly one element. This way we can be sure we can index it correctly to call the scalar version. This shouldn't be a problem now that we explicitly disallow zero-sized dimensions, but it's nice to be safe in case the user created the dimensions some other way.
- Loading branch information
Showing
2 changed files
with
24 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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} |