Skip to content

Commit 37e8721

Browse files
committed
fixed a potential stack overflow with intel compiler
1 parent 305bf8a commit 37e8721

File tree

1 file changed

+21
-1
lines changed

1 file changed

+21
-1
lines changed

src/pyplot_module.F90

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,27 @@ subroutine add_str(me,str)
129129
class(pyplot), intent(inout) :: me !! pyplot handler
130130
character(len=*), intent(in) :: str !! str to be added to pyplot handler buffer
131131

132-
me%str = me%str//str//new_line(' ')
132+
integer :: n_old !! current `me%str` length
133+
integer :: n_str !! length of input `str`
134+
character(len=:),allocatable :: tmp !! tmp string for building the result
135+
136+
! original
137+
!me%str = me%str//str//new_line(' ')
138+
139+
if (len(str)==0) return
140+
141+
! the above can sometimes cause a stack overflow in the
142+
! intel Fortran compiler, so we replace with this:
143+
if (allocated(me%str)) then
144+
n_old = len(me%str)
145+
n_str = len(str)
146+
allocate(character(len=n_old+n_str+1) :: tmp)
147+
tmp(1:n_old) = me%str
148+
tmp(n_old+1:) = str//new_line(' ')
149+
call move_alloc(tmp, me%str)
150+
else
151+
allocate(me%str, source = str//new_line(' '))
152+
end if
133153

134154
end subroutine add_str
135155
!*****************************************************************************************

0 commit comments

Comments
 (0)