Merge branch 'vs/prompt-avoid-unset-variable'
[gitweb.git] / xdiff / xemit.c
index 29cec1259ca9678fd2d73b68e69b37c912e447e3..49aa16ff78d8c0f10942e0f519543cc6befabb9d 100644 (file)
@@ -231,6 +231,8 @@ int xdl_emit_diff(xdfenv_t *xe, xdchange_t *xscr, xdemitcb_t *ecb,
                        long fe1 = get_func_line(xe, xecfg, NULL,
                                                 xche->i1 + xche->chg1,
                                                 xe->xdf1.nrec);
+                       while (fe1 > 0 && is_empty_rec(&xe->xdf1, fe1 - 1))
+                               fe1--;
                        if (fe1 < 0)
                                fe1 = xe->xdf1.nrec;
                        if (fe1 > e1) {
@@ -244,7 +246,8 @@ int xdl_emit_diff(xdfenv_t *xe, xdchange_t *xscr, xdemitcb_t *ecb,
                         * its new end.
                         */
                        if (xche->next) {
-                               long l = xche->next->i1;
+                               long l = XDL_MIN(xche->next->i1,
+                                                xe->xdf1.nrec - 1);
                                if (l <= e1 ||
                                    get_func_line(xe, xecfg, NULL, l, e1) < 0) {
                                        xche = xche->next;