From eb2661dc2d7325aa656f3631c41ef7772cc5f88b Mon Sep 17 00:00:00 2001 From: Benno Schulenberg <bensberg@justemail.net> Date: Sun, 17 Apr 2016 17:33:18 +0200 Subject: [PATCH] spelling: if rereading the file fails, don't destroy the current buffer If for some reason opening the spell-checked or formatted file fails, don't throw away the current contents of the buffer. (It should also give proper feedback about the failure, but we'll leave that for some other time.) --- src/files.c | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/src/files.c b/src/files.c index c71763ff..38fdb1b8 100644 --- a/src/files.c +++ b/src/files.c @@ -511,8 +511,8 @@ bool open_buffer(const char *filename, bool undoable) } #ifndef DISABLE_SPELLER -/* Blow away the text of the current buffer, and then open and read - * the specified file into its place. */ +/* Open the specified file, and if that succeeds, blow away the text of + * the current buffer and read the file contents into its place. */ void replace_buffer(const char *filename) { FILE *f; @@ -521,15 +521,18 @@ void replace_buffer(const char *filename) assert(filename != NULL && filename[0] != '\0'); /* Open the file quietly. */ - descriptor = open_file(filename, TRUE, FALSE, &f); + descriptor = open_file(filename, FALSE, TRUE, &f); + + /* If opening failed, forget it. */ + if (descriptor < 0) + return; /* Reinitialize the text of the current buffer. */ free_filestruct(openfile->fileage); initialize_buffer_text(); - /* If opening the file succeeded, read it in. */ - if (descriptor > 0) - read_file(f, descriptor, filename, FALSE, TRUE); + /* Insert the processed file into its place. */ + read_file(f, descriptor, filename, FALSE, TRUE); /* Put current at a place that is certain to exist. */ openfile->current = openfile->fileage; -- GitLab