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.master
parent
dc18746cbd
commit
edbc1e5950
|
@ -3073,6 +3073,8 @@ const char *do_alt_speller(char *tempfile_name)
|
||||||
|
|
||||||
/* Go back to the old position. */
|
/* Go back to the old position. */
|
||||||
goto_line_posx(lineno_save, current_x_save);
|
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->current_y = current_y_save;
|
||||||
openfile->placewewant = pww_save;
|
openfile->placewewant = pww_save;
|
||||||
adjust_viewport(STATIONARY);
|
adjust_viewport(STATIONARY);
|
||||||
|
@ -3545,8 +3547,10 @@ void do_formatter(void)
|
||||||
/* Replace the text of the current buffer with the formatted text. */
|
/* Replace the text of the current buffer with the formatted text. */
|
||||||
replace_buffer(temp);
|
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);
|
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->current_y = current_y_save;
|
||||||
openfile->placewewant = pww_save;
|
openfile->placewewant = pww_save;
|
||||||
adjust_viewport(STATIONARY);
|
adjust_viewport(STATIONARY);
|
||||||
|
|
Loading…
Reference in New Issue