patch 8.0.1575: crash when using virtual replace

Problem:    Crash when using virtual replace.
Solution:   Adjust orig_line_count.  Add more tests. (Christian Brabandt)
diff --git a/src/edit.c b/src/edit.c
index 423ccea..21941cb 100644
--- a/src/edit.c
+++ b/src/edit.c
@@ -8907,7 +8907,17 @@
 		|| do_join(2, FALSE, TRUE, FALSE, FALSE) == FAIL)
 	    vim_beep(BO_BS);
 	else
+	{
 	    curwin->w_cursor.col = temp;
+#ifdef FEAT_VREPLACE
+	    /* Adjust orig_line_count in case more lines have been deleted than
+	     * have been added. That makes sure, that open_line() later
+	     * can access all buffer lines correctly */
+	    if (State & VREPLACE_FLAG &&
+		    orig_line_count > curbuf->b_ml.ml_line_count)
+		orig_line_count = curbuf->b_ml.ml_line_count;
+#endif
+	}
     }
     else if (del_char(FALSE) == FAIL)  /* delete char under cursor */
 	vim_beep(BO_BS);