aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJustin M. Keyes <justinkz@gmail.com>2019-07-16 19:56:30 +0200
committerGitHub <noreply@github.com>2019-07-16 19:56:30 +0200
commitb53b3f7dac51ee1001a97efea83690908cb5db76 (patch)
treecb131820ae351b40a94aa9f77af830f5ff15cd0b
parentb35ad8602402d5fbd67936ab12f660525228220a (diff)
parent8df20ff56278467211360a71a9139eb76116eaf3 (diff)
downloadrneovim-b53b3f7dac51ee1001a97efea83690908cb5db76.tar.gz
rneovim-b53b3f7dac51ee1001a97efea83690908cb5db76.tar.bz2
rneovim-b53b3f7dac51ee1001a97efea83690908cb5db76.zip
Merge #10493 from ngortheone/pvs/V1028_getchar_918
-rw-r--r--src/nvim/getchar.c29
1 files changed, 16 insertions, 13 deletions
diff --git a/src/nvim/getchar.c b/src/nvim/getchar.c
index 7efae1e637..64722ef35d 100644
--- a/src/nvim/getchar.c
+++ b/src/nvim/getchar.c
@@ -15,6 +15,7 @@
#include <string.h>
#include <inttypes.h>
+#include "nvim/assert.h"
#include "nvim/vim.h"
#include "nvim/ascii.h"
#include "nvim/getchar.h"
@@ -905,18 +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)(typebuf.tb_len - offset + 1));
- 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,
@@ -1062,11 +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)(typebuf.tb_len - offset + 1));
- /* 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));