From e75ccc3b3ac7e827d9e7a5661fa34365b32f629f Mon Sep 17 00:00:00 2001 From: Dundar Goc Date: Tue, 17 May 2022 13:40:09 +0200 Subject: [PATCH 1/4] fix(PVS/V1028): prevent potential overflow --- src/nvim/grid.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/nvim/grid.c b/src/nvim/grid.c index 8a5d8081c0..13429994de 100644 --- a/src/nvim/grid.c +++ b/src/nvim/grid.c @@ -63,7 +63,7 @@ void grid_clear_line(ScreenGrid *grid, size_t off, int width, bool valid) void grid_invalidate(ScreenGrid *grid) { - (void)memset(grid->attrs, -1, sizeof(sattr_T) * (size_t)(grid->Rows * grid->Columns)); + (void)memset(grid->attrs, -1, sizeof(sattr_T) * (size_t)grid->Rows * (size_t)grid->Columns); } bool grid_invalid_row(ScreenGrid *grid, int row) From 65f585ce9b68b7d16e8efd70c3c05d453359c1e0 Mon Sep 17 00:00:00 2001 From: Dundar Goc Date: Tue, 17 May 2022 13:44:54 +0200 Subject: [PATCH 2/4] fix(PVS/V547): "expression is always false" Suppress warning in loop.c, the expression can be true if EXITFREE isn't defined. --- src/nvim/event/loop.c | 2 +- src/nvim/ex_docmd.c | 13 ++++++------- 2 files changed, 7 insertions(+), 8 deletions(-) diff --git a/src/nvim/event/loop.c b/src/nvim/event/loop.c index 89fced59c5..d4e20e2f66 100644 --- a/src/nvim/event/loop.c +++ b/src/nvim/event/loop.c @@ -143,7 +143,7 @@ bool loop_close(Loop *loop, bool wait) while (true) { // Run the loop to tickle close-callbacks (which should then free memory). // Use UV_RUN_NOWAIT to avoid a hang. #11820 - uv_run(&loop->uv, didstop ? UV_RUN_DEFAULT : UV_RUN_NOWAIT); + uv_run(&loop->uv, didstop ? UV_RUN_DEFAULT : UV_RUN_NOWAIT); // -V547 if ((uv_loop_close(&loop->uv) != UV_EBUSY) || !wait) { break; } diff --git a/src/nvim/ex_docmd.c b/src/nvim/ex_docmd.c index e845073c12..c271ccdb39 100644 --- a/src/nvim/ex_docmd.c +++ b/src/nvim/ex_docmd.c @@ -1683,14 +1683,13 @@ void execute_cmd(exarg_T *eap, CmdParseInfo *cmdinfo) (eap->argt & EX_BUFUNL) != 0, false, false); eap->addr_count = 1; // Shift each argument by 1 - if (eap->args != NULL) { - for (size_t i = 0; i < eap->argc - 1; i++) { - eap->args[i] = eap->args[i + 1]; - } - // Make the last argument point to the NUL terminator at the end of string - eap->args[eap->argc - 1] = eap->args[eap->argc - 1] + eap->arglens[eap->argc - 1]; - eap->argc -= 1; + for (size_t i = 0; i < eap->argc - 1; i++) { + eap->args[i] = eap->args[i + 1]; } + // Make the last argument point to the NUL terminator at the end of string + eap->args[eap->argc - 1] = eap->args[eap->argc - 1] + eap->arglens[eap->argc - 1]; + eap->argc -= 1; + eap->arg = eap->args[0]; } if (eap->line2 < 0) { // failed From 5084b6fb921778fdf83c7b7274edc72c6a2b0a64 Mon Sep 17 00:00:00 2001 From: Dundar Goc Date: Tue, 17 May 2022 14:04:29 +0200 Subject: [PATCH 3/4] fix(PVS/V568): correct placement of ignore directive --- src/nvim/strings.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/nvim/strings.c b/src/nvim/strings.c index c0c942ffd2..cde2059a9d 100644 --- a/src/nvim/strings.c +++ b/src/nvim/strings.c @@ -634,12 +634,12 @@ static const void *tv_ptr(const typval_T *const tvs, int *const idxp) FUNC_ATTR_NONNULL_ALL FUNC_ATTR_WARN_UNUSED_RESULT { #define OFF(attr) offsetof(union typval_vval_union, attr) - STATIC_ASSERT(OFF(v_string) == OFF(v_list) + STATIC_ASSERT(OFF(v_string) == OFF(v_list) // -V568 && OFF(v_string) == OFF(v_dict) && OFF(v_string) == OFF(v_partial) - && sizeof(tvs[0].vval.v_string) == sizeof(tvs[0].vval.v_list) // -V568 - && sizeof(tvs[0].vval.v_string) == sizeof(tvs[0].vval.v_dict) // -V568 - && sizeof(tvs[0].vval.v_string) == sizeof(tvs[0].vval.v_partial), // -V568 + && sizeof(tvs[0].vval.v_string) == sizeof(tvs[0].vval.v_list) + && sizeof(tvs[0].vval.v_string) == sizeof(tvs[0].vval.v_dict) + && sizeof(tvs[0].vval.v_string) == sizeof(tvs[0].vval.v_partial), "Strings, dictionaries, lists and partials are expected to be pointers, " "so that all three of them can be accessed via v_string"); #undef OFF From 10868dbf893f69070a56ea2193b9962caacef324 Mon Sep 17 00:00:00 2001 From: Dundar Goc Date: Tue, 17 May 2022 14:36:15 +0200 Subject: [PATCH 4/4] fix(PVS/V1044): suppress warning --- test/unit/fixtures/rbuffer.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/unit/fixtures/rbuffer.c b/test/unit/fixtures/rbuffer.c index 3f4062fa18..efa7ab1986 100644 --- a/test/unit/fixtures/rbuffer.c +++ b/test/unit/fixtures/rbuffer.c @@ -15,7 +15,7 @@ void ut_rbuffer_each_read_chunk(RBuffer *buf, each_ptr_cb cb) void ut_rbuffer_each_write_chunk(RBuffer *buf, each_ptr_cb cb) { - RBUFFER_UNTIL_FULL(buf, wptr, wcnt) { + RBUFFER_UNTIL_FULL(buf, wptr, wcnt) { // -V1044 cb(wptr, wcnt); rbuffer_produced(buf, wcnt); }