Skip to content

Commit

Permalink
Merge branch 'jonbob/cice/fix-unitialized-variable' (PR #1274)
Browse files Browse the repository at this point in the history
This PR fixes an uninitialized variable in function FirstFactor in
ice_spacecurve.F90 and adds testing of its returned value in the calling routine.
It resolves Issue #880 , though not exactly in the manner suggested by the
reporter. The uninitialized variable, res, is initialized to 0, which would be an
invalid return value for this variable, because it represents the index of a
particular value in a derived type array.  This function is only called by one
subroutine, so in the calling routine a check is added to make sure the returned
value is valid before using it.

Fixes #880

Tested with SMS_D.f19_f19.FC5.edison_intel

[BFB]
  • Loading branch information
jonbob committed Mar 22, 2017
2 parents a800f46 + 2b2335c commit 8a195f1
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions components/cice/src/source/ice_spacecurve.F90
Original file line number Diff line number Diff line change
Expand Up @@ -1139,6 +1139,7 @@ function FirstFactor(fac) result(res)
integer (int_kind) :: i

found = .false.
res = 0
i=1
do while (i<=fac%numfact .and. (.not. found))
if(fac%used(i) == 0) then
Expand Down Expand Up @@ -1189,8 +1190,10 @@ subroutine MatchFactor(fac1,fac2,val,found)

val1 = FirstFactor(fac1)
!JMD print *,'Matchfactor: found value: ',val1
found = FindandMark(fac2,val1,.true.)
tmp = FindandMark(fac1,val1,found)
if (val1.ge.1) then
found = FindandMark(fac2,val1,.true.)
tmp = FindandMark(fac1,val1,found)
endif
if (found) then
val = val1
else
Expand Down

0 comments on commit 8a195f1

Please sign in to comment.