From 9b1c9393709a42e6999e4c29f7d0249ae9d8b7be Mon Sep 17 00:00:00 2001 From: Eliseo Martínez Date: Sun, 14 Dec 2014 20:13:31 +0100 Subject: coverity/13695: Unchecked return value: RI. Problem : Unchecked return value (CHECKED_RETURN) @ 8554. Diagnostic : Real issue. Rationale : Other invocations of `do_source` are checked and generate an error message if fail. There seems to be no reason why this particular instance could not fail the same. Resolution : Check invocation and generate error message on failure. --- src/nvim/ex_docmd.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/nvim/ex_docmd.c b/src/nvim/ex_docmd.c index 56c8206d2a..65a0017e20 100644 --- a/src/nvim/ex_docmd.c +++ b/src/nvim/ex_docmd.c @@ -8543,7 +8543,9 @@ static void ex_loadview(exarg_T *eap) fname = get_view_file(*eap->arg); if (fname != NULL) { - do_source(fname, FALSE, DOSO_NONE); + if (do_source(fname, FALSE, DOSO_NONE) == FAIL) { + EMSG2(_(e_notopen), fname); + } free(fname); } } -- cgit From a97f9e9594225f8078847311fd23b7c339b9f6bc Mon Sep 17 00:00:00 2001 From: Eliseo Martínez Date: Sun, 14 Dec 2014 22:19:23 +0100 Subject: coverity/13696: Unchecked return value: RI. Problem : Unchecked return value (CHECKED_RETURN) @ 2644. Diagnostic : Real issue. Rationale : Other `u_save` invocations are checked, and there's no reason to think this invocation could not fail. Resolution : Check and return if failed (other previous checks in the same function just return, without reporting error, so we just do the same). --- src/nvim/ops.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/nvim/ops.c b/src/nvim/ops.c index a6dee2be5b..931b877a95 100644 --- a/src/nvim/ops.c +++ b/src/nvim/ops.c @@ -30,6 +30,7 @@ #include "nvim/fold.h" #include "nvim/getchar.h" #include "nvim/indent.h" +#include "nvim/log.h" #include "nvim/mark.h" #include "nvim/mbyte.h" #include "nvim/memline.h" @@ -2641,7 +2642,10 @@ do_put ( /* Autocommands may be executed when saving lines for undo, which may make * y_array invalid. Start undo now to avoid that. */ - u_save(curwin->w_cursor.lnum, curwin->w_cursor.lnum + 1); + if (u_save(curwin->w_cursor.lnum, curwin->w_cursor.lnum + 1) == FAIL) { + ELOG(_("Failed to save undo information")); + return; + } if (insert_string != NULL) { y_type = MCHAR; -- cgit From 85ee4b83ac9c8b8b1cc804ffcdb694dca51ec792 Mon Sep 17 00:00:00 2001 From: Eliseo Martínez Date: Sun, 14 Dec 2014 22:37:26 +0100 Subject: Passing-by: Fix FALSE/FAIL confusion. FALSE was being used instead of FAIL. They happen to have the same value, so it works the same. But from function comment it's clear it uses the OK/FAIL convention. --- src/nvim/undo.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src') diff --git a/src/nvim/undo.c b/src/nvim/undo.c index 2ab31b6cfd..9a3da5bcdb 100644 --- a/src/nvim/undo.c +++ b/src/nvim/undo.c @@ -230,7 +230,7 @@ int u_save(linenr_T top, linenr_T bot) if (top > curbuf->b_ml.ml_line_count || top >= bot || bot > curbuf->b_ml.ml_line_count + 1) - return FALSE; /* rely on caller to do error messages */ + return FAIL; /* rely on caller to do error messages */ if (top + 2 == bot) u_saveline((linenr_T)(top + 1)); -- cgit From e0b23b3d090f58c772ff0175c38afa1d5e0f1612 Mon Sep 17 00:00:00 2001 From: Eliseo Martínez Date: Tue, 16 Dec 2014 13:37:56 +0100 Subject: coverity/75594: Explicit null dereferenced: RI. Problem : Exlicit null dereferenced (FORWARD NULL) @ 2859. Diagnostic : Real issue. Rationale : Code within `if (!p_bk)` seems to assume `backup` not null at that point, which may not be true. Resolution : Don't enter conditional on null `backup`. --- src/nvim/fileio.c | 32 +++++++++++++++----------------- 1 file changed, 15 insertions(+), 17 deletions(-) (limited to 'src') diff --git a/src/nvim/fileio.c b/src/nvim/fileio.c index 9734ac07f9..9c6d7c96bb 100644 --- a/src/nvim/fileio.c +++ b/src/nvim/fileio.c @@ -2839,27 +2839,25 @@ buf_write ( * Check if backup file already exists. */ if (os_fileinfo((char *)backup, &file_info_new)) { - /* - * Check if backup file is same as original file. - * May happen when modname() gave the same file back (e.g. silly - * link). If we don't check here, we either ruin the file when - * copying or erase it after writing. - */ if (os_fileinfo_id_equal(&file_info_new, &file_info_old)) { + /* + * Backup file is same as original file. + * May happen when modname() gave the same file back (e.g. silly + * link). If we don't check here, we either ruin the file when + * copying or erase it after writing. + */ free(backup); backup = NULL; /* no backup file to delete */ - } - - /* - * If we are not going to keep the backup file, don't - * delete an existing one, try to use another name. - * Change one character, just before the extension. - */ - if (!p_bk) { - wp = backup + STRLEN(backup) - 1 - - STRLEN(backup_ext); - if (wp < backup) /* empty file name ??? */ + } else if (!p_bk) { + /* + * We are not going to keep the backup file, so don't + * delete an existing one, and try to use another name instead. + * Change one character, just before the extension. + */ + wp = backup + STRLEN(backup) - 1 - STRLEN(backup_ext); + if (wp < backup) { /* empty file name ??? */ wp = backup; + } *wp = 'z'; while (*wp > 'a' && os_fileinfo((char *)backup, &file_info_new)) { -- cgit