Skip to content

Commit 584371e

Browse files
authored
fix(util-sparse): fix stack overflow exception in overloaded sparse init (#979)
1 parent c3f4153 commit 584371e

File tree

1 file changed

+19
-16
lines changed

1 file changed

+19
-16
lines changed

src/Utilities/Sparse.f90

Lines changed: 19 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -64,22 +64,25 @@ end subroutine initialize
6464

6565
! overload
6666
subroutine initializefixed(this,nrow,ncol,maxnnz)
67-
implicit none
68-
class(sparsematrix), intent(inout) :: this
69-
integer(I4B),intent(in) :: nrow,ncol
70-
integer(I4B),intent(in) :: maxnnz
71-
! local
72-
integer(I4B), dimension(nrow) :: rowmaxnnz
73-
integer(I4B) :: i
74-
75-
do i=1,nrow
76-
rowmaxnnz(i) = maxnnz
77-
enddo
78-
79-
call this%initialize(nrow, ncol, rowmaxnnz)
80-
67+
implicit none
68+
class(sparsematrix), intent(inout) :: this
69+
integer(I4B),intent(in) :: nrow,ncol
70+
integer(I4B),intent(in) :: maxnnz
71+
! local
72+
integer(I4B), dimension(:), allocatable :: rowmaxnnz
73+
integer(I4B) :: i
74+
75+
allocate(rowmaxnnz(nrow))
76+
77+
do i=1,nrow
78+
rowmaxnnz(i) = maxnnz
79+
enddo
80+
81+
call this%initialize(nrow, ncol, rowmaxnnz)
82+
deallocate(rowmaxnnz)
83+
8184
end subroutine initializefixed
82-
85+
8386
subroutine filliaja(this, ia, ja, ierror, sort)
8487
!allocate and fill the ia and ja arrays using information
8588
!from the sparsematrix.
@@ -274,4 +277,4 @@ subroutine csr_diagsum(ia, flowja)
274277
return
275278
end subroutine csr_diagsum
276279

277-
end module SparseModule
280+
end module SparseModule

0 commit comments

Comments
 (0)