Commit edbc1e59 authored by Benno Schulenberg's avatar Benno Schulenberg
Browse files

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.
parent dc18746c
Showing with 5 additions and 1 deletion
+5 -1
......@@ -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);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment