From dc0d021d9fbe5180f6ea7089ad192f4aa9668da3 Mon Sep 17 00:00:00 2001 From: Ihor Antonov Date: Mon, 15 Jul 2019 18:49:20 -0400 Subject: pvs/V1028: cast operands, not the result --- src/nvim/getchar.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) (limited to 'src') diff --git a/src/nvim/getchar.c b/src/nvim/getchar.c index 7efae1e637..9a3a996635 100644 --- a/src/nvim/getchar.c +++ b/src/nvim/getchar.c @@ -15,6 +15,7 @@ #include #include +#include "nvim/assert.h" #include "nvim/vim.h" #include "nvim/ascii.h" #include "nvim/getchar.h" @@ -912,9 +913,10 @@ int ins_typebuf(char_u *str, int noremap, int offset, int nottyped, bool silent) memmove(s1 + newoff + offset, str, (size_t)addlen); /* copy the old chars, after the insertion point, including the NUL at * the end */ + int bytes = typebuf.tb_len - offset + 1; + assert(bytes > 0); memmove(s1 + newoff + offset + addlen, - typebuf.tb_buf + typebuf.tb_off + offset, - (size_t)(typebuf.tb_len - offset + 1)); + typebuf.tb_buf + typebuf.tb_off + offset, (size_t)bytes); if (typebuf.tb_buf != typebuf_init) xfree(typebuf.tb_buf); typebuf.tb_buf = s1; @@ -1063,9 +1065,10 @@ void del_typebuf(int len, int offset) typebuf.tb_off = MAXMAPLEN; } /* adjust typebuf.tb_buf (include the NUL at the end) */ + int bytes = typebuf.tb_len - offset + 1; + assert(bytes > 0); memmove(typebuf.tb_buf + typebuf.tb_off + offset, - typebuf.tb_buf + i + len, - (size_t)(typebuf.tb_len - offset + 1)); + typebuf.tb_buf + i + len, (size_t)bytes); /* adjust typebuf.tb_noremap[] */ memmove(typebuf.tb_noremap + typebuf.tb_off + offset, typebuf.tb_noremap + i + len, -- cgit From 8df20ff56278467211360a71a9139eb76116eaf3 Mon Sep 17 00:00:00 2001 From: Ihor Antonov Date: Mon, 15 Jul 2019 20:02:36 -0400 Subject: lint --- src/nvim/getchar.c | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) (limited to 'src') diff --git a/src/nvim/getchar.c b/src/nvim/getchar.c index 9a3a996635..64722ef35d 100644 --- a/src/nvim/getchar.c +++ b/src/nvim/getchar.c @@ -906,19 +906,19 @@ int ins_typebuf(char_u *str, int noremap, int offset, int nottyped, bool silent) s2 = xmalloc((size_t)newlen); typebuf.tb_buflen = newlen; - /* copy the old chars, before the insertion point */ - memmove(s1 + newoff, typebuf.tb_buf + typebuf.tb_off, - (size_t)offset); - /* copy the new chars */ + // copy the old chars, before the insertion point + memmove(s1 + newoff, typebuf.tb_buf + typebuf.tb_off, (size_t)offset); + // copy the new chars memmove(s1 + newoff + offset, str, (size_t)addlen); - /* copy the old chars, after the insertion point, including the NUL at - * the end */ + // copy the old chars, after the insertion point, including the NUL at + // the end int bytes = typebuf.tb_len - offset + 1; assert(bytes > 0); memmove(s1 + newoff + offset + addlen, - typebuf.tb_buf + typebuf.tb_off + offset, (size_t)bytes); - if (typebuf.tb_buf != typebuf_init) + typebuf.tb_buf + typebuf.tb_off + offset, (size_t)bytes); + if (typebuf.tb_buf != typebuf_init) { xfree(typebuf.tb_buf); + } typebuf.tb_buf = s1; memmove(s2 + newoff, typebuf.tb_noremap + typebuf.tb_off, @@ -1064,12 +1064,12 @@ void del_typebuf(int len, int offset) typebuf.tb_noremap + typebuf.tb_off, (size_t)offset); typebuf.tb_off = MAXMAPLEN; } - /* adjust typebuf.tb_buf (include the NUL at the end) */ + // adjust typebuf.tb_buf (include the NUL at the end) int bytes = typebuf.tb_len - offset + 1; assert(bytes > 0); memmove(typebuf.tb_buf + typebuf.tb_off + offset, - typebuf.tb_buf + i + len, (size_t)bytes); - /* adjust typebuf.tb_noremap[] */ + typebuf.tb_buf + i + len, (size_t)bytes); + // adjust typebuf.tb_noremap[] memmove(typebuf.tb_noremap + typebuf.tb_off + offset, typebuf.tb_noremap + i + len, (size_t)(typebuf.tb_len - offset)); -- cgit