]> git.wh0rd.org Git - nano.git/commitdiff
Allowing the parameter of free_filestruct() to be NULL,
authorBenno Schulenberg <bensberg@justemail.net>
Thu, 18 Feb 2016 19:58:18 +0000 (19:58 +0000)
committerBenno Schulenberg <bensberg@justemail.net>
Thu, 18 Feb 2016 19:58:18 +0000 (19:58 +0000)
so we can delete four annoying pre-checks.

git-svn-id: svn://svn.savannah.gnu.org/nano/trunk/nano@5651 35c25a1d-7b9e-4130-9fde-d3aeb78583b8

ChangeLog
src/cut.c
src/nano.c
src/text.c

index 8a74ed9ca899e26648c5698a70fff054b266a2c7..21fcd3d016b0c9eb596368e5bf71d59ffa1c434d 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,6 +1,7 @@
 2016-02-18  Benno Schulenberg  <bensberg@justemail.net>
        * src/search.c (do_replace_loop), src/text.c (do_int_spell_fix),
        src/winio.c (edit_refresh): Fix Savannah bug #47127 the proper way.
+       * src/nano.c (free_filestruct): Allow the parameter to be NULL.
 
 2016-02-16  Benno Schulenberg  <bensberg@justemail.net>
        * src/files.c (initialize_buffer_text): Delete redundant assignment.
index e8d24abc347f1ea71112e2832cde551e8bcce657..fffd7bfbeabee5a78ef269d3789e4222be5a221f 100644 (file)
--- a/src/cut.c
+++ b/src/cut.c
@@ -134,9 +134,8 @@ void do_cut_text(
 
     assert(openfile->current != NULL && openfile->current->data != NULL);
 
-    /* If keep_cutbuffer is FALSE and the cutbuffer isn't empty, blow
-     * away the text in the cutbuffer. */
-    if (!keep_cutbuffer && cutbuffer != NULL) {
+    /* Empty the cutbuffer when a chain of cuts is broken. */
+    if (!keep_cutbuffer) {
        free_filestruct(cutbuffer);
        cutbuffer = NULL;
 #ifdef DEBUG
index f9169ed340cf507ed513004f8e6d88b66b09b5cd..84e0e369832c90593df56b5368b1b1d95d51206c 100644 (file)
@@ -163,10 +163,11 @@ filestruct *copy_filestruct(const filestruct *src)
     return head;
 }
 
-/* Free a filestruct. */
+/* Free a whole linked list of filestructs. */
 void free_filestruct(filestruct *src)
 {
-    assert(src != NULL);
+    if (src == NULL)
+       return;
 
     while (src->next != NULL) {
        src = src->next;
@@ -364,8 +365,7 @@ void move_to_filestruct(filestruct **file_top, filestruct **file_bot,
            *file_bot = openfile->filebot;
        }
 
-       openfile->fileage->next = NULL;
-       free_filestruct(openfile->fileage);
+       delete_node(openfile->fileage);
 
        /* Renumber starting with the line after the original
         * file_bot. */
index da105ea1f1cc93198a80a218f2eaa86e3e8e1012..996479b8fcd70fea3108f01465811253adb6ca41 100644 (file)
@@ -459,8 +459,7 @@ void redo_cut(undo *u)
     openfile->mark_set = FALSE;
     openfile->mark_begin = NULL;
 
-    if (cutbuffer != NULL)
-       free_filestruct(cutbuffer);
+    free_filestruct(cutbuffer);
     cutbuffer = oldcutbuffer;
     cutbottom = oldcutbottom;
 }
@@ -579,8 +578,7 @@ void do_undo(void)
        openfile->mark_set = TRUE;
        goto_line_posx(u->lineno, u->begin);
        cut_marked();
-       if (u->cutbuffer != NULL)
-           free_filestruct(u->cutbuffer);
+       free_filestruct(u->cutbuffer);
        u->cutbuffer = cutbuffer;
        u->cutbottom = cutbottom;
        cutbuffer = oldcutbuffer;
@@ -903,8 +901,7 @@ void discard_until(const undo *thisitem, openfilestruct *thefile)
     while (dropit != NULL && dropit != thisitem) {
        thefile->undotop = dropit->next;
        free(dropit->strdata);
-       if (dropit->cutbuffer != NULL)
-           free_filestruct(dropit->cutbuffer);
+       free_filestruct(dropit->cutbuffer);
        free(dropit);
        dropit = thefile->undotop;
     }
@@ -1113,8 +1110,7 @@ fprintf(stderr, "  >> Updating... action = %d, openfile->last_action = %d, openf
     case CUT:
        if (!cutbuffer)
            break;
-       if (u->cutbuffer)
-           free_filestruct(u->cutbuffer);
+       free_filestruct(u->cutbuffer);
        u->cutbuffer = copy_filestruct(cutbuffer);
        if (u->mark_set) {
            /* If the "marking" operation was from right-->left or