nano

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

commit 588022ab8c6aa6bd0f5b42ef081114d063e531a2
parent cf0820549b1573b249f0f0ebb1297a962484ab41
Author: Benno Schulenberg <bensberg@telfort.nl>
Date:   Thu, 22 Apr 2021 19:28:34 +0200

editing: prevent the pointer for the top row from becoming dangling

When undoing several actions, it is possible for the line at the top
of the screen to be removed, leaving 'edittop' pointing to a structure
that has been freed.  Soon after, 'edittop' is referenced to determine
whether the cursor is offscreen...  Prevent this invalid reference by
stepping 'edittop' one line back in that special case.  This changes
the normal centering behavior of Undo when the cursor goes offscreen,
but... so be it.

When a single node is deleted, it is always possible to step one line
back, because a buffer contains always at least one line (even though
maybe empty), so if the current line could be deleted, there must be
one before it (when at the top of the screen).

This fixes https://savannah.gnu.org/bugs/?60436.

Bug existed since version 2.3.3, commit 60815461,
since undoing does not always center the cursor.

Diffstat:
Msrc/nano.c | 3+++
1 file changed, 3 insertions(+), 0 deletions(-)

diff --git a/src/nano.c b/src/nano.c @@ -99,6 +99,9 @@ void splice_node(linestruct *afterthis, linestruct *newnode) /* Free the data structures in the given node. */ void delete_node(linestruct *line) { + /* If the first line on the screen gets deleted, step one back. */ + if (line == openfile->edittop) + openfile->edittop = line->prev; #ifdef ENABLE_WRAPPING /* If the spill-over line for hard-wrapping is deleted... */ if (line == openfile->spillage_line)