Static Analysis Problem Type Reference

FORTRAN IN argument modified

FORTRAN IN parameters should not be modified.

Declaring an argument as an "IN" argument indicates the intention to use this argument as a pure input parameter. However, this does not alter the fact that all FORTRAN arguments are passed by reference. Therefore, modifying the formal parameter will modify the actual argument, even if it is marked as "IN."

ID

Code Location

Description

1

Definition

The place where the argument was defined

2

Bad memory write

The place where the argument was modifed

Example


subroutine IModifyMyArg(k)
    integer :: k
    k = k+1
end

subroutine TestProc(i)
    integer, intent(in) :: i
    call IModifyMyArg(i)
    ! argument "i" is INTENT(IN) dummy argument
    ! but it is modified by IModifyMyArg
    print *,i
end

integer :: j
read *,j
print *,j
call TestProc(j)
print *,j
end