changeset 6328:e97a1cc44be8

(Finsert_file_contents): Don't let same_at_end be less than same_at_start.
author Richard M. Stallman <rms@gnu.org>
date Mon, 14 Mar 1994 01:29:37 +0000
parents d93a087868cb
children a8922d5bcb06
files src/fileio.c
diffstat 1 files changed, 9 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/src/fileio.c	Mon Mar 14 01:29:15 1994 +0000
+++ b/src/fileio.c	Mon Mar 14 01:29:37 1994 +0000
@@ -2607,6 +2607,8 @@
       char buffer[1 << 14];
       int same_at_start = BEGV;
       int same_at_end = ZV;
+      int overlap;
+
       immediate_quit = 1;
       QUIT;
       /* Count how many chars at the start of the file
@@ -2678,9 +2680,16 @@
 	    break;
 	}
       immediate_quit = 0;
+
+      /* Don't try to reuse the same piece of text twice.  */
+      overlap = same_at_start - BEGV - (same_at_end + st.st_size - ZV);
+      if (overlap > 0)
+	same_at_end += overlap;
+
       /* Arrange to read only the nonmatching middle part of the file.  */
       XFASTINT (beg) = same_at_start - BEGV;
       XFASTINT (end) = st.st_size - (ZV - same_at_end);
+
       del_range_1 (same_at_start, same_at_end, 0);
       /* Insert from the file at the proper position.  */
       SET_PT (same_at_start);