From 0d7daaad98d5874b345453073f6e21b024ee42d4 Mon Sep 17 00:00:00 2001 From: ZyX Date: Sun, 8 Apr 2018 16:01:19 +0300 Subject: charset,*: Refactor transstr() --- src/nvim/eval.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/nvim/eval.c') diff --git a/src/nvim/eval.c b/src/nvim/eval.c index 7bdfe7c9ee..9a5b508cb4 100644 --- a/src/nvim/eval.c +++ b/src/nvim/eval.c @@ -16090,7 +16090,7 @@ static void f_strridx(typval_T *argvars, typval_T *rettv, FunPtr fptr) static void f_strtrans(typval_T *argvars, typval_T *rettv, FunPtr fptr) { rettv->v_type = VAR_STRING; - rettv->vval.v_string = transstr((char_u *)tv_get_string(&argvars[0])); + rettv->vval.v_string = (char_u *)transstr(tv_get_string(&argvars[0])); } /* -- cgit From 07b67f9eff56ff741484109e4dcea42020c5f750 Mon Sep 17 00:00:00 2001 From: ZyX Date: Tue, 10 Apr 2018 01:01:16 +0300 Subject: eval: Fix PVS/V547: ufunc_T is actually an incomplete type --- src/nvim/eval.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) (limited to 'src/nvim/eval.c') diff --git a/src/nvim/eval.c b/src/nvim/eval.c index 9a5b508cb4..2fe89dba67 100644 --- a/src/nvim/eval.c +++ b/src/nvim/eval.c @@ -5807,8 +5807,8 @@ static int get_lambda_tv(char_u **arg, typval_T *rettv, bool evaluate) lambda_no++; snprintf((char *)name, sizeof(name), "%d", lambda_no); - fp = (ufunc_T *)xcalloc(1, sizeof(ufunc_T) + STRLEN(name)); - pt = (partial_T *)xcalloc(1, sizeof(partial_T)); + fp = xcalloc(1, offsetof(ufunc_T, uf_name) + STRLEN(name) + 1); + pt = xcalloc(1, sizeof(partial_T)); ga_init(&newlines, (int)sizeof(char_u *), 1); ga_grow(&newlines, 1); @@ -20059,7 +20059,7 @@ void ex_function(exarg_T *eap) } } - fp = xcalloc(1, sizeof(ufunc_T) + STRLEN(name)); + fp = xcalloc(1, offsetof(ufunc_T, uf_name) + STRLEN(name) + 1); if (fudi.fd_dict != NULL) { if (fudi.fd_di == NULL) { @@ -20814,8 +20814,9 @@ char_u *get_user_func_name(expand_T *xp, int idx) return (char_u *)""; // don't show dict and lambda functions } - if (STRLEN(fp->uf_name) + 4 >= IOSIZE) - return fp->uf_name; /* prevents overflow */ + if (STRLEN(fp->uf_name) + 4 >= IOSIZE) { + return fp->uf_name; // Prevent overflow. + } cat_func_name(IObuff, fp); if (xp->xp_context != EXPAND_USER_FUNC) { -- cgit From 4d1b3bf317d4827a21d1e4b1aedfacc6e892555b Mon Sep 17 00:00:00 2001 From: ZyX Date: Tue, 10 Apr 2018 01:25:00 +0300 Subject: eval: Fix PVS/V560: unneded check for name_len It is unsigned, zero length would already cause early return and length 1 is checked earlier in the same condition. --- src/nvim/eval.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/nvim/eval.c') diff --git a/src/nvim/eval.c b/src/nvim/eval.c index 2fe89dba67..4b2e95c624 100644 --- a/src/nvim/eval.c +++ b/src/nvim/eval.c @@ -18728,7 +18728,7 @@ static hashtab_T *find_var_ht_dict(const char *name, const size_t name_len, if (name_len == 0) { return NULL; } - if (name_len == 1 || (name_len >= 2 && name[1] != ':')) { + if (name_len == 1 || name[1] != ':') { // name has implicit scope if (name[0] == ':' || name[0] == AUTOLOAD_CHAR) { // The name must not start with a colon or #. -- cgit From 6f19b9f4e19d12aea23ac61c889aa122bc2576eb Mon Sep 17 00:00:00 2001 From: ZyX Date: Tue, 10 Apr 2018 01:34:54 +0300 Subject: eval: Silence PVS/V614: use of potentially uninitialized pointer It is hard to say whether it actually is uninitialized, need to go deeper into regex code. Probably analyzer did not go that far as regmatch for sure would not be initialized up until calling NFA/DFA engine functions, which is to be done by pointer. --- src/nvim/eval.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) (limited to 'src/nvim/eval.c') diff --git a/src/nvim/eval.c b/src/nvim/eval.c index 4b2e95c624..5281e227d6 100644 --- a/src/nvim/eval.c +++ b/src/nvim/eval.c @@ -15627,7 +15627,6 @@ f_spellsuggest_return: static void f_split(typval_T *argvars, typval_T *rettv, FunPtr fptr) { - regmatch_T regmatch; char_u *save_cpo; int match; colnr_T col = 0; @@ -15660,9 +15659,13 @@ static void f_split(typval_T *argvars, typval_T *rettv, FunPtr fptr) return; } - regmatch.regprog = vim_regcomp((char_u *)pat, RE_MAGIC + RE_STRING); + regmatch_T regmatch = { + .regprog = vim_regcomp((char_u *)pat, RE_MAGIC + RE_STRING), + .startp = { NULL }, + .endp = { NULL }, + .rm_ic = false, + }; if (regmatch.regprog != NULL) { - regmatch.rm_ic = FALSE; while (*str != NUL || keepempty) { if (*str == NUL) { match = false; // Empty item at the end. @@ -15681,8 +15684,9 @@ static void f_split(typval_T *argvars, typval_T *rettv, FunPtr fptr) && end < (const char *)regmatch.endp[0])) { tv_list_append_string(rettv->vval.v_list, str, end - str); } - if (!match) + if (!match) { break; + } // Advance to just after the match. if (regmatch.endp[0] > (char_u *)str) { col = 0; -- cgit From f8d574225b61fc4bc0fd52990deda4825f62dc8f Mon Sep 17 00:00:00 2001 From: ZyX Date: Sun, 15 Apr 2018 18:45:12 +0300 Subject: eval: Silence PVS/V547: E882 may be triggered MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit I failed to deduce why analyzer thinks E882 may not be triggered, though conditions for triggering it are strange: it would trigger E882 only in the single case “function returned non-number”. Cases “function thrown exception”, or “built-in sorter encountered error” will neither yield E882 nor stop sort()/uniq(). Note though that searching test code revealed that neither E702 nor E882 are not tested anywhere. --- src/nvim/eval.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/nvim/eval.c') diff --git a/src/nvim/eval.c b/src/nvim/eval.c index 5281e227d6..437a9dacf6 100644 --- a/src/nvim/eval.c +++ b/src/nvim/eval.c @@ -15453,7 +15453,7 @@ static void do_sort_uniq(typval_T *argvars, typval_T *rettv, bool sort) ; li != NULL;) { listitem_T *const prev_li = TV_LIST_ITEM_PREV(l, li); if (item_compare_func_ptr(&prev_li, &li) == 0) { - if (info.item_compare_func_err) { + if (info.item_compare_func_err) { // -V547 EMSG(_("E882: Uniq compare function failed")); break; } -- cgit From 1df9ac1c03f56e98f63ae320f4e48360e8ee0b26 Mon Sep 17 00:00:00 2001 From: ZyX Date: Sun, 15 Apr 2018 18:50:02 +0300 Subject: eval: Fix PVS/V547: skipping is now done using eval0 --- src/nvim/eval.c | 53 ++++++++++++++++++++++------------------------------- 1 file changed, 22 insertions(+), 31 deletions(-) (limited to 'src/nvim/eval.c') diff --git a/src/nvim/eval.c b/src/nvim/eval.c index 437a9dacf6..036caf6e6a 100644 --- a/src/nvim/eval.c +++ b/src/nvim/eval.c @@ -2684,17 +2684,19 @@ void ex_call(exarg_T *eap) tofree = trans_function_name(&arg, eap->skip, TFN_INT, &fudi, &partial); if (fudi.fd_newkey != NULL) { - /* Still need to give an error message for missing key. */ + // Still need to give an error message for missing key. EMSG2(_(e_dictkey), fudi.fd_newkey); xfree(fudi.fd_newkey); } - if (tofree == NULL) + if (tofree == NULL) { return; + } - /* Increase refcount on dictionary, it could get deleted when evaluating - * the arguments. */ - if (fudi.fd_dict != NULL) - ++fudi.fd_dict->dv_refcount; + // Increase refcount on dictionary, it could get deleted when evaluating + // the arguments. + if (fudi.fd_dict != NULL) { + fudi.fd_dict->dv_refcount++; + } // If it is the name of a variable of type VAR_FUNC or VAR_PARTIAL use its // contents. For VAR_PARTIAL get its partial, unless we already have one @@ -2703,8 +2705,8 @@ void ex_call(exarg_T *eap) name = deref_func_name((const char *)tofree, &len, partial != NULL ? NULL : &partial, false); - /* Skip white space to allow ":call func ()". Not good, but required for - * backward compatibility. */ + // Skip white space to allow ":call func ()". Not good, but required for + // backward compatibility. startarg = skipwhite(arg); rettv.v_type = VAR_UNKNOWN; // tv_clear() uses this. @@ -2713,20 +2715,9 @@ void ex_call(exarg_T *eap) goto end; } - /* - * When skipping, evaluate the function once, to find the end of the - * arguments. - * When the function takes a range, this is discovered after the first - * call, and the loop is broken. - */ - if (eap->skip) { - emsg_skip++; - lnum = eap->line2; // Do it once, also with an invalid range. - } else { - lnum = eap->line1; - } + lnum = eap->line1; for (; lnum <= eap->line2; lnum++) { - if (!eap->skip && eap->addr_count > 0) { // -V560 + if (eap->addr_count > 0) { // -V560 curwin->w_cursor.lnum = lnum; curwin->w_cursor.col = 0; curwin->w_cursor.coladd = 0; @@ -2747,27 +2738,27 @@ void ex_call(exarg_T *eap) } tv_clear(&rettv); - if (doesrange || eap->skip) { // -V560 + if (doesrange) { break; } - /* Stop when immediately aborting on error, or when an interrupt - * occurred or an exception was thrown but not caught. - * get_func_tv() returned OK, so that the check for trailing - * characters below is executed. */ - if (aborting()) + // Stop when immediately aborting on error, or when an interrupt + // occurred or an exception was thrown but not caught. + // get_func_tv() returned OK, so that the check for trailing + // characters below is executed. + if (aborting()) { break; + } } - if (eap->skip) - --emsg_skip; if (!failed) { - /* Check for trailing illegal characters and a following command. */ + // Check for trailing illegal characters and a following command. if (!ends_excmd(*arg)) { emsg_severe = TRUE; EMSG(_(e_trailing)); - } else + } else { eap->nextcmd = check_nextcmd(arg); + } } end: -- cgit From 17e21eae24ff001eae0a74e252acab5992adb5dc Mon Sep 17 00:00:00 2001 From: ZyX Date: Sun, 15 Apr 2018 20:05:17 +0300 Subject: eval: Silence PVS/V547: PVS cannot stand `!known_val` expressions --- src/nvim/eval.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'src/nvim/eval.c') diff --git a/src/nvim/eval.c b/src/nvim/eval.c index 036caf6e6a..e38f7e7dda 100644 --- a/src/nvim/eval.c +++ b/src/nvim/eval.c @@ -2682,7 +2682,7 @@ void ex_call(exarg_T *eap) return; } - tofree = trans_function_name(&arg, eap->skip, TFN_INT, &fudi, &partial); + tofree = trans_function_name(&arg, false, TFN_INT, &fudi, &partial); if (fudi.fd_newkey != NULL) { // Still need to give an error message for missing key. EMSG2(_(e_dictkey), fudi.fd_newkey); @@ -2725,13 +2725,13 @@ void ex_call(exarg_T *eap) arg = startarg; if (get_func_tv(name, (int)STRLEN(name), &rettv, &arg, eap->line1, eap->line2, &doesrange, - !eap->skip, partial, fudi.fd_dict) == FAIL) { + true, partial, fudi.fd_dict) == FAIL) { failed = true; break; } // Handle a function returning a Funcref, Dictionary or List. - if (handle_subscript((const char **)&arg, &rettv, !eap->skip, true) + if (handle_subscript((const char **)&arg, &rettv, true, true) == FAIL) { failed = true; break; -- cgit