Skip to content

Commit 5085ac5

Browse files
committed
index handling
1 parent ae8398c commit 5085ac5

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

src/stdlib_strings.fypp

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -302,11 +302,17 @@ contains
302302

303303
last = len(string)
304304
nsub = len(substring)
305-
if (nsub > 0) then
306-
do while(string(last-nsub+1:last) == substring)
305+
if (nsub > 0 .and. nsub <= last) then
306+
do while(last >= nsub .and. string(last-nsub+1:last) == substring)
307307
last = last - nsub
308308
end do
309309
end if
310+
311+
if (last <= 0) then
312+
chomped_string = ''
313+
return
314+
end if
315+
310316
chomped_string = string(1:last)
311317

312318
end function chomp_substring_char_char

0 commit comments

Comments
 (0)