From d15defeb2f3b964510e0e6013a7efef7613ad26d Mon Sep 17 00:00:00 2001 From: "Justin M. Keyes" Date: Fri, 24 Sep 2021 01:50:07 -0700 Subject: [PATCH 1/6] fix(PVS V507): false positive https://pvs-studio.com/en/docs/warnings/v507/ "Pointer to local array 'sourcing_name_buf' is stored outside the scope of this array. Such a pointer will become invalid." False positive: `sourcing_name = save_sourcing_name` before returning from this scope. --- src/nvim/ex_cmds2.c | 2 +- src/nvim/memory.c | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/src/nvim/ex_cmds2.c b/src/nvim/ex_cmds2.c index d8827f0a3d..1a576bd891 100644 --- a/src/nvim/ex_cmds2.c +++ b/src/nvim/ex_cmds2.c @@ -1950,7 +1950,7 @@ static int source_using_linegetter(void *cookie, LineGetter fgetline, const char snprintf((char *)sourcing_name_buf, sizeof(sourcing_name_buf), "%s called at %s:%" PRIdLINENR, traceback_name, save_sourcing_name, save_sourcing_lnum); - sourcing_name = sourcing_name_buf; + sourcing_name = sourcing_name_buf; // -V507 reassigned below, before return. } sourcing_lnum = 0; diff --git a/src/nvim/memory.c b/src/nvim/memory.c index cc9c047fa0..0f5f4c1e40 100644 --- a/src/nvim/memory.c +++ b/src/nvim/memory.c @@ -170,6 +170,8 @@ void *xrealloc(void *ptr, size_t size) /// xmalloc() wrapper that allocates size + 1 bytes and zeroes the last byte /// +/// Commonly used to allocate strings, e.g. `char *s = xmallocz(len)`. +/// /// @see {xmalloc} /// @param size /// @return pointer to allocated space. Never NULL From 0d59c01a64906bd1e0792193e1d1a31ab25995c4 Mon Sep 17 00:00:00 2001 From: "Justin M. Keyes" Date: Fri, 24 Sep 2021 02:29:49 -0700 Subject: [PATCH 2/6] fix(PVS V576): wrong fprintf() format https://pvs-studio.com/en/docs/warnings/v576/ Before 1bffe66508ff986a61c0e08caddc92b7f3ace81e this was originally "%ld" but that looks like a mistake. At least now, w_height_inner and w_width_inner are just `int`. --- src/nvim/ex_session.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/nvim/ex_session.c b/src/nvim/ex_session.c index 11e8353e3a..4aadd77d45 100644 --- a/src/nvim/ex_session.c +++ b/src/nvim/ex_session.c @@ -450,11 +450,11 @@ static int put_view(FILE *fd, win_T *wp, int add_edit, unsigned *flagp, int curr } } else if (fprintf(fd, "let s:l = %" PRIdLINENR " - ((%" PRIdLINENR - " * winheight(0) + %" PRId64 ") / %" PRId64 ")\n", + " * winheight(0) + %d) / %d)\n", wp->w_cursor.lnum, wp->w_cursor.lnum - wp->w_topline, - (int64_t)(wp->w_height_inner / 2), - (int64_t)wp->w_height_inner) < 0) { + (wp->w_height_inner / 2), + wp->w_height_inner) < 0) { return FAIL; } if (fprintf(fd, From fefd1652e7ffd1e756d2475f970ff2475cdb741f Mon Sep 17 00:00:00 2001 From: "Justin M. Keyes" Date: Fri, 24 Sep 2021 02:43:37 -0700 Subject: [PATCH 3/6] fix(PVS V576): false positive `lower`, `upper` are `varnumber_T`, correctly matched to `PRIdVARNUMBER` format. --- src/nvim/eval.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/nvim/eval.c b/src/nvim/eval.c index ae64732eb9..0b73d6b37f 100644 --- a/src/nvim/eval.c +++ b/src/nvim/eval.c @@ -6193,7 +6193,7 @@ int assert_inrange(typval_T *argvars) char msg[55]; vim_snprintf(msg, sizeof(msg), "range %" PRIdVARNUMBER " - %" PRIdVARNUMBER ",", - lower, upper); + lower, upper); // -V576 fill_assert_error(&ga, &argvars[3], (char_u *)msg, NULL, &argvars[2], ASSERT_INRANGE); assert_error(&ga); From 3c7cef7b08c03b5bebc25d137425ef2cd6ff4472 Mon Sep 17 00:00:00 2001 From: "Justin M. Keyes" Date: Fri, 24 Sep 2021 02:49:59 -0700 Subject: [PATCH 4/6] fix(PVS V681): function call order is undefined https://pvs-studio.com/en/docs/warnings/v681/ --- src/nvim/buffer.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/nvim/buffer.c b/src/nvim/buffer.c index 2b5325a917..c58eb1610e 100644 --- a/src/nvim/buffer.c +++ b/src/nvim/buffer.c @@ -3112,12 +3112,13 @@ void fileinfo(int fullname, // when non-zero print full path (size_t)(IOSIZE - (p - buffer)), true); } + bool dontwrite = bt_dontwrite(curbuf); vim_snprintf_add((char *)buffer, IOSIZE, "\"%s%s%s%s%s%s", curbufIsChanged() ? (shortmess(SHM_MOD) ? " [+]" : _(" [Modified]")) : " ", - (curbuf->b_flags & BF_NOTEDITED) && !bt_dontwrite(curbuf) + (curbuf->b_flags & BF_NOTEDITED) && !dontwrite ? _("[Not edited]") : "", - (curbuf->b_flags & BF_NEW) && !bt_dontwrite(curbuf) + (curbuf->b_flags & BF_NEW) && !dontwrite ? new_file_message() : "", (curbuf->b_flags & BF_READERR) ? _("[Read errors]") : "", From 508fcdadb7f56da9c556727bfa414b5411912255 Mon Sep 17 00:00:00 2001 From: "Justin M. Keyes" Date: Fri, 24 Sep 2021 03:07:05 -0700 Subject: [PATCH 5/6] fix(PVS): disable "typo" warnings V1051, V1074 PVS is worried about typos. Now we need it to stop worrying... Disable these checks entirely, they are all false positives. tui.c:1873 V1074 Boundary between escape sequence and string is unclear. The escape sequence ends with a letter and the next character is also a letter. Check for typos. tui.c:1983 V1074 Boundary between escape sequence and string is unclear. The escape sequence ends with a letter and the next character is also a letter. Check for typos. regexp_nfa.c:6189 V1051 Consider checking for misprints. It's possible that the 'pim->result' should be checked here. screen.c:2928 V1051 Consider checking for misprints. It's possible that the 'vcol_sbr' should be checked here. screen.c:3187 V1051 Consider checking for misprints. It's possible that the 'line_attr' should be checked here. screen.c:3267 V1051 Consider checking for misprints. It's possible that the 'multi_attr' should be checked here. screen.c:4747 V1051 Consider checking for misprints. It's possible that the 'redraw_next' should be checked here. syntax.c:3448 V1051 Consider checking for misprints. It's possible that the 'arg_end' should be checked here. syntax.c:3625 V1051 Consider checking for misprints. It's possible that the 'arg_end' should be checked here. tui.c:1836 V1051 Consider checking for misprints. It's possible that the 'data->unibi_ext.set_cursor_style' should be checked here. tui.c:1863 V1051 Consider checking for misprints. It's possible that the 'data->unibi_ext.set_cursor_style' should be checked here. tui.c:1882 V1051 Consider checking for misprints. It's possible that the 'data->unibi_ext.set_cursor_style' should be checked here. --- scripts/pvscheck.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/pvscheck.sh b/scripts/pvscheck.sh index aa27c94f29..0f8f1ad266 100755 --- a/scripts/pvscheck.sh +++ b/scripts/pvscheck.sh @@ -379,7 +379,7 @@ run_analysis() {( --sourcetree-root . || true rm -rf PVS-studio.{xml,err,tsk,html.d} - local plog_args="PVS-studio.log --srcRoot . --excludedCodes V011,V1042" + local plog_args="PVS-studio.log --srcRoot . --excludedCodes V011,V1042,V1051,V1074" plog-converter $plog_args --renderTypes xml --output PVS-studio.xml plog-converter $plog_args --renderTypes errorfile --output PVS-studio.err plog-converter $plog_args --renderTypes tasklist --output PVS-studio.tsk From 03ed72642ddfe6a603673efdc0998a154e581b88 Mon Sep 17 00:00:00 2001 From: "Justin M. Keyes" Date: Fri, 24 Sep 2021 03:26:31 -0700 Subject: [PATCH 6/6] fix(pvs): Exclude xdiff from analysis ref 088161a9459a ref fbe88ef8f5a4 --- scripts/pvscheck.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/pvscheck.sh b/scripts/pvscheck.sh index 0f8f1ad266..904ff81700 100755 --- a/scripts/pvscheck.sh +++ b/scripts/pvscheck.sh @@ -373,7 +373,7 @@ run_analysis() {( analyze \ --lic-file PVS-Studio.lic \ --threads "$(get_jobs_num)" \ - --exclude-path src/nvim/xdiff \ + --exclude-path src/xdiff \ --output-file PVS-studio.log \ --file build/compile_commands.json \ --sourcetree-root . || true