@@ -765,26 +765,26 @@ handle_pushline(int cols, const VTermScreenCell *cells, void *user)
765765 /* TODO: put the text in the buffer. */
766766 if (ga_grow (& term -> tl_scrollback , 1 ) == OK )
767767 {
768- VTermScreenCell * p ;
769- int len ;
770- int i ;
768+ VTermScreenCell * p = NULL ;
769+ int len = 0 ;
770+ int i ;
771+ sb_line_T * line ;
771772
772773 /* do not store empty cells at the end */
773774 for (i = 0 ; i < cols ; ++ i )
774775 if (cells [i ].chars [0 ] != 0 )
775776 len = i + 1 ;
776777
777- p = (VTermScreenCell * )alloc ((int )sizeof (VTermScreenCell ) * len );
778+ if (len > 0 )
779+ p = (VTermScreenCell * )alloc ((int )sizeof (VTermScreenCell ) * len );
778780 if (p != NULL )
779- {
780- sb_line_T * line = (sb_line_T * )term -> tl_scrollback .ga_data
781- + term -> tl_scrollback .ga_len ;
782-
783781 mch_memmove (p , cells , sizeof (VTermScreenCell ) * len );
784- line -> sb_cols = len ;
785- line -> sb_cells = p ;
786- ++ term -> tl_scrollback .ga_len ;
787- }
782+
783+ line = (sb_line_T * )term -> tl_scrollback .ga_data
784+ + term -> tl_scrollback .ga_len ;
785+ line -> sb_cols = len ;
786+ line -> sb_cells = p ;
787+ ++ term -> tl_scrollback .ga_len ;
788788 }
789789 return 0 ; /* ignored */
790790}
@@ -818,7 +818,9 @@ move_scrollback_to_buffer(term_T *term)
818818 && cell .chars [0 ] != NUL )
819819 len = pos .col + 1 ;
820820
821- if (len > 0 )
821+ if (len == 0 )
822+ ++ lines_skipped ;
823+ else
822824 {
823825 while (lines_skipped > 0 )
824826 {
@@ -865,13 +867,15 @@ move_scrollback_to_buffer(term_T *term)
865867
866868 ga .ga_len = 0 ;
867869 for (col = 0 ; col < line -> sb_cols ; ++ col )
868- for ( i = 0 ; ( c = line -> sb_cells [ col ]. chars [ i ]) != 0 || i == 0 ; ++ i )
869- {
870- if ( ga_grow ( & ga , MB_MAXBYTES ) == FAIL )
871- goto failed ;
870+ {
871+ if ( ga_grow ( & ga , MB_MAXBYTES ) == FAIL )
872+ goto failed ;
873+ for ( i = 0 ; ( c = line -> sb_cells [ col ]. chars [ i ]) > 0 || i == 0 ; ++ i )
872874 ga .ga_len += mb_char2bytes (c == NUL ? ' ' : c ,
873875 (char_u * )ga .ga_data + ga .ga_len );
874- }
876+ }
877+ if (ga_grow (& ga , 1 ) == FAIL )
878+ goto failed ;
875879 * ((char_u * )ga .ga_data + ga .ga_len ) = NUL ;
876880 ml_append_buf (term -> tl_buffer , lnum , ga .ga_data , ga .ga_len + 1 , FALSE);
877881 }
0 commit comments