mirror of
https://github.com/neovim/neovim.git
synced 2025-02-25 18:55:25 -06:00
Merge #7593 'PVS static analysis fixes'
This commit is contained in:
commit
8c959be511
@ -12,6 +12,7 @@
|
||||
#include "nvim/api/private/handle.h"
|
||||
#include "nvim/msgpack_rpc/helpers.h"
|
||||
#include "nvim/ascii.h"
|
||||
#include "nvim/assert.h"
|
||||
#include "nvim/vim.h"
|
||||
#include "nvim/buffer.h"
|
||||
#include "nvim/window.h"
|
||||
@ -760,12 +761,8 @@ bool object_to_vim(Object obj, typval_T *tv, Error *err)
|
||||
case kObjectTypeWindow:
|
||||
case kObjectTypeTabpage:
|
||||
case kObjectTypeInteger:
|
||||
if (obj.data.integer > VARNUMBER_MAX
|
||||
|| obj.data.integer < VARNUMBER_MIN) {
|
||||
api_set_error(err, kErrorTypeValidation, "Integer value outside range");
|
||||
return false;
|
||||
}
|
||||
|
||||
STATIC_ASSERT(sizeof(obj.data.integer) <= sizeof(varnumber_T),
|
||||
"Integer size must be <= VimL number size");
|
||||
tv->v_type = VAR_NUMBER;
|
||||
tv->vval.v_number = (varnumber_T)obj.data.integer;
|
||||
break;
|
||||
|
@ -1696,7 +1696,7 @@ static void printdigraph(digr_T *dp)
|
||||
}
|
||||
}
|
||||
|
||||
p = buf;
|
||||
p = &buf[0];
|
||||
*p++ = dp->char1;
|
||||
*p++ = dp->char2;
|
||||
*p++ = ' ';
|
||||
|
@ -2206,10 +2206,6 @@ static char_u *get_lval(char_u *const name, typval_T *const rettv,
|
||||
if (len == -1) {
|
||||
// "[key]": get key from "var1"
|
||||
key = (char_u *)tv_get_string(&var1); // is number or string
|
||||
if (key == NULL) {
|
||||
tv_clear(&var1);
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
lp->ll_list = NULL;
|
||||
lp->ll_dict = lp->ll_tv->vval.v_dict;
|
||||
@ -5706,10 +5702,6 @@ static int get_function_args(char_u **argp, char_u endchar, garray_T *newargs,
|
||||
c = *p;
|
||||
*p = NUL;
|
||||
arg = vim_strsave(arg);
|
||||
if (arg == NULL) {
|
||||
*p = c;
|
||||
goto err_ret;
|
||||
}
|
||||
|
||||
// Check for duplicate argument name.
|
||||
for (i = 0; i < newargs->ga_len; i++) {
|
||||
@ -5833,10 +5825,6 @@ static int get_lambda_tv(char_u **arg, typval_T *rettv, bool evaluate)
|
||||
|
||||
fp = (ufunc_T *)xcalloc(1, sizeof(ufunc_T) + STRLEN(name));
|
||||
pt = (partial_T *)xcalloc(1, sizeof(partial_T));
|
||||
if (pt == NULL) {
|
||||
xfree(fp);
|
||||
goto errret;
|
||||
}
|
||||
|
||||
ga_init(&newlines, (int)sizeof(char_u *), 1);
|
||||
ga_grow(&newlines, 1);
|
||||
@ -6222,14 +6210,10 @@ static char_u *fname_trans_sid(const char_u *const name,
|
||||
fname = fname_buf;
|
||||
} else {
|
||||
fname = xmalloc(i + STRLEN(name + llen) + 1);
|
||||
if (fname == NULL) {
|
||||
*error = ERROR_OTHER;
|
||||
} else {
|
||||
*tofree = fname;
|
||||
memmove(fname, fname_buf, (size_t)i);
|
||||
STRCPY(fname + i, name + llen);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
fname = (char_u *)name;
|
||||
}
|
||||
@ -6309,9 +6293,6 @@ call_func(
|
||||
// Make a copy of the name, if it comes from a funcref variable it could
|
||||
// be changed or deleted in the called function.
|
||||
name = vim_strnsave(funcname, len);
|
||||
if (name == NULL) {
|
||||
return ret;
|
||||
}
|
||||
|
||||
fname = fname_trans_sid(name, fname_buf, &tofree, &error);
|
||||
|
||||
@ -7184,8 +7165,7 @@ static void f_bufnr(typval_T *argvars, typval_T *rettv, FunPtr fptr)
|
||||
&& argvars[1].v_type != VAR_UNKNOWN
|
||||
&& tv_get_number_chk(&argvars[1], &error) != 0
|
||||
&& !error
|
||||
&& (name = tv_get_string_chk(&argvars[0])) != NULL
|
||||
&& !error) {
|
||||
&& (name = tv_get_string_chk(&argvars[0])) != NULL) {
|
||||
buf = buflist_new((char_u *)name, NULL, 1, 0);
|
||||
}
|
||||
|
||||
@ -7733,7 +7713,7 @@ static void f_delete(typval_T *argvars, typval_T *rettv, FunPtr fptr)
|
||||
}
|
||||
|
||||
const char *const name = tv_get_string(&argvars[0]);
|
||||
if (name == NULL || *name == NUL) {
|
||||
if (*name == NUL) {
|
||||
EMSG(_(e_invarg));
|
||||
return;
|
||||
}
|
||||
@ -8748,10 +8728,9 @@ static void f_foldtext(typval_T *argvars, typval_T *rettv, FunPtr fptr)
|
||||
foldstart = (linenr_T)get_vim_var_nr(VV_FOLDSTART);
|
||||
foldend = (linenr_T)get_vim_var_nr(VV_FOLDEND);
|
||||
dashes = get_vim_var_str(VV_FOLDDASHES);
|
||||
if (foldstart > 0 && foldend <= curbuf->b_ml.ml_line_count
|
||||
&& dashes != NULL) {
|
||||
/* Find first non-empty line in the fold. */
|
||||
for (lnum = foldstart; lnum < foldend; ++lnum) {
|
||||
if (foldstart > 0 && foldend <= curbuf->b_ml.ml_line_count) {
|
||||
// Find first non-empty line in the fold.
|
||||
for (lnum = foldstart; lnum < foldend; lnum++) {
|
||||
if (!linewhite(lnum)) {
|
||||
break;
|
||||
}
|
||||
@ -8874,10 +8853,8 @@ static void common_function(typval_T *argvars, typval_T *rettv,
|
||||
snprintf(sid_buf, sizeof(sid_buf), "<SNR>%" PRId64 "_",
|
||||
(int64_t)current_SID);
|
||||
name = xmalloc(STRLEN(sid_buf) + STRLEN(s + off) + 1);
|
||||
if (name != NULL) {
|
||||
STRCPY(name, sid_buf);
|
||||
STRCAT(name, s + off);
|
||||
}
|
||||
} else {
|
||||
name = vim_strsave(s);
|
||||
}
|
||||
@ -8927,11 +8904,6 @@ static void common_function(typval_T *argvars, typval_T *rettv,
|
||||
|
||||
pt->pt_argc = arg_len + lv_len;
|
||||
pt->pt_argv = xmalloc(sizeof(pt->pt_argv[0]) * pt->pt_argc);
|
||||
if (pt->pt_argv == NULL) {
|
||||
xfree(pt);
|
||||
xfree(name);
|
||||
goto theend;
|
||||
}
|
||||
int i = 0;
|
||||
for (; i < arg_len; i++) {
|
||||
tv_copy(&arg_pt->pt_argv[i], &pt->pt_argv[i]);
|
||||
@ -9197,9 +9169,7 @@ static void f_getbufinfo(typval_T *argvars, typval_T *rettv, FunPtr fptr)
|
||||
}
|
||||
|
||||
dict_T *const d = get_buffer_info(buf);
|
||||
if (d != NULL) {
|
||||
tv_list_append_dict(rettv->vval.v_list, d);
|
||||
}
|
||||
if (argbuf != NULL) {
|
||||
return;
|
||||
}
|
||||
@ -9568,14 +9538,12 @@ static void f_getcompletion(typval_T *argvars, typval_T *rettv, FunPtr fptr)
|
||||
theend:
|
||||
pat = addstar(xpc.xp_pattern, xpc.xp_pattern_len, xpc.xp_context);
|
||||
tv_list_alloc_ret(rettv);
|
||||
if (pat != NULL) {
|
||||
ExpandOne(&xpc, pat, NULL, options, WILD_ALL_KEEP);
|
||||
|
||||
for (int i = 0; i < xpc.xp_numfiles; i++) {
|
||||
tv_list_append_string(rettv->vval.v_list, (const char *)xpc.xp_files[i],
|
||||
-1);
|
||||
}
|
||||
}
|
||||
xfree(pat);
|
||||
ExpandCleanup(&xpc);
|
||||
}
|
||||
@ -10136,9 +10104,7 @@ static void f_gettabinfo(typval_T *argvars, typval_T *rettv, FunPtr fptr)
|
||||
continue;
|
||||
}
|
||||
dict_T *const d = get_tabpage_info(tp, tpnr);
|
||||
if (d != NULL) {
|
||||
tv_list_append_dict(rettv->vval.v_list, d);
|
||||
}
|
||||
if (tparg != NULL) {
|
||||
return;
|
||||
}
|
||||
@ -10240,9 +10206,7 @@ static void f_getwininfo(typval_T *argvars, typval_T *rettv, FunPtr fptr)
|
||||
}
|
||||
winnr++;
|
||||
dict_T *const d = get_win_info(wp, tabnr, winnr);
|
||||
if (d != NULL) {
|
||||
tv_list_append_dict(rettv->vval.v_list, d);
|
||||
}
|
||||
if (wparg != NULL) {
|
||||
// found information about a specific window
|
||||
return;
|
||||
@ -14803,9 +14767,6 @@ static void f_setmatches(typval_T *argvars, typval_T *rettv, FunPtr fptr)
|
||||
if (di == NULL) {
|
||||
if (s == NULL) {
|
||||
s = tv_list_alloc();
|
||||
if (s == NULL) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
// match from matchaddpos()
|
||||
@ -18628,8 +18589,6 @@ void set_selfdict(typval_T *rettv, dict_T *selfdict)
|
||||
// Turn "dict.Func" into a partial for "Func" with "dict".
|
||||
if (fp != NULL && (fp->uf_flags & FC_DICT)) {
|
||||
partial_T *pt = (partial_T *)xcalloc(1, sizeof(partial_T));
|
||||
|
||||
if (pt != NULL) {
|
||||
pt->pt_refcount = 1;
|
||||
pt->pt_dict = selfdict;
|
||||
(selfdict->dv_refcount)++;
|
||||
@ -18654,22 +18613,16 @@ void set_selfdict(typval_T *rettv, dict_T *selfdict)
|
||||
if (ret_pt->pt_argc > 0) {
|
||||
size_t arg_size = sizeof(typval_T) * ret_pt->pt_argc;
|
||||
pt->pt_argv = (typval_T *)xmalloc(arg_size);
|
||||
if (pt->pt_argv == NULL) {
|
||||
// out of memory: drop the arguments
|
||||
pt->pt_argc = 0;
|
||||
} else {
|
||||
pt->pt_argc = ret_pt->pt_argc;
|
||||
for (i = 0; i < pt->pt_argc; i++) {
|
||||
tv_copy(&ret_pt->pt_argv[i], &pt->pt_argv[i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
partial_unref(ret_pt);
|
||||
}
|
||||
rettv->v_type = VAR_PARTIAL;
|
||||
rettv->vval.v_partial = pt;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Find variable "name" in the list of variables.
|
||||
|
@ -1417,17 +1417,20 @@ void ex_emenu(exarg_T *eap)
|
||||
idx = MENU_INDEX_NORMAL;
|
||||
}
|
||||
|
||||
if (idx != MENU_INDEX_INVALID && menu->strings[idx] != NULL) {
|
||||
/* When executing a script or function execute the commands right now.
|
||||
* Otherwise put them in the typeahead buffer. */
|
||||
if (current_SID != 0)
|
||||
assert(idx != MENU_INDEX_INVALID);
|
||||
if (menu->strings[idx] != NULL) {
|
||||
// When executing a script or function execute the commands right now.
|
||||
// Otherwise put them in the typeahead buffer.
|
||||
if (current_SID != 0) {
|
||||
exec_normal_cmd(menu->strings[idx], menu->noremap[idx],
|
||||
menu->silent[idx]);
|
||||
else
|
||||
ins_typebuf(menu->strings[idx], menu->noremap[idx], 0,
|
||||
TRUE, menu->silent[idx]);
|
||||
} else
|
||||
} else {
|
||||
ins_typebuf(menu->strings[idx], menu->noremap[idx], 0, true,
|
||||
menu->silent[idx]);
|
||||
}
|
||||
} else {
|
||||
EMSG2(_("E335: Menu not defined for %s mode"), mode);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -1989,9 +1989,8 @@ void halfpage(bool flag, linenr_T Prenum)
|
||||
while (n > 0 && curwin->w_botline <= curbuf->b_ml.ml_line_count) {
|
||||
if (curwin->w_topfill > 0) {
|
||||
i = 1;
|
||||
if (--n < 0 && scrolled > 0)
|
||||
break;
|
||||
--curwin->w_topfill;
|
||||
n--;
|
||||
curwin->w_topfill--;
|
||||
} else {
|
||||
i = plines_nofill(curwin->w_topline);
|
||||
n -= i;
|
||||
@ -2067,9 +2066,8 @@ void halfpage(bool flag, linenr_T Prenum)
|
||||
while (n > 0 && curwin->w_topline > 1) {
|
||||
if (curwin->w_topfill < diff_check_fill(curwin, curwin->w_topline)) {
|
||||
i = 1;
|
||||
if (--n < 0 && scrolled > 0)
|
||||
break;
|
||||
++curwin->w_topfill;
|
||||
n--;
|
||||
curwin->w_topfill++;
|
||||
} else {
|
||||
i = plines_nofill(curwin->w_topline - 1);
|
||||
n -= i;
|
||||
|
@ -199,18 +199,25 @@ static void forward_mouse_event(TermInput *input, TermKeyKey *key)
|
||||
len += (size_t)snprintf(buf + len, sizeof(buf) - len, "Right");
|
||||
}
|
||||
|
||||
if (ev == TERMKEY_MOUSE_PRESS) {
|
||||
switch (ev) {
|
||||
case TERMKEY_MOUSE_PRESS:
|
||||
if (button == 4) {
|
||||
len += (size_t)snprintf(buf + len, sizeof(buf) - len, "ScrollWheelUp");
|
||||
} else if (button == 5) {
|
||||
len += (size_t)snprintf(buf + len, sizeof(buf) - len, "ScrollWheelDown");
|
||||
len += (size_t)snprintf(buf + len, sizeof(buf) - len,
|
||||
"ScrollWheelDown");
|
||||
} else {
|
||||
len += (size_t)snprintf(buf + len, sizeof(buf) - len, "Mouse");
|
||||
}
|
||||
} else if (ev == TERMKEY_MOUSE_DRAG) {
|
||||
break;
|
||||
case TERMKEY_MOUSE_DRAG:
|
||||
len += (size_t)snprintf(buf + len, sizeof(buf) - len, "Drag");
|
||||
} else if (ev == TERMKEY_MOUSE_RELEASE) {
|
||||
break;
|
||||
case TERMKEY_MOUSE_RELEASE:
|
||||
len += (size_t)snprintf(buf + len, sizeof(buf) - len, "Release");
|
||||
break;
|
||||
case TERMKEY_MOUSE_UNKNOWN:
|
||||
assert(false);
|
||||
}
|
||||
|
||||
len += (size_t)snprintf(buf + len, sizeof(buf) - len, "><%d,%d>", col, row);
|
||||
|
@ -1644,7 +1644,7 @@ static void flush_buf(UI *ui, bool toggle_cursor)
|
||||
{
|
||||
uv_write_t req;
|
||||
uv_buf_t bufs[3];
|
||||
uv_buf_t *bufp = bufs;
|
||||
uv_buf_t *bufp = &bufs[0];
|
||||
TUIData *data = ui->data;
|
||||
|
||||
if (data->bufpos <= 0 && data->busy == data->is_invisible) {
|
||||
|
Loading…
Reference in New Issue
Block a user