2009-07-27 Chris Allegretta <chrisa@asty.org>

* text.c (undo_cut, redo_cut): Don't actually try and undo/redo an empty cut, i.e. the magicline. 
	  Fixes crash on cutting last line discovered by Eitan Adler <eitanadlerlist@gmail.com>.



git-svn-id: svn://svn.savannah.gnu.org/nano/trunk/nano@4397 35c25a1d-7b9e-4130-9fde-d3aeb78583b8
master
Chris Allegretta 2009-07-27 04:16:44 +00:00
parent 0a10e20eec
commit 42726f74cc
2 changed files with 53 additions and 41 deletions

View File

@ -1,3 +1,7 @@
2009-07-27 Chris Allegretta <chrisa@asty.org>
* text.c (undo_cut, redo_cut): Don't actually try and undo/redo an empty cut, i.e. the magicline.
Fixes crash on cutting last line discovered by Eitan Adler <eitanadlerlist@gmail.com>.
2009-07-11 Chris Allegretta <chrisa@asty.org> 2009-07-11 Chris Allegretta <chrisa@asty.org>
* nano-regress: Small tweaks * nano-regress: Small tweaks
* Change undo code to off unless unabled via a command line option (-u/--undo). Until this code * Change undo code to off unless unabled via a command line option (-u/--undo). Until this code

View File

@ -360,21 +360,25 @@ void do_unindent(void)
/* undo a cut, or re-do an uncut */ /* undo a cut, or re-do an uncut */
void undo_cut(undo *u) void undo_cut(undo *u)
{ {
cutbuffer = copy_filestruct(u->cutbuffer); /* If we cut the magicline may was well not crash :/ */
if (!u->cutbuffer)
return;
/* Compute cutbottom for the uncut using out copy */ cutbuffer = copy_filestruct(u->cutbuffer);
for (cutbottom = cutbuffer; cutbottom->next != NULL; cutbottom = cutbottom->next)
;
/* Get to where we need to uncut from */ /* Compute cutbottom for the uncut using out copy */
if (u->mark_set && u->mark_begin_lineno < u->lineno) for (cutbottom = cutbuffer; cutbottom->next != NULL; cutbottom = cutbottom->next)
do_gotolinecolumn(u->mark_begin_lineno, u->mark_begin_x+1, FALSE, FALSE, FALSE, FALSE); ;
else
do_gotolinecolumn(u->lineno, u->begin+1, FALSE, FALSE, FALSE, FALSE);
copy_from_filestruct(cutbuffer, cutbottom); /* Get to where we need to uncut from */
free_filestruct(cutbuffer); if (u->mark_set && u->mark_begin_lineno < u->lineno)
cutbuffer = NULL; do_gotolinecolumn(u->mark_begin_lineno, u->mark_begin_x+1, FALSE, FALSE, FALSE, FALSE);
else
do_gotolinecolumn(u->lineno, u->begin+1, FALSE, FALSE, FALSE, FALSE);
copy_from_filestruct(cutbuffer, cutbottom);
free_filestruct(cutbuffer);
cutbuffer = NULL;
} }
@ -383,40 +387,44 @@ void redo_cut(undo *u) {
int i; int i;
filestruct *t, *c; filestruct *t, *c;
do_gotolinecolumn(u->lineno, u->begin+1, FALSE, FALSE, FALSE, FALSE); /* If we cut the magicline may was well not crash :/ */
openfile->mark_set = u->mark_set; if (!u->cutbuffer)
if (cutbuffer) return;
free(cutbuffer);
cutbuffer = NULL;
/* Move ahead the same # lines we had if a marked cut */ do_gotolinecolumn(u->lineno, u->begin+1, FALSE, FALSE, FALSE, FALSE);
if (u->mark_set) { openfile->mark_set = u->mark_set;
for (i = 1, t = openfile->fileage; i != u->mark_begin_lineno; i++) if (cutbuffer)
t = t->next; free(cutbuffer);
openfile->mark_begin = t; cutbuffer = NULL;
} else if (!u->to_end) {
/* Here we have a regular old potentially multi-line ^K cut. We'll /* Move ahead the same # lines we had if a marked cut */
need to trick nano into thinking it's a marked cut to cut more if (u->mark_set) {
than one line again */ for (i = 1, t = openfile->fileage; i != u->mark_begin_lineno; i++)
for (c = u->cutbuffer, t = openfile->current; c->next != NULL && t->next != NULL; ) { t = t->next;
openfile->mark_begin = t;
} else if (!u->to_end) {
/* Here we have a regular old potentially multi-line ^K cut. We'll
need to trick nano into thinking it's a marked cut to cut more
than one line again */
for (c = u->cutbuffer, t = openfile->current; c->next != NULL && t->next != NULL; ) {
#ifdef DEBUG #ifdef DEBUG
fprintf(stderr, "Advancing, lineno = %d, data = \"%s\"\n", t->lineno, t->data); fprintf(stderr, "Advancing, lineno = %d, data = \"%s\"\n", t->lineno, t->data);
#endif #endif
c = c->next; c = c->next;
t = t->next; t = t->next;
} }
openfile->mark_begin = t; openfile->mark_begin = t;
openfile->mark_begin_x = 0; openfile->mark_begin_x = 0;
openfile->mark_set = TRUE; openfile->mark_set = TRUE;
} }
openfile->mark_begin_x = u->mark_begin_x; openfile->mark_begin_x = u->mark_begin_x;
do_cut_text(FALSE, u->to_end, TRUE); do_cut_text(FALSE, u->to_end, TRUE);
openfile->mark_set = FALSE; openfile->mark_set = FALSE;
openfile->mark_begin = NULL; openfile->mark_begin = NULL;
openfile->mark_begin_x = 0; openfile->mark_begin_x = 0;
edit_refresh_needed = TRUE; edit_refresh_needed = TRUE;
} }
/* Undo the last thing(s) we did */ /* Undo the last thing(s) we did */