@@ -544,14 +544,17 @@ subroutine format_output_string( self, unit, string, procedure_name, &
544544
545545 subroutine format_first_line ()
546546
547- if ( length <= self % max_width .or. self % max_width == 0 ) then
547+ if ( self % max_width == 0 .or. &
548+ ( length <= self % max_width .and. &
549+ index ( string (1 :min (length, self % max_width)), new_line(' a' )) == 0 &
550+ )) then
548551 write ( unit, ' (a)' , err= 999 , iostat= iostat, iomsg= iomsg ) &
549552 string (1 :length)
550553 remain = 0
551554 return
552555 else
553556
554- index_ = index ( string (1 :self % max_width), new_line(' a' ))
557+ index_ = index ( string (1 :min (length, self % max_width) ), new_line(' a' ))
555558 if ( index_ == 0 ) then
556559 do index_= self % max_width, 1 , - 1
557560 if ( string (index_:index_) == ' ' ) exit
@@ -627,8 +630,9 @@ subroutine indent_format_subsequent_line()
627630 return
628631 else
629632
630- index_ = count + index ( string (count+1 :count+ self % max_width &
631- - indent_len), new_line(' a' ))
633+ index_ = count + index ( string (count+1 : &
634+ min ( length, count+ self % max_width - indent_len) ), &
635+ new_line(' a' ))
632636 if (index_ == count) then
633637 do index_= count+ self % max_width- indent_len, count+1 , - 1
634638 if ( string (index_:index_) == ' ' ) exit
0 commit comments