From 5bf94259c1c5f763c2dd3f102f984a87928e663a Mon Sep 17 00:00:00 2001 From: Jan Edmund Lazo Date: Thu, 1 Apr 2021 20:58:03 -0400 Subject: clang/'Logic error': set vcol in do_put() --- src/nvim/ops.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src') diff --git a/src/nvim/ops.c b/src/nvim/ops.c index 2d351f4dba..2cd71f2360 100644 --- a/src/nvim/ops.c +++ b/src/nvim/ops.c @@ -2807,7 +2807,7 @@ void do_put(int regname, yankreg_T *reg, int dir, long count, int flags) size_t y_size; size_t oldlen; int y_width = 0; - colnr_T vcol; + colnr_T vcol = 0; int delcount; int incr = 0; struct block_def bd; -- cgit From ba3d626efb37fbd704c69eeea0fb6568fb53c7bf Mon Sep 17 00:00:00 2001 From: Jan Edmund Lazo Date: Thu, 1 Apr 2021 21:03:05 -0400 Subject: clang/'Logic error': avoid nullptr deref mouse_find_win() can return NULL. --- src/nvim/mouse.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src') diff --git a/src/nvim/mouse.c b/src/nvim/mouse.c index fa9787a3ac..4c0339e5f4 100644 --- a/src/nvim/mouse.c +++ b/src/nvim/mouse.c @@ -748,7 +748,7 @@ int mouse_check_fold(void) } } - if (mouse_char == wp->w_p_fcs_chars.foldclosed) { + if (wp && mouse_char == wp->w_p_fcs_chars.foldclosed) { return MOUSE_FOLD_OPEN; } else if (mouse_char != ' ') { return MOUSE_FOLD_CLOSE; -- cgit From 484370f2069c78ac902535766ca864a6bd1f58bb Mon Sep 17 00:00:00 2001 From: Jan Edmund Lazo Date: Thu, 1 Apr 2021 21:10:29 -0400 Subject: clang/'Logic error': cmd_source_buffer() requires nonnull param --- src/nvim/ex_cmds2.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/nvim/ex_cmds2.c b/src/nvim/ex_cmds2.c index c4c18c4324..cc0ec71627 100644 --- a/src/nvim/ex_cmds2.c +++ b/src/nvim/ex_cmds2.c @@ -2535,7 +2535,7 @@ void ex_source(exarg_T *eap) static void cmd_source(char_u *fname, exarg_T *eap) { - if (*fname == NUL) { + if (eap != NULL && *fname == NUL) { cmd_source_buffer(eap); } else if (eap != NULL && eap->forceit) { // ":source!": read Normal mode commands @@ -2575,7 +2575,8 @@ static char_u *get_buffer_line(int c, void *cookie, int indent, bool do_concat) return (char_u *)xstrdup((const char *)curr_line); } -static void cmd_source_buffer(exarg_T *eap) +static void cmd_source_buffer(const exarg_T *eap) + FUNC_ATTR_NONNULL_ALL { GetBufferLineCookie cookie = { .curr_lnum = eap->line1, -- cgit From 6d34b0b70279bbd272ce8cee4a3f7706eb5c529e Mon Sep 17 00:00:00 2001 From: Jan Edmund Lazo Date: Thu, 1 Apr 2021 21:22:57 -0400 Subject: clang/'Dead store': do not assign fnamelen Vim hasn't changed this line in buf_modname(). Assigning a value to fnamelen is useless when evaluating strlen() is sufficient for the condition check. --- src/nvim/fileio.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src') diff --git a/src/nvim/fileio.c b/src/nvim/fileio.c index 714bbb5780..65bd809436 100644 --- a/src/nvim/fileio.c +++ b/src/nvim/fileio.c @@ -4280,7 +4280,7 @@ char *modname(const char *fname, const char *ext, bool prepend_dot) if (fname == NULL || *fname == NUL) { retval = xmalloc(MAXPATHL + extlen + 3); // +3 for PATHSEP, "_" (Win), NUL if (os_dirname((char_u *)retval, MAXPATHL) == FAIL - || (fnamelen = strlen(retval)) == 0) { + || strlen(retval) == 0) { xfree(retval); return NULL; } -- cgit From 5bfad093b2fd261f37c77ea9bbff366e3f4af545 Mon Sep 17 00:00:00 2001 From: Jan Edmund Lazo Date: Thu, 1 Apr 2021 21:31:07 -0400 Subject: clang/'Dead store': remove dead assign in msg_may_trunc Evaluating the expression without assignment is enough. --- src/nvim/message.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/nvim/message.c b/src/nvim/message.c index dea6696f55..7c98d3c6b5 100644 --- a/src/nvim/message.c +++ b/src/nvim/message.c @@ -869,18 +869,18 @@ char_u *msg_trunc_attr(char_u *s, int force, int attr) */ char_u *msg_may_trunc(int force, char_u *s) { - int n; int room; room = (int)(Rows - cmdline_row - 1) * Columns + sc_col - 1; if ((force || (shortmess(SHM_TRUNC) && !exmode_active)) - && (n = (int)STRLEN(s) - room) > 0) { + && (int)STRLEN(s) - room > 0) { int size = vim_strsize(s); // There may be room anyway when there are multibyte chars. if (size <= room) { return s; } + int n; for (n = 0; size >= room; ) { size -= utf_ptr2cells(s + n); n += utfc_ptr2len(s + n); -- cgit From 4d396271e1b650f1225ea27240af8616283cfa39 Mon Sep 17 00:00:00 2001 From: Jan Edmund Lazo Date: Fri, 2 Apr 2021 08:27:53 -0400 Subject: clang/API: copy "" if orig_save is NULL orig_save can be NULL if ExpandOne() is misused if ExpandOne() is first called with mode "WILD_CANCEL" or "WILD_APPLY" before other modes. --- src/nvim/ex_getln.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/nvim/ex_getln.c b/src/nvim/ex_getln.c index 76df01c205..38385d19b2 100644 --- a/src/nvim/ex_getln.c +++ b/src/nvim/ex_getln.c @@ -4093,9 +4093,10 @@ ExpandOne ( } if (mode == WILD_CANCEL) { - ss = vim_strsave(orig_save); + ss = vim_strsave(orig_save ? orig_save : (char_u *)""); } else if (mode == WILD_APPLY) { - ss = vim_strsave(findex == -1 ? orig_save : xp->xp_files[findex]); + ss = vim_strsave(findex == -1 ? (orig_save ? orig_save : (char_u *)"") : + xp->xp_files[findex]); } /* free old names */ -- cgit From 49706a1842de8ea07a22244dead32472d1bed768 Mon Sep 17 00:00:00 2001 From: Jan Edmund Lazo Date: Fri, 2 Apr 2021 08:38:37 -0400 Subject: clang/'Logic error': fix loop cond to avoid nullptr deref nvim_set_decoration_provider() has insufficient null checks. --- src/nvim/api/vim.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src') diff --git a/src/nvim/api/vim.c b/src/nvim/api/vim.c index 9dde62f0ee..787b6addc9 100644 --- a/src/nvim/api/vim.c +++ b/src/nvim/api/vim.c @@ -2960,7 +2960,7 @@ void nvim_set_decoration_provider(Integer ns_id, DictionaryOf(LuaRef) opts, String k = opts.items[i].key; Object *v = &opts.items[i].value; size_t j; - for (j = 0; cbs[j].name; j++) { + for (j = 0; cbs[j].name && cbs[j].dest; j++) { if (strequal(cbs[j].name, k.data)) { if (v->type != kObjectTypeLuaRef) { api_set_error(err, kErrorTypeValidation, -- cgit From 4f3396e128b0a1820fbb7f8e138def0322571244 Mon Sep 17 00:00:00 2001 From: Jan Edmund Lazo Date: Fri, 2 Apr 2021 08:43:49 -0400 Subject: clang/'Logic error': assert nonnull p_extra --- src/nvim/screen.c | 1 + 1 file changed, 1 insertion(+) (limited to 'src') diff --git a/src/nvim/screen.c b/src/nvim/screen.c index 760a54a316..5bf5a471c1 100644 --- a/src/nvim/screen.c +++ b/src/nvim/screen.c @@ -3154,6 +3154,7 @@ static int win_line(win_T *wp, linenr_T lnum, int startrow, int endrow, mb_utf8 = false; } } else { + assert(p_extra != NULL); c = *p_extra; mb_c = c; // If the UTF-8 character is more than one byte: -- cgit