1
1

speller: don't crash when the spell-checked tempfile cannot be opened

This addresses https://savannah.gnu.org/bugs/?56361.
Этот коммит содержится в:
Benno Schulenberg 2019-05-24 17:22:04 +02:00
родитель b512e253b6
Коммит 9a475bf2d3
3 изменённых файлов: 10 добавлений и 6 удалений

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

@ -498,7 +498,7 @@ bool open_buffer(const char *filename, bool new_buffer)
#ifdef ENABLE_SPELLER
/* Open the specified file, and if that succeeds, remove the text of the marked
* region or of the entire buffer and read the file contents into its place. */
void replace_buffer(const char *filename, undo_type action, bool marked)
bool replace_buffer(const char *filename, undo_type action, bool marked)
{
linestruct *was_cutbuffer = cutbuffer;
int descriptor;
@ -507,7 +507,7 @@ void replace_buffer(const char *filename, undo_type action, bool marked)
descriptor = open_file(filename, FALSE, &f);
if (descriptor < 0)
return;
return FALSE;
#ifndef NANO_TINY
add_undo(COUPLE_BEGIN);
@ -539,6 +539,7 @@ void replace_buffer(const char *filename, undo_type action, bool marked)
add_undo(COUPLE_END);
openfile->undotop->strdata = mallocstrcpy(NULL, _("spelling correction"));
#endif
return TRUE;
}
#endif /* ENABLE_SPELLER */
@ -959,6 +960,7 @@ int open_file(const char *filename, bool newfie, FILE **f)
if (*f == NULL) {
statusline(ALERT, _("Error reading %s: %s"), filename, strerror(errno));
close(fd);
fd = -1;
} else if (!inhelp)
statusbar(_("Reading..."));
}

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

@ -267,7 +267,7 @@ void make_new_buffer(void);
void set_modified(void);
bool open_buffer(const char *filename, bool new_buffer);
#ifdef ENABLE_SPELLER
void replace_buffer(const char *filename, undo_type action, bool marked);
bool replace_buffer(const char *filename, undo_type action, bool marked);
#endif
void prepare_for_display(void);
#ifdef ENABLE_MULTIBUFFER

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

@ -2531,6 +2531,7 @@ const char *do_alt_speller(char *tempfile_name)
size_t pww_save = openfile->placewewant;
ssize_t lineno_save = openfile->current->lineno;
bool was_at_eol = (openfile->current->data[openfile->current_x] == '\0');
bool replaced = FALSE;
struct stat spellfileinfo;
time_t timestamp;
pid_t pid_spell;
@ -2586,7 +2587,7 @@ const char *do_alt_speller(char *tempfile_name)
openfile->mark_x < openfile->current_x));
ssize_t was_mark_lineno = openfile->mark->lineno;
replace_buffer(tempfile_name, CUT, TRUE);
replaced = replace_buffer(tempfile_name, CUT, TRUE);
/* Adjust the end point of the marked region for any change in
* length of the region's last line. */
@ -2599,14 +2600,15 @@ const char *do_alt_speller(char *tempfile_name)
openfile->mark = fsfromline(was_mark_lineno);
} else
#endif
replace_buffer(tempfile_name, CUT_TO_EOF, FALSE);
replaced = replace_buffer(tempfile_name, CUT_TO_EOF, FALSE);
/* Go back to the old position. */
goto_line_posx(lineno_save, current_x_save);
if (was_at_eol || openfile->current_x > strlen(openfile->current->data))
openfile->current_x = strlen(openfile->current->data);
#ifndef NANO_TINY
update_undo(COUPLE_END);
if (replaced)
update_undo(COUPLE_END);
#endif
openfile->placewewant = pww_save;
adjust_viewport(STATIONARY);