From e178c7b16ddeeeaffbb336897b192564063d0af6 Mon Sep 17 00:00:00 2001 From: Paul Romano Date: Fri, 12 Jul 2013 19:06:29 -0400 Subject: [PATCH] Fix infinite loop with words greater than 80 characters in write_message. Closes #196 on github. --- src/output.F90 | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/src/output.F90 b/src/output.F90 index f19148fb02..d82b4903c6 100644 --- a/src/output.F90 +++ b/src/output.F90 @@ -185,10 +185,11 @@ contains integer, optional :: level ! verbosity level - integer :: i_start ! starting position - integer :: i_end ! ending position - integer :: line_wrap ! length of line - integer :: length ! length of message + integer :: i_start ! starting position + integer :: i_end ! ending position + integer :: line_wrap ! length of line + integer :: length ! length of message + integer :: last_space ! index of last space (relative to start) ! Set length of line line_wrap = 80 @@ -209,11 +210,17 @@ contains else ! Determine last space in current line - i_end = i_start + index(message(i_start+1:i_start+line_wrap), & + last_space = index(message(i_start+1:i_start+line_wrap), & ' ', BACK=.true.) + if (last_space == 0) then + i_end = min(length + 1, i_start+line_wrap) - 1 + write(ou, fmt='(1X,A)') message(i_start+1:i_end) + else + i_end = i_start + last_space + write(ou, fmt='(1X,A)') message(i_start+1:i_end-1) + end if ! Write up to last space - write(ou, fmt='(1X,A)') message(i_start+1:i_end-1) ! Advance starting position i_start = i_end