From b44b533ada401f0e468a07272f3b5d10f78bba5a Mon Sep 17 00:00:00 2001 From: Nick Neisen Date: Wed, 16 May 2018 19:17:11 -0600 Subject: coverity/13969: handle u_save() failure Looking at the implementation of u_save suggests that its failure is a normal and expected situation (e.g. if undo isn't allowed for some reason, it will fail). Also (most of) the other calls to u_save() in do_put() return early. --- src/nvim/ops.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'src/nvim') diff --git a/src/nvim/ops.c b/src/nvim/ops.c index b39b139f9b..d874768dfc 100644 --- a/src/nvim/ops.c +++ b/src/nvim/ops.c @@ -2724,7 +2724,9 @@ void do_put(int regname, yankreg_T *reg, int dir, long count, int flags) // So the 'u' command restores cursor position after ".p, save the cursor // position now (though not saving any text). if (command_start_char == 'a') { - u_save(curwin->w_cursor.lnum, curwin->w_cursor.lnum + 1); + if (u_save(curwin->w_cursor.lnum, curwin->w_cursor.lnum + 1) == FAIL) { + return; + } } return; } @@ -2742,7 +2744,6 @@ void do_put(int regname, yankreg_T *reg, int dir, long count, int flags) // Autocommands may be executed when saving lines for undo, which may make // y_array invalid. Start undo now to avoid that. if (u_save(curwin->w_cursor.lnum, curwin->w_cursor.lnum + 1) == FAIL) { - ELOG("Failed to save undo information"); return; } } -- cgit From 32df42549a49124976e1993218cd560833777482 Mon Sep 17 00:00:00 2001 From: Nick Neisen Date: Wed, 16 May 2018 19:17:56 -0600 Subject: coverity/13700: ignore failed win_split() win_split() does EMSG for all failure cases, so we don't need to log it. Easiest thing to do here is ignore the return value (otherwise we need to do some cleanup and might require some refactoring. jumpto_tag() can deal with a failed split, so it's no big deal. --- src/nvim/tag.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/nvim') diff --git a/src/nvim/tag.c b/src/nvim/tag.c index f23465e501..ba2727f0d7 100644 --- a/src/nvim/tag.c +++ b/src/nvim/tag.c @@ -2407,8 +2407,8 @@ jumpto_tag ( /* If it was a CTRL-W CTRL-] command split window now. For ":tab tag" * open a new tab page. */ if (postponed_split || cmdmod.tab != 0) { - win_split(postponed_split > 0 ? postponed_split : 0, - postponed_split_flags); + (void)win_split(postponed_split > 0 ? postponed_split : 0, + postponed_split_flags); RESET_BINDING(curwin); } -- cgit From aea70b4404399d353e1df0bd73ef344f5559843a Mon Sep 17 00:00:00 2001 From: Nick Neisen Date: Wed, 16 May 2018 19:18:35 -0600 Subject: coverity/13709: spell_add_word: handle failed fseek() Check the return status after removing a duplicate word. Add a log for a nonzero return status. --- src/nvim/spellfile.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) (limited to 'src/nvim') diff --git a/src/nvim/spellfile.c b/src/nvim/spellfile.c index dab9a2aacd..b844fd9ab8 100644 --- a/src/nvim/spellfile.c +++ b/src/nvim/spellfile.c @@ -5368,8 +5368,9 @@ spell_add_word ( // doesn't work for all systems, close the file first. fclose(fd); fd = mch_fopen((char *)fname, "r+"); - if (fd == NULL) + if (fd == NULL) { break; + } if (fseek(fd, fpos, SEEK_SET) == 0) { fputc('#', fd); if (undo) { @@ -5378,7 +5379,9 @@ spell_add_word ( len, word, NameBuff); } } - fseek(fd, fpos_next, SEEK_SET); + if (fseek(fd, fpos_next, SEEK_SET) <= 0) { + break; + } } } if (fd != NULL) -- cgit From 189a5f2b959b568ce598c4bf6345c1ec74f9d470 Mon Sep 17 00:00:00 2001 From: Nick Neisen Date: Wed, 16 May 2018 19:17:34 -0600 Subject: coverity/13713: do_pending_operator: handle failed u_save_cursor() --- src/nvim/normal.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'src/nvim') diff --git a/src/nvim/normal.c b/src/nvim/normal.c index e4310de5d8..43e8b6fb3d 100644 --- a/src/nvim/normal.c +++ b/src/nvim/normal.c @@ -1812,7 +1812,10 @@ void do_pending_operator(cmdarg_T *cap, int old_col, bool gui_yank) } else { (void)op_delete(oap); if (oap->motion_type == kMTLineWise && has_format_option(FO_AUTO)) { - u_save_cursor(); // cursor line wasn't saved yet + // cursor line wasn't saved yet + if (u_save_cursor() == FAIL) { + break; + } } auto_format(false, true); } -- cgit From c2d1684e05f62e66e4820c6f86b80f5c9187365f Mon Sep 17 00:00:00 2001 From: Nick Neisen Date: Wed, 16 May 2018 19:18:16 -0600 Subject: coverity/13702: open_spellbuf: handle failed ml_open() --- src/nvim/spell.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'src/nvim') diff --git a/src/nvim/spell.c b/src/nvim/spell.c index 84aeeda2bf..22390557b6 100644 --- a/src/nvim/spell.c +++ b/src/nvim/spell.c @@ -2487,7 +2487,9 @@ buf_T *open_spellbuf(void) buf->b_spell = true; buf->b_p_swf = true; // may create a swap file - ml_open(buf); + if (ml_open(buf) == FAIL) { + ELOG("Error opening a new memline"); + } ml_open_file(buf); // create swap file now return buf; -- cgit From d2944e6a298e824e5084ac0dfd8701ff9cd1a523 Mon Sep 17 00:00:00 2001 From: "Justin M. Keyes" Date: Thu, 17 May 2018 08:16:58 +0200 Subject: mf_open(): never fails (except for OOM) --- src/nvim/memfile.c | 3 +-- src/nvim/memline.c | 18 ++++++------------ src/nvim/spell.c | 2 +- 3 files changed, 8 insertions(+), 15 deletions(-) (limited to 'src/nvim') diff --git a/src/nvim/memfile.c b/src/nvim/memfile.c index f6e03e2532..fe4d24ba11 100644 --- a/src/nvim/memfile.c +++ b/src/nvim/memfile.c @@ -76,8 +76,7 @@ /// @param flags Flags for open() call. /// -/// @return - The open memory file, on success. -/// - NULL, on failure. +/// @return The open memory file. 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 06de9fda67..3b0cac0456 100644 --- a/src/nvim/memline.c +++ b/src/nvim/memline.c @@ -246,7 +246,6 @@ typedef enum { */ int ml_open(buf_T *buf) { - memfile_T *mfp; bhdr_T *hp = NULL; ZERO_BL *b0p; PTR_BL *pp; @@ -275,12 +274,8 @@ int ml_open(buf_T *buf) buf->b_may_swap = false; } - /* - * Open the memfile. No swap file is created yet. - */ - mfp = mf_open(NULL, 0); - if (mfp == NULL) - goto error; + // Open the memfile. No swap file is created yet. + memfile_T *mfp = mf_open(NULL, 0); buf->b_ml.ml_mfp = mfp; buf->b_ml.ml_flags = ML_EMPTY; @@ -364,11 +359,10 @@ int ml_open(buf_T *buf) return OK; error: - if (mfp != NULL) { - if (hp) - mf_put(mfp, hp, false, false); - mf_close(mfp, true); /* will also xfree(mfp->mf_fname) */ + if (hp) { + mf_put(mfp, hp, false, false); } + mf_close(mfp, true); // will also xfree(mfp->mf_fname) buf->b_ml.ml_mfp = NULL; return FAIL; } @@ -842,7 +836,7 @@ void ml_recover(void) mf_open() will consume "fname_used"! */ mfp = mf_open(fname_used, O_RDONLY); fname_used = p; - if (mfp == NULL || mfp->mf_fd < 0) { + if (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 22390557b6..686962704a 100644 --- a/src/nvim/spell.c +++ b/src/nvim/spell.c @@ -2488,7 +2488,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) { - ELOG("Error opening a new memline"); + abort(); } ml_open_file(buf); // create swap file now -- cgit