patch 8.0.0968: crash when switching terminal modes

Problem:    Crash when switching terminal modes. (Nikolai Pavlov)
Solution:   Check that there are scrollback lines.
diff --git a/src/terminal.c b/src/terminal.c
index 6b401be..bb2dba9 100644
--- a/src/terminal.c
+++ b/src/terminal.c
@@ -1037,14 +1037,13 @@
 
     /* Remove the terminal contents from the scrollback and the buffer. */
     gap = &term->tl_scrollback;
-    while (curbuf->b_ml.ml_line_count > term->tl_scrollback_scrolled)
+    while (curbuf->b_ml.ml_line_count > term->tl_scrollback_scrolled
+							    && gap->ga_len > 0)
     {
 	ml_delete(curbuf->b_ml.ml_line_count, FALSE);
 	line = (sb_line_T *)gap->ga_data + gap->ga_len - 1;
 	vim_free(line->sb_cells);
 	--gap->ga_len;
-	if (gap->ga_len == 0)
-	    break;
     }
     check_cursor();