From 8848ac5a9b78acde38987dd0071cad0749ac2380 Mon Sep 17 00:00:00 2001 From: Benno Schulenberg Date: Sun, 1 Mar 2020 12:10:21 +0100 Subject: [PATCH] undo: do not try to copy a cutbuffer that is NULL Allow the creation of an empty CUT undo item (because the result of a filtering operation may be empty), but then don't crash when undoing such an empty CUT. This fixes https://savannah.gnu.org/bugs/?57929. Bug existed since version 2.9.8, when filtering was introduced. --- src/text.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/text.c b/src/text.c index f866c698..43e6ee1c 100644 --- a/src/text.c +++ b/src/text.c @@ -470,7 +470,8 @@ void undo_cut(undostruct *u) { goto_line_posx(u->tail_lineno, (u->xflags & WAS_WHOLE_LINE) ? 0 : u->tail_x); - copy_from_buffer(u->cutbuffer); + if (u->cutbuffer) + copy_from_buffer(u->cutbuffer); /* If originally the last line was cut too, remove an extra magic line. */ if ((u->xflags & WAS_FINAL_LINE) && !ISSET(NO_NEWLINES) && @@ -1319,11 +1320,9 @@ void update_undo(undo_type action) case ZAP: case CUT_TO_EOF: case CUT: - if (!cutbuffer) - die("Adding empty undo item -- please report a bug\n"); if (u->type == ZAP) u->cutbuffer = cutbuffer; - else { + else if (cutbuffer != NULL) { free_lines(u->cutbuffer); u->cutbuffer = copy_buffer(cutbuffer); }