From 8651fefc68abda94607303f3a33836f51124c25b Mon Sep 17 00:00:00 2001 From: Benno Schulenberg Date: Thu, 3 Dec 2015 09:03:45 +0000 Subject: [PATCH] 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 --- ChangeLog | 3 +++ src/text.c | 8 +++++++- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/ChangeLog b/ChangeLog index 06241bac..ca9a5720 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,6 +1,9 @@ 2015-12-03 Benno Schulenberg * 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 * doc/syntax/python.nanorc: Don't colour triple quotes by themselves. diff --git a/src/text.c b/src/text.c index c63d435c..f0fe45dd 100644 --- 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; -- 2.39.5