]> git.wh0rd.org Git - nano.git/commitdiff
Discarding the entire undo stack, to prevent nano from dying (or
authorBenno Schulenberg <bensberg@justemail.net>
Thu, 3 Dec 2015 09:03:45 +0000 (09:03 +0000)
committerBenno Schulenberg <bensberg@justemail.net>
Thu, 3 Dec 2015 09:03:45 +0000 (09:03 +0000)
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
src/text.c

index 06241bac9a453c47e73d897ec4fa7c51dc9ac936..ca9a572082ac0c0dd89f42017ec8b922c8ff7d30 100644 (file)
--- 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.
index c63d435cb396836f3471b5cbf6979edd60c9dd40..f0fe45ddadbb5533db719c8fc83a29a18920658c 100644 (file)
@@ -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;