nano

nano with my custom patches
git clone git://bsandro.tech/nano
Log | Files | Refs | README | LICENSE

commit 8848ac5a9b78acde38987dd0071cad0749ac2380
parent c055e629c75fe3acade3f86abd9a90c12d8ee43a
Author: Benno Schulenberg <bensberg@telfort.nl>
Date:   Sun,  1 Mar 2020 12:10:21 +0100

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.

Diffstat:
Msrc/text.c | 7+++----
1 file changed, 3 insertions(+), 4 deletions(-)

diff --git 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); }