nano

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

commit edbc1e5950efd0049570bd915d882690de396a1c
parent dc18746cbdf601f8e4d28113c95896236412f16b
Author: Benno Schulenberg <bensberg@justemail.net>
Date:   Sat, 24 Dec 2016 12:09:47 +0100

text: avoid a crash when a spell-checked line has gotten shorter

When using an external spell checker or formatter, the line with
the cursor might become shorter, which might result in the stored
cursor position being beyond the end-of-line.  So, when restoring
the x position, make sure to limit it to the length of the line.

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

Diffstat:
Msrc/text.c | 6+++++-
1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/src/text.c b/src/text.c @@ -3073,6 +3073,8 @@ const char *do_alt_speller(char *tempfile_name) /* Go back to the old position. */ goto_line_posx(lineno_save, current_x_save); + if (openfile->current_x > strlen(openfile->current->data)) + openfile->current_x = strlen(openfile->current->data); openfile->current_y = current_y_save; openfile->placewewant = pww_save; adjust_viewport(STATIONARY); @@ -3545,8 +3547,10 @@ void do_formatter(void) /* Replace the text of the current buffer with the formatted text. */ replace_buffer(temp); - /* Restore the cursor position, and mark the file as modified. */ + /* Restore the cursor position. */ goto_line_posx(lineno_save, current_x_save); + if (openfile->current_x > strlen(openfile->current->data)) + openfile->current_x = strlen(openfile->current->data); openfile->current_y = current_y_save; openfile->placewewant = pww_save; adjust_viewport(STATIONARY);