diff options
author | raffitz <raf.a.m.c.gon@gmail.com> | 2019-01-14 14:09:47 +0000 |
---|---|---|
committer | Justin M. Keyes <justinkz@gmail.com> | 2019-01-15 00:47:53 +0100 |
commit | 95fa71c6d2b4a2d86bc1e4a984efbd188fab1382 (patch) | |
tree | 349c0133f741a871cdf36c2423254d19d89b57da /src | |
parent | 387ab4f7065c24f178ddb1c90e0378a1ea677314 (diff) | |
download | rneovim-95fa71c6d2b4a2d86bc1e4a984efbd188fab1382.tar.gz rneovim-95fa71c6d2b4a2d86bc1e4a984efbd188fab1382.tar.bz2 rneovim-95fa71c6d2b4a2d86bc1e4a984efbd188fab1382.zip |
:recover : Fix crash on non-existent *.swp #9504
Reverts d2944e6a298e. mf_open() _can_ fail if the file does not exist.
closes #9503
closes #9504
Diffstat (limited to 'src')
-rw-r--r-- | src/nvim/memfile.c | 3 | ||||
-rw-r--r-- | src/nvim/memline.c | 13 | ||||
-rw-r--r-- | src/nvim/spell.c | 2 |
3 files changed, 12 insertions, 6 deletions
diff --git a/src/nvim/memfile.c b/src/nvim/memfile.c index fe4d24ba11..0a16f8aafb 100644 --- a/src/nvim/memfile.c +++ b/src/nvim/memfile.c @@ -76,7 +76,8 @@ /// @param flags Flags for open() call. /// -/// @return The open memory file. +/// @return - The open memory file, on success. +/// - NULL, on failure (e.g. file does not exist). memfile_T *mf_open(char_u *fname, int flags) { memfile_T *mfp = xmalloc(sizeof(memfile_T)); diff --git a/src/nvim/memline.c b/src/nvim/memline.c index 95f3b0c623..4c4f7d65bd 100644 --- a/src/nvim/memline.c +++ b/src/nvim/memline.c @@ -277,6 +277,9 @@ int ml_open(buf_T *buf) // Open the memfile. No swap file is created yet. memfile_T *mfp = mf_open(NULL, 0); + if (mfp == NULL) { + goto error; + } buf->b_ml.ml_mfp = mfp; buf->b_ml.ml_flags = ML_EMPTY; @@ -360,10 +363,12 @@ int ml_open(buf_T *buf) return OK; error: - if (hp) { - mf_put(mfp, hp, false, false); + if (mfp != NULL) { + if (hp) { + mf_put(mfp, hp, false, false); + } + mf_close(mfp, true); // will also xfree(mfp->mf_fname) } - mf_close(mfp, true); // will also xfree(mfp->mf_fname) buf->b_ml.ml_mfp = NULL; return FAIL; } @@ -839,7 +844,7 @@ void ml_recover(void) mf_open() will consume "fname_used"! */ mfp = mf_open(fname_used, O_RDONLY); fname_used = p; - if (mfp->mf_fd < 0) { + if (mfp == NULL || mfp->mf_fd < 0) { EMSG2(_("E306: Cannot open %s"), fname_used); goto theend; } diff --git a/src/nvim/spell.c b/src/nvim/spell.c index a9330e792a..ff61c2e5de 100644 --- a/src/nvim/spell.c +++ b/src/nvim/spell.c @@ -2510,7 +2510,7 @@ buf_T *open_spellbuf(void) buf->b_spell = true; buf->b_p_swf = true; // may create a swap file if (ml_open(buf) == FAIL) { - abort(); + ELOG("Error opening a new memline"); } ml_open_file(buf); // create swap file now |