commit 8651fefc68abda94607303f3a33836f51124c25b
parent ee5cdcbce589ea3eb4cf930d65a360745ede2cc9
Author: Benno Schulenberg <bensberg@justemail.net>
Date: Thu, 3 Dec 2015 09:03:45 +0000
Discarding the entire undo stack, to prevent nano from dying (or
making mistakes) when trying to undo edits after a justification.
This works around Savannah bug #45531.
git-svn-id: svn://svn.savannah.gnu.org/nano/trunk/nano@5473 35c25a1d-7b9e-4130-9fde-d3aeb78583b8
Diffstat:
2 files changed, 10 insertions(+), 1 deletion(-)
diff --git a/ChangeLog b/ChangeLog
@@ -1,6 +1,9 @@
2015-12-03 Benno Schulenberg <bensberg@justemail.net>
* src/text.c (discard_until): Move the trimming of the undo stack
into a separate function, so it can be used elsewhere.
+ * src/text.c (do_justify): Discard the entire undo stack, to prevent
+ nano from dying (or making mistakes) when trying to undo edits after
+ a justification. This works around Savannah bug #45531.
2015-12-02 Benno Schulenberg <bensberg@justemail.net>
* doc/syntax/python.nanorc: Don't colour triple quotes by themselves.
diff --git a/src/text.c b/src/text.c
@@ -912,7 +912,7 @@ void discard_until(undo *thisone)
while (dropit != NULL && dropit != thisone) {
openfile->undotop = dropit->next;
free(dropit->strdata);
- if (dropit->cutbuffer)
+ if (dropit->cutbuffer != NULL)
free_filestruct(dropit->cutbuffer);
free(dropit);
dropit = openfile->undotop;
@@ -2315,8 +2315,14 @@ void do_justify(bool full_justify)
edit_refresh_needed = TRUE;
}
} else {
+ /* Put the keystroke back into the queue. */
unget_kbinput(kbinput, meta_key, func_key);
+ /* Throw away the entire undo stack, to prevent a crash when
+ * the user tries to undo something in the justified text. */
+ discard_until(NULL);
+ openfile->current_undo = NULL;
+
/* Blow away the text in the justify buffer. */
free_filestruct(jusbuffer);
jusbuffer = NULL;