Allowing the parameter of free_filestruct() to be NULL,

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
This commit is contained in:
Benno Schulenberg 2016-02-18 19:58:18 +00:00
parent 56cfab3df6
commit 9703934479
4 changed files with 11 additions and 15 deletions

View File

@ -1,6 +1,7 @@
2016-02-18 Benno Schulenberg <bensberg@justemail.net> 2016-02-18 Benno Schulenberg <bensberg@justemail.net>
* src/search.c (do_replace_loop), src/text.c (do_int_spell_fix), * 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/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> 2016-02-16 Benno Schulenberg <bensberg@justemail.net>
* src/files.c (initialize_buffer_text): Delete redundant assignment. * src/files.c (initialize_buffer_text): Delete redundant assignment.

View File

@ -134,9 +134,8 @@ void do_cut_text(
assert(openfile->current != NULL && openfile->current->data != NULL); assert(openfile->current != NULL && openfile->current->data != NULL);
/* If keep_cutbuffer is FALSE and the cutbuffer isn't empty, blow /* Empty the cutbuffer when a chain of cuts is broken. */
* away the text in the cutbuffer. */ if (!keep_cutbuffer) {
if (!keep_cutbuffer && cutbuffer != NULL) {
free_filestruct(cutbuffer); free_filestruct(cutbuffer);
cutbuffer = NULL; cutbuffer = NULL;
#ifdef DEBUG #ifdef DEBUG

View File

@ -163,10 +163,11 @@ filestruct *copy_filestruct(const filestruct *src)
return head; return head;
} }
/* Free a filestruct. */ /* Free a whole linked list of filestructs. */
void free_filestruct(filestruct *src) void free_filestruct(filestruct *src)
{ {
assert(src != NULL); if (src == NULL)
return;
while (src->next != NULL) { while (src->next != NULL) {
src = src->next; src = src->next;
@ -364,8 +365,7 @@ void move_to_filestruct(filestruct **file_top, filestruct **file_bot,
*file_bot = openfile->filebot; *file_bot = openfile->filebot;
} }
openfile->fileage->next = NULL; delete_node(openfile->fileage);
free_filestruct(openfile->fileage);
/* Renumber starting with the line after the original /* Renumber starting with the line after the original
* file_bot. */ * file_bot. */

View File

@ -459,7 +459,6 @@ void redo_cut(undo *u)
openfile->mark_set = FALSE; openfile->mark_set = FALSE;
openfile->mark_begin = NULL; openfile->mark_begin = NULL;
if (cutbuffer != NULL)
free_filestruct(cutbuffer); free_filestruct(cutbuffer);
cutbuffer = oldcutbuffer; cutbuffer = oldcutbuffer;
cutbottom = oldcutbottom; cutbottom = oldcutbottom;
@ -579,7 +578,6 @@ void do_undo(void)
openfile->mark_set = TRUE; openfile->mark_set = TRUE;
goto_line_posx(u->lineno, u->begin); goto_line_posx(u->lineno, u->begin);
cut_marked(); cut_marked();
if (u->cutbuffer != NULL)
free_filestruct(u->cutbuffer); free_filestruct(u->cutbuffer);
u->cutbuffer = cutbuffer; u->cutbuffer = cutbuffer;
u->cutbottom = cutbottom; u->cutbottom = cutbottom;
@ -903,7 +901,6 @@ void discard_until(const undo *thisitem, openfilestruct *thefile)
while (dropit != NULL && dropit != thisitem) { while (dropit != NULL && dropit != thisitem) {
thefile->undotop = dropit->next; thefile->undotop = dropit->next;
free(dropit->strdata); free(dropit->strdata);
if (dropit->cutbuffer != NULL)
free_filestruct(dropit->cutbuffer); free_filestruct(dropit->cutbuffer);
free(dropit); free(dropit);
dropit = thefile->undotop; dropit = thefile->undotop;
@ -1113,7 +1110,6 @@ fprintf(stderr, " >> Updating... action = %d, openfile->last_action = %d, openf
case CUT: case CUT:
if (!cutbuffer) if (!cutbuffer)
break; break;
if (u->cutbuffer)
free_filestruct(u->cutbuffer); free_filestruct(u->cutbuffer);
u->cutbuffer = copy_filestruct(cutbuffer); u->cutbuffer = copy_filestruct(cutbuffer);
if (u->mark_set) { if (u->mark_set) {