From b977515bd7d089351c1859c14ac881d2793dd6df Mon Sep 17 00:00:00 2001
From: David Lawrence Ramsey <pooka109@gmail.com>
Date: Fri, 19 Mar 2004 02:15:42 +0000
Subject: [PATCH] avoid any more editbot-related segfaults by removing the last
 of the references to it, as in DB's patch

git-svn-id: svn://svn.savannah.gnu.org/nano/trunk/nano@1697 35c25a1d-7b9e-4130-9fde-d3aeb78583b8
---
 ChangeLog    |  3 +++
 src/files.c  |  9 +--------
 src/global.c |  1 -
 src/nano.c   | 26 +++-----------------------
 src/proto.h  |  3 +--
 src/winio.c  | 10 ----------
 6 files changed, 8 insertions(+), 44 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index aee61359..60e50c8d 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -38,6 +38,9 @@ CVS code -
 	  pointing to a different memory block, there will be a segfault
 	  when the value of def is copied into it via strcpy(). (bort,
 	  Christian Weisgarber, David Benbennick, and DLR)
+	- Remove the last editbot references, to avoid any potential
+	  segfaults related to them.  Also remove fix_editbot(), as it's
+	  no longer needed. (David Benbennick)
 - files.c:
   do_insertfile()
 	- Wrap one reference to NANO_EXTCMD_KEY in a NANO_SMALL #ifdef.
diff --git a/src/files.c b/src/files.c
index f346f499..31c4a54d 100644
--- a/src/files.c
+++ b/src/files.c
@@ -75,7 +75,6 @@ void new_file(void)
     fileage->data[0] = '\0';
     filebot = fileage;
     edittop = fileage;
-    editbot = fileage;
     current = fileage;
     current_x = 0;
     totlines = 1;
@@ -592,9 +591,6 @@ int do_insertfile(int loading_file)
 #endif
 	    set_modified();
 
-	/* Here we want to rebuild the edit window */
-	fix_editbot();
-
 #ifdef ENABLE_MULTIBUFFER
 	/* If we've loaded another file, update the titlebar's contents */
 	if (loading_file) {
@@ -618,10 +614,7 @@ int do_insertfile(int loading_file)
 #endif
 
 	/* If we've gone off the bottom, recenter; otherwise, just redraw */
-	if (current->lineno > editbot->lineno)
-	    edit_update(current, CENTER);
-	else
-	    edit_refresh();
+	edit_refresh();
 
     } else {
 	statusbar(_("Cancelled"));
diff --git a/src/global.c b/src/global.c
index 435eaea4..fa524fab 100644
--- a/src/global.c
+++ b/src/global.c
@@ -59,7 +59,6 @@ filestruct *fileage = NULL;	/* Our file buffer */
 filestruct *edittop = NULL;	/* Pointer to the top of the edit
 				   buffer with respect to the
 				   file struct */
-filestruct *editbot = NULL;	/* Same for the bottom */
 filestruct *filebot = NULL;	/* Last node in the file struct */
 filestruct *cutbuffer = NULL;	/* A place to store cut text */
 
diff --git a/src/nano.c b/src/nano.c
index 268d473e..a8e18484 100644
--- a/src/nano.c
+++ b/src/nano.c
@@ -202,7 +202,6 @@ void global_init(int save_cutbuffer)
 	cutbuffer = NULL;
     current = NULL;
     edittop = NULL;
-    editbot = NULL;
     totlines = 0;
     totsize = 0;
     placewewant = 0;
@@ -961,10 +960,8 @@ void do_char(char ch)
 
     /* When a character is inserted on the current magicline, it means
      * we need a new one! */
-    if (filebot == current) {
+    if (filebot == current)
 	new_magicline();
-	fix_editbot();
-    }
 
     /* More dangerousness fun =) */
     current->data = charealloc(current->data, current_len + 2);
@@ -1064,10 +1061,8 @@ int do_delete(void)
 	strcat(current->data, current->next->data);
 
 	foo = current->next;
-	if (filebot == foo) {
+	if (filebot == foo)
 	    filebot = current;
-	    editbot = current;
-	}
 
 	unlink_node(foo);
 	delete_node(foo);
@@ -1132,10 +1127,8 @@ int do_enter(void)
     }
     *tmp = '\0';
 
-    if (current->next == NULL) {
+    if (current->next == NULL)
 	filebot = newnode;
-	editbot = newnode;
-    }
     splice_node(current, newnode, current->next);
 
     totsize++;
@@ -2444,7 +2437,6 @@ int do_justify(void)
     int flags_save = flags;
     long totsize_save = totsize;
     filestruct *edittop_save = edittop;
-    filestruct *editbot_save = editbot;
 #ifndef NANO_SMALL
     filestruct *mark_beginbuf_save = mark_beginbuf;
     int mark_beginx_save = mark_beginx;
@@ -2675,7 +2667,6 @@ int do_justify(void)
 	current_x = current_x_save;
 	current_y = current_y_save;
 	edittop = edittop_save;
-	editbot = editbot_save;
 	if (first_mod_line != NULL) {
 	    filestruct *cutbottom = get_cutbottom();
 
@@ -2940,16 +2931,6 @@ void handle_sigwinch(int s)
 #endif				/* HAVE_WRESIZE */
 #endif				/* HAVE_RESIZETERM */
 
-    fix_editbot();
-
-    if (current_y > editwinrows - 1)
-	edit_update(editbot, CENTER);
-    erase();
-
-    /* Do these because width may have changed. */
-    refresh();
-    titlebar(NULL);
-    edit_refresh();
     display_main_list();
     blank_statusbar();
     total_refresh();
@@ -3014,7 +2995,6 @@ void do_toggle(const toggle *which)
 	wclear(bottomwin);
 	wrefresh(bottomwin);
 	window_init();
-	fix_editbot();
 	edit_refresh();
 	display_main_list();
 	break;
diff --git a/src/proto.h b/src/proto.h
index d0cb35a3..1c2033ec 100644
--- a/src/proto.h
+++ b/src/proto.h
@@ -74,7 +74,7 @@ extern char *alt_speller;
 
 extern int resetstatuspos;
 extern struct stat fileinfo;
-extern filestruct *current, *fileage, *edittop, *editbot, *filebot; 
+extern filestruct *current, *fileage, *edittop, *filebot;
 extern filestruct *cutbuffer;
 #ifndef NANO_SMALL
 extern filestruct *mark_beginbuf;
@@ -517,7 +517,6 @@ int do_cursorpos_void(void);
 int line_len(const char *ptr);
 int do_help(void);
 void do_replace_highlight(int highlight_flag, const char *word);
-void fix_editbot(void);
 #ifdef DEBUG
 void dump_buffer(const filestruct *inptr);
 void dump_buffer_reverse(void);
diff --git a/src/winio.c b/src/winio.c
index 01484ef5..55bfd291 100644
--- a/src/winio.c
+++ b/src/winio.c
@@ -2491,16 +2491,6 @@ void do_replace_highlight(int highlight_flag, const char *word)
 	wattroff(edit, A_REVERSE);
 }
 
-/* Fix editbot, based on the assumption that edittop is correct. */
-void fix_editbot(void)
-{
-    int i;
-
-    editbot = edittop;
-    for (i = 0; i < editwinrows && editbot->next != NULL; i++)
-	editbot = editbot->next;
-}
-
 #ifdef DEBUG
 /* Dump the passed-in file structure to stderr. */
 void dump_buffer(const filestruct *inptr)
-- 
GitLab