1
1

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.
Этот коммит содержится в:
Benno Schulenberg 2020-03-01 12:10:21 +01:00
родитель c055e629c7
Коммит 8848ac5a9b

Просмотреть файл

@ -470,6 +470,7 @@ void undo_cut(undostruct *u)
{ {
goto_line_posx(u->tail_lineno, (u->xflags & WAS_WHOLE_LINE) ? 0 : u->tail_x); goto_line_posx(u->tail_lineno, (u->xflags & WAS_WHOLE_LINE) ? 0 : u->tail_x);
if (u->cutbuffer)
copy_from_buffer(u->cutbuffer); copy_from_buffer(u->cutbuffer);
/* If originally the last line was cut too, remove an extra magic line. */ /* If originally the last line was cut too, remove an extra magic line. */
@ -1319,11 +1320,9 @@ void update_undo(undo_type action)
case ZAP: case ZAP:
case CUT_TO_EOF: case CUT_TO_EOF:
case CUT: case CUT:
if (!cutbuffer)
die("Adding empty undo item -- please report a bug\n");
if (u->type == ZAP) if (u->type == ZAP)
u->cutbuffer = cutbuffer; u->cutbuffer = cutbuffer;
else { else if (cutbuffer != NULL) {
free_lines(u->cutbuffer); free_lines(u->cutbuffer);
u->cutbuffer = copy_buffer(cutbuffer); u->cutbuffer = copy_buffer(cutbuffer);
} }