From 9c3a3e13814c6601271288f4550d5c723ce8b4c3 Mon Sep 17 00:00:00 2001 From: Eliseo Martínez Date: Fri, 7 Nov 2014 20:46:56 +0100 Subject: Fix warnings: ex_cmds.c: do_ascii(): Garbage value (2): MI. Problems : Assigned value is garbage or undefined @ 127. Assigned value is garbage or undefined @ 152. Diagnostic : Multithreading issues. Rationale : Error could only occurr if global `enc_utf8` changed while the function is executing. Resolution : Use local copy of global var. --- src/nvim/ex_cmds.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/nvim/ex_cmds.c b/src/nvim/ex_cmds.c index f5fa16a139..a71ee7a2fe 100644 --- a/src/nvim/ex_cmds.c +++ b/src/nvim/ex_cmds.c @@ -90,8 +90,9 @@ void do_ascii(exarg_T *eap) int cc[MAX_MCO]; int ci = 0; int len; + const bool l_enc_utf8 = enc_utf8; - if (enc_utf8) + if (l_enc_utf8) c = utfc_ptr2char(get_cursor_pos_ptr(), cc); else c = gchar_cursor(); @@ -123,20 +124,20 @@ void do_ascii(exarg_T *eap) vim_snprintf((char *)IObuff, IOSIZE, _("<%s>%s%s %d, Hex %02x, Octal %03o"), transchar(c), buf1, buf2, cval, cval, cval); - if (enc_utf8) + if (l_enc_utf8) c = cc[ci++]; else c = 0; } /* Repeat for combining characters. */ - while (has_mbyte && (c >= 0x100 || (enc_utf8 && c >= 0x80))) { + while (has_mbyte && (c >= 0x100 || (l_enc_utf8 && c >= 0x80))) { len = (int)STRLEN(IObuff); /* This assumes every multi-byte char is printable... */ if (len > 0) IObuff[len++] = ' '; IObuff[len++] = '<'; - if (enc_utf8 && utf_iscomposing(c) + if (l_enc_utf8 && utf_iscomposing(c) # ifdef USE_GUI && !gui.in_use # endif @@ -148,7 +149,7 @@ void do_ascii(exarg_T *eap) : _("> %d, Hex %08x, Octal %o"), c, c, c); if (ci == MAX_MCO) break; - if (enc_utf8) + if (l_enc_utf8) c = cc[ci++]; else c = 0; -- cgit From 3efd39a41b598ea876c2ced322284fad0678bc1d Mon Sep 17 00:00:00 2001 From: Eliseo Martínez Date: Fri, 7 Nov 2014 20:50:41 +0100 Subject: Fix warnings: ex_cmds.c: do_ecmd(): Np dereference: FP. Problem : Dereference of null pointer @ 2768. Diagnostic : False positive. Rationale : `win_valid(oldwin)` implies `oldwin` not null. Resolution : Assert `oldwin` not null. --- src/nvim/ex_cmds.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/nvim/ex_cmds.c b/src/nvim/ex_cmds.c index a71ee7a2fe..ef9affcdf6 100644 --- a/src/nvim/ex_cmds.c +++ b/src/nvim/ex_cmds.c @@ -10,6 +10,7 @@ * ex_cmds.c: some functions for command line commands */ +#include #include #include #include @@ -2765,9 +2766,12 @@ do_ecmd ( /* Autocommands may open a new window and leave oldwin open * which leads to crashes since the above call sets * oldwin->w_buffer to NULL. */ - if (curwin != oldwin && oldwin != aucmd_win - && win_valid(oldwin) && oldwin->w_buffer == NULL) - win_close(oldwin, FALSE); + if (curwin != oldwin && oldwin != aucmd_win && win_valid(oldwin)) { + assert(oldwin); + if (oldwin->w_buffer == NULL) { + win_close(oldwin, FALSE); + } + } if (aborting()) { /* autocmds may abort script processing */ free(new_name); -- cgit From 739124c1b82bb7723f099a7c945e32fe1be9cf87 Mon Sep 17 00:00:00 2001 From: Eliseo Martínez Date: Sat, 8 Nov 2014 09:23:55 +0100 Subject: Fix warnings: ex_cmds2.c: do_source(): Np dereference: FP. Problem : Dereference of null pointer @ 2462. Diagnostic : False positive. Rationale : Error occurred if neither loop neither following if were entered (this implied `script_items.ga_len < 0`, which should not be possible). Resolution : Assert not negative length (loop or if entered). --- src/nvim/ex_cmds2.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/nvim/ex_cmds2.c b/src/nvim/ex_cmds2.c index 6e31142137..28483f9fdf 100644 --- a/src/nvim/ex_cmds2.c +++ b/src/nvim/ex_cmds2.c @@ -10,6 +10,7 @@ * ex_cmds2.c: some more functions for command line commands */ +#include #include #include #include @@ -2422,6 +2423,7 @@ do_source ( save_current_SID = current_SID; FileID file_id; bool file_id_ok = os_fileid((char *)fname_exp, &file_id); + assert(script_items.ga_len >= 0); for (current_SID = script_items.ga_len; current_SID > 0; --current_SID) { si = &SCRIPT_ITEM(current_SID); // Compare dev/ino when possible, it catches symbolic links. -- cgit From 49cf578b76d573ebee2cf7e4f9b398dc64a13025 Mon Sep 17 00:00:00 2001 From: Eliseo Martínez Date: Sat, 8 Nov 2014 09:30:53 +0100 Subject: Fix warnings: ex_cmds2.c: do_source(): Unitialized arg (2): MI. Problem : Uninitialized argument value @ 2485. Uninitialized argument value @ 2507. Diagnostic : Multithreading issues. Rationale : Error can only occur if globals `do_profiling`, `time_fd` are modified while function is executing. Resolution : Use local copy of globals. --- src/nvim/ex_cmds2.c | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/src/nvim/ex_cmds2.c b/src/nvim/ex_cmds2.c index 28483f9fdf..1636d62c74 100644 --- a/src/nvim/ex_cmds2.c +++ b/src/nvim/ex_cmds2.c @@ -2405,11 +2405,13 @@ do_source ( // time_fd was successfully opened afterwards. proftime_T rel_time; proftime_T start_time; - if (time_fd != NULL) { + FILE * const l_time_fd = time_fd; + if (l_time_fd != NULL) { time_push(&rel_time, &start_time); } - if (do_profiling == PROF_YES) + const int l_do_profiling = do_profiling; + if (l_do_profiling == PROF_YES) prof_child_enter(&wait_start); /* entering a child now */ /* Don't use local function variables, if called from a function. @@ -2457,7 +2459,7 @@ do_source ( new_script_vars(current_SID); } - if (do_profiling == PROF_YES) { + if (l_do_profiling == PROF_YES) { int forceit; /* Check if we do profiling for this script. */ @@ -2479,7 +2481,7 @@ do_source ( DOCMD_VERBOSE|DOCMD_NOWAIT|DOCMD_REPEAT); retval = OK; - if (do_profiling == PROF_YES) { + if (l_do_profiling == PROF_YES) { /* Get "si" again, "script_items" may have been reallocated. */ si = &SCRIPT_ITEM(current_SID); if (si->sn_prof_on) { @@ -2503,7 +2505,7 @@ do_source ( verbose_leave(); } - if (time_fd != NULL) { + if (l_time_fd != NULL) { vim_snprintf((char *)IObuff, IOSIZE, "sourcing %s", fname); time_msg((char *)IObuff, &start_time); time_pop(rel_time); @@ -2519,7 +2521,7 @@ do_source ( current_SID = save_current_SID; restore_funccal(save_funccalp); - if (do_profiling == PROF_YES) + if (l_do_profiling == PROF_YES) prof_child_exit(&wait_start); /* leaving a child now */ fclose(cookie.fp); free(cookie.nextline); -- cgit From 1575642b11a48005563b9fc993325ed6e50d5488 Mon Sep 17 00:00:00 2001 From: Eliseo Martínez Date: Sat, 8 Nov 2014 11:33:36 +0100 Subject: Fix warnings: ex_docmd.c: eval_vars(): Unitialized arg: FP. Problem : Uninitialized argument value @ 7704. Diagnostic : False positive. Rationale : Error occurs if `switch(spec_idx)` doesn't enter any case, which should not occur after `spec_idx = find_cmdline_var(...)` returned non-negative. Resolution : Add default clause to switch and error if reached. --- src/nvim/ex_docmd.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/nvim/ex_docmd.c b/src/nvim/ex_docmd.c index 21c877e2b9..67c346237c 100644 --- a/src/nvim/ex_docmd.c +++ b/src/nvim/ex_docmd.c @@ -7699,6 +7699,10 @@ eval_vars ( sprintf((char *)strbuf, "%" PRId64, (int64_t)sourcing_lnum); result = strbuf; break; + default: + // should not happen + *errormsg = (char_u *)""; + return NULL; } resultlen = (int)STRLEN(result); /* length of new string */ -- cgit From ea1f883b199e957134bcb115184280e7122cadbb Mon Sep 17 00:00:00 2001 From: Eliseo Martínez Date: Sat, 8 Nov 2014 13:04:35 +0100 Subject: Fix warnings: ex_eval.c: report_pending(): Np dereference: FP. Problem : Dereference of null pointer @ 711. Diagnostic : False positive. Rationale : Codepath producing error invokes this function with values `action=RPC_DISCARD, pending=CSTP_FINISH, value=NULL`. Now, for some reason, the analyzer is remembering that `value` is null, and that `action` is `RPC_DISCARD`, but it's not remembering that `pending` is `CSTP_FINISH`. Then, it's taking the wrong branch in the switch for `pending`. That path would never occur invocating the function with those values. Resolution : Assert function precondition between `pending` and `value`. This is, let the compiler know that `value` being null implies `pending` not containing `CSTP_THROW`. --- src/nvim/ex_eval.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/nvim/ex_eval.c b/src/nvim/ex_eval.c index 3e1672c2e7..fba0b93253 100644 --- a/src/nvim/ex_eval.c +++ b/src/nvim/ex_eval.c @@ -9,8 +9,8 @@ /* * ex_eval.c: functions for Ex command line for the +eval feature. */ +#include #include - #include #include "nvim/vim.h" @@ -670,6 +670,7 @@ static void report_pending(int action, int pending, void *value) char *s; int save_msg_silent; + assert(value || !(pending & CSTP_THROW)); switch (action) { case RP_MAKE: -- cgit From d6472f459bc531bf6e24c3bcc1916dba16ba1f10 Mon Sep 17 00:00:00 2001 From: Eliseo Martínez Date: Sat, 8 Nov 2014 21:14:33 +0100 Subject: Fix warnings: ex_getln.c: init_history(): Double free: FP. Problem : Double free @ 4249. Diagnostic : False positive. Rationale : Codepath leading to error contains two consecutive iterations in which `if (--j < 0)` is true. That executes `free` two consecutive times with the same value (hislen - 1) for j, with leads to double free. Now, that can only happen with j == 0 && hislen == 1. And that would imply j == hisidx[type] too, which would take the following break. So, the error codepath cannot really happen, but the compiler cannot deduce the last implication. Resolution : We have two possible solutions for this: 1.- Comparing value of j before and after updating it, and breaking out of iteration if equal. That changes nothing in functionality, but teaches the compiler his proposed error codepath is impossible. 2.- Nullify pointer after freeing. This way, the compiler still thinks his error codepath is possible, but it's not an error anymore, as free(NULL) is a no-op. We opt for solution 2, as solution 1 requires adding logic that adds nothing (and having to explain that clearly in aside comments) just for the purpose of silencing warning. On the other hand, solution 2 improves the code, adding something considered good practice in any case, and therefore doesn't require further explanation. --- src/nvim/ex_getln.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/nvim/ex_getln.c b/src/nvim/ex_getln.c index b8d8837092..5feff4d456 100644 --- a/src/nvim/ex_getln.c +++ b/src/nvim/ex_getln.c @@ -4245,8 +4245,10 @@ void init_history(void) for (i = newlen - 1;; --i) { if (i >= 0) /* copy newest entries */ temp[i] = history[type][j]; - else /* remove older entries */ + else { /* remove older entries */ free(history[type][j].hisstr); + history[type][j].hisstr = NULL; + } if (--j < 0) j = hislen - 1; if (j == hisidx[type]) -- cgit From 1002e3fe1ddb1d95c838197dc802c3b1ba094bd3 Mon Sep 17 00:00:00 2001 From: Eliseo Martínez Date: Sun, 9 Nov 2014 09:33:48 +0100 Subject: Fix warnings: fold.c: get_foldtext(): Np dereference: FP. Problem : Dereference of null pointer @ 1701. Diagnostic : False positive. Rationale : Comparison `last_wp != wp` just after initializing `last_wp` to NULL makes the compiler think `wp` can be null. Error appears then on codepath assuming comparison is false (i.e. `wp` is null). Resolution : Change order of OR clauses. That seems not to give motives for the analyzer to check the `wp` null path and removes the warning. But potential null dereference is still there, so we add the nonnull annotation to `wp` parameter. --- src/nvim/fold.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/nvim/fold.c b/src/nvim/fold.c index 95f1e054b9..6014dbfd15 100644 --- a/src/nvim/fold.c +++ b/src/nvim/fold.c @@ -22,6 +22,7 @@ #include "nvim/diff.h" #include "nvim/eval.h" #include "nvim/ex_docmd.h" +#include "nvim/func_attr.h" #include "nvim/indent.h" #include "nvim/mark.h" #include "nvim/memline.h" @@ -1680,7 +1681,9 @@ static void foldDelMarker(linenr_T lnum, char_u *marker, int markerlen) * When 'foldtext' isn't set puts the result in "buf[51]". Otherwise the * result is in allocated memory. */ -char_u *get_foldtext(win_T *wp, linenr_T lnum, linenr_T lnume, foldinfo_T *foldinfo, char_u *buf) +char_u *get_foldtext(win_T *wp, linenr_T lnum, linenr_T lnume, + foldinfo_T *foldinfo, char_u *buf) + FUNC_ATTR_NONNULL_ARG(1) { char_u *text = NULL; /* an error occurred when evaluating 'fdt' setting */ @@ -1689,8 +1692,7 @@ char_u *get_foldtext(win_T *wp, linenr_T lnum, linenr_T lnume, foldinfo_T *foldi static win_T *last_wp = NULL; static linenr_T last_lnum = 0; - if (last_wp != wp || last_wp == NULL - || last_lnum > lnum || last_lnum == 0) + if (last_wp == NULL || last_wp != wp || last_lnum > lnum || last_lnum == 0) /* window changed, try evaluating foldtext setting once again */ got_fdt_error = FALSE; -- cgit From 4e02a1bf46995e784ea6f7688113a02a8dd3f8ed Mon Sep 17 00:00:00 2001 From: Eliseo Martínez Date: Mon, 10 Nov 2014 00:03:47 +0100 Subject: Fix warnings: fileio.c: readfile(): Dead assignment: HI. Problem : Dead assignment @ 1754. Diagnostic : Harmless issue. Rationale : It's true `iconv_fd` is not going to be used again (we are in the failure handler). But what is being done (assigning sentinel value to mark as "empty" after destroying) is in fact good practice, which could turn significant if more code is added later on. So, we don't want to remove this. Resolution : Leave it there, but exclude from analysis. --- src/nvim/fileio.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/nvim/fileio.c b/src/nvim/fileio.c index ecc05a9faa..16431d14c3 100644 --- a/src/nvim/fileio.c +++ b/src/nvim/fileio.c @@ -1751,7 +1751,9 @@ failed: # ifdef USE_ICONV if (iconv_fd != (iconv_t)-1) { iconv_close(iconv_fd); +# ifndef __clang_analyzer__ iconv_fd = (iconv_t)-1; +# endif } # endif -- cgit From 6d057a2ca53f295f2db9a89b924f904128e4ce34 Mon Sep 17 00:00:00 2001 From: Eliseo Martínez Date: Mon, 10 Nov 2014 00:15:24 +0100 Subject: Fix warnings: fileio.c: aucmd_prepbuf(): Np dereference: FP. Problem : Dereference of null pointer @ 6219. Diagnostic : False positive. Rationale : Problem occurs if `aucmd_win` is NULL after `win_alloc_aucmd_win()`, which cannot happen since it uses new memory functions. So, this is a leftover since OOM refactorization. Resolution : Remove dead code. --- src/nvim/fileio.c | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/src/nvim/fileio.c b/src/nvim/fileio.c index 16431d14c3..05a0a59874 100644 --- a/src/nvim/fileio.c +++ b/src/nvim/fileio.c @@ -6191,12 +6191,9 @@ aucmd_prepbuf ( } } - /* Allocate "aucmd_win" when needed. If this fails (out of memory) fall - * back to using the current window. */ + /* Allocate "aucmd_win" when needed. */ if (win == NULL && aucmd_win == NULL) { win_alloc_aucmd_win(); - if (aucmd_win == NULL) - win = curwin; } if (win == NULL && aucmd_win_used) /* Strange recursive autocommand, fall back to using the current -- cgit From 51080737df84c3ef4f8c17fb004c93b7d7a2850a Mon Sep 17 00:00:00 2001 From: Eliseo Martínez Date: Mon, 10 Nov 2014 11:18:27 +0100 Subject: Fix warnings: hardcopy.c: mch_print_text_out(): Bad free: FP + RI. Problem : Bad free @ 3058. Diagnostic : False positive uncovering a real issue. Rationale : Signaled error occurs if p gets assigned `(char_u*)""` at line 3009 and then is freed at line 3058. But that cannot happen because of the last guard condition before `free` (`*p != NUL`). So, signaled error is a false positive. Now, examining this code more carefully reveals a real issue: not freeing an empty string may not be always correct, as an empty (but allocated) string could also be returned in `p = string_convert(&prt_conv, p, &len);` if passed '&len' points to 0). Which would in fact be a memory leak. Resolution : Remove the exceptional case. Make p always point to allocated memory, and always free it, when `prt_do_conv` is on. --- src/nvim/hardcopy.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/nvim/hardcopy.c b/src/nvim/hardcopy.c index c6354d6c5f..2ef35fdac6 100644 --- a/src/nvim/hardcopy.c +++ b/src/nvim/hardcopy.c @@ -3006,7 +3006,7 @@ int mch_print_text_out(char_u *p, int len) /* Convert from multi-byte to 8-bit encoding */ p = string_convert(&prt_conv, p, &len); if (p == NULL) - p = (char_u *)""; + p = (char_u *)xstrdup(""); } if (prt_out_mbyte) { @@ -3054,7 +3054,7 @@ int mch_print_text_out(char_u *p, int len) } /* Need to free any translated characters */ - if (prt_do_conv && (*p != NUL)) + if (prt_do_conv) free(p); prt_text_run += char_width; -- cgit From 8bb2c2c0742c57150655e18cf8418a758cebdce8 Mon Sep 17 00:00:00 2001 From: Eliseo Martínez Date: Mon, 10 Nov 2014 14:37:31 +0100 Subject: Fix warnings: memory.c: xcalloc(): 0 size calloc: CW. Problem : Undefined allocation of 0 bytes (CERT MEM04-C; CWE-131) @ 148. Diagnostic : Cautionary warning. Rationale : Reported circumstance (calling calloc with requesting 0 size allocation) can occur, and it's not an issue. It's perfectly legal doing so, though result is implementation dependant. A given implementation can return NULL or a valid pointer, so that free() can be called on it later the same as if it was a real pointer. Such a pointer should not be dereferenced, though. Now, for some reason I can't explain, compiler is warning us in the case of calloc, but not in the case of malloc, which is doing the same. Resolution : Refactor memory functions to avoid using implementation dependant behaviour. Proposed code is neater to read, and it avoids calling system memory functions with size 0, thus behaving the same everywhere. Note that semantics for xmalloc/xcalloc is slightly changed: - Previously, an implementation that returns a valid pointer on malloc/calloc with 0 size, would return that pointer to xmalloc/xcalloc caller. - Currently, a regular pointer is always returned. --- src/nvim/memory.c | 35 ++++++----------------------------- 1 file changed, 6 insertions(+), 29 deletions(-) diff --git a/src/nvim/memory.c b/src/nvim/memory.c index 4b24213ecd..0e7f8a9071 100644 --- a/src/nvim/memory.c +++ b/src/nvim/memory.c @@ -78,17 +78,11 @@ static void try_to_free_memory(void) /// @return pointer to allocated space. NULL if out of memory void *try_malloc(size_t size) FUNC_ATTR_MALLOC FUNC_ATTR_ALLOC_SIZE(1) { + size = size ? size : 1; void *ret = malloc(size); - - if (!ret && !size) { - ret = malloc(1); - } if (!ret) { try_to_free_memory(); ret = malloc(size); - if (!ret && !size) { - ret = malloc(1); - } } return ret; } @@ -120,7 +114,6 @@ void *xmalloc(size_t size) FUNC_ATTR_MALLOC FUNC_ATTR_ALLOC_SIZE(1) FUNC_ATTR_NONNULL_RET { void *ret = try_malloc(size); - if (!ret) { OUT_STR(e_outofmem); out_char('\n'); @@ -138,23 +131,16 @@ void *xmalloc(size_t size) void *xcalloc(size_t count, size_t size) FUNC_ATTR_MALLOC FUNC_ATTR_ALLOC_SIZE_PROD(1, 2) FUNC_ATTR_NONNULL_RET { - void *ret = calloc(count, size); - - if (!ret && (!count || !size)) - ret = calloc(1, 1); - + void *ret = count && size ? calloc(count, size) : calloc(1, 1); if (!ret) { try_to_free_memory(); - ret = calloc(count, size); - if (!ret && (!count || !size)) - ret = calloc(1, 1); + ret = count && size ? calloc(count, size) : calloc(1, 1); if (!ret) { OUT_STR(e_outofmem); out_char('\n'); preserve_exit(); } } - return ret; } @@ -166,23 +152,16 @@ void *xcalloc(size_t count, size_t size) void *xrealloc(void *ptr, size_t size) FUNC_ATTR_WARN_UNUSED_RESULT FUNC_ATTR_ALLOC_SIZE(2) FUNC_ATTR_NONNULL_RET { - void *ret = realloc(ptr, size); - - if (!ret && !size) - ret = realloc(ptr, 1); - + void *ret = size ? realloc(ptr, size) : realloc(ptr, 1); if (!ret) { try_to_free_memory(); - ret = realloc(ptr, size); - if (!ret && !size) - ret = realloc(ptr, 1); + ret = size ? realloc(ptr, size) : realloc(ptr, 1); if (!ret) { OUT_STR(e_outofmem); out_char('\n'); preserve_exit(); } } - return ret; } @@ -195,14 +174,12 @@ void *xmallocz(size_t size) FUNC_ATTR_MALLOC FUNC_ATTR_NONNULL_RET FUNC_ATTR_WARN_UNUSED_RESULT { size_t total_size = size + 1; - void *ret; - if (total_size < size) { OUT_STR(_("Vim: Data too large to fit into virtual memory space\n")); preserve_exit(); } - ret = xmalloc(total_size); + void *ret = xmalloc(total_size); ((char*)ret)[size] = 0; return ret; -- cgit From 5bf6639e0fb5698a436efe5105fa5dc8714f67dc Mon Sep 17 00:00:00 2001 From: Eliseo Martínez Date: Mon, 10 Nov 2014 17:23:34 +0100 Subject: Fix warnings: message.c: delete_first_msg(): Np dereference: FP. Problem : Dereference of null pointer @ 693. Diagnostic : False positive. Rationale : Error condition occurs if `delete_first_msg` is entered two consecutive times, the firt of which sets leaves history empty. But, in that case, second entrance should leave at the `return FAIL`, and thus cannot reach the pointer dereference. Resolution : Assert history will be empty after first entrance. --- src/nvim/message.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/nvim/message.c b/src/nvim/message.c index 58dbee8cf9..0e287268eb 100644 --- a/src/nvim/message.c +++ b/src/nvim/message.c @@ -12,6 +12,7 @@ #define MESSAGE_FILE /* don't include prototype for smsg() */ +#include #include #include #include @@ -691,8 +692,10 @@ int delete_first_msg(void) return FAIL; p = first_msg_hist; first_msg_hist = p->next; - if (first_msg_hist == NULL) - last_msg_hist = NULL; /* history is empty */ + if (first_msg_hist == NULL) { /* history is becoming empty */ + assert(msg_hist_len == 1); + last_msg_hist = NULL; + } free(p->msg); free(p); --msg_hist_len; -- cgit From a6548e4fb34d50fbd49d0878618c3aecefabe79b Mon Sep 17 00:00:00 2001 From: Eliseo Martínez Date: Mon, 10 Nov 2014 18:00:46 +0100 Subject: Fix warnings: message.c: vim_vsnprintf(): Dead assignment (2): HI. Problem : Dead assignment @ 3323. Dead assignment @ 3587. Diagnostic : Harmless issues. Rationale : - 3323: Assignment is in fact dead. But, in addition to that, `length_modifier` is assigned default value `\0` when declared and is untouched in path leading to signaled point. So, maintaining assignment adds nothing to code. - 3587: Assignment is in fact dead. It could be thought that `precision_specified` has to be 1 in order to flag `precision` as having a valid value. But that doesn't seem to be the case, as there are places in the code where `precision` gets assigned a default value, even if `precision_specified` is 0. So, maintaining assignment adds nothing to code. Resolution : Remove dead assignments. --- src/nvim/message.c | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/nvim/message.c b/src/nvim/message.c index 0e287268eb..ee83fd371e 100644 --- a/src/nvim/message.c +++ b/src/nvim/message.c @@ -3323,7 +3323,6 @@ int vim_vsnprintf(char *str, size_t str_m, char *fmt, va_list ap, typval_T *tvs) case 'c': case 's': case 'S': - length_modifier = '\0'; str_arg_l = 1; switch (fmt_spec) { case '%': @@ -3587,7 +3586,6 @@ int vim_vsnprintf(char *str, size_t str_m, char *fmt, va_list ap, typval_T *tvs) * zero value is formatted with an * explicit precision of zero */ precision = num_of_digits + 1; - precision_specified = 1; } } /* zero padding to specified precision? */ -- cgit