aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJustin M. Keyes <justinkz@gmail.com>2019-07-16 20:01:50 +0200
committerGitHub <noreply@github.com>2019-07-16 20:01:50 +0200
commit1eea2d236ff33245b426544ce4b90c8aafa53d90 (patch)
tree71dfad2f9df9fa819392a65ad3dab3215d74b1ca
parent56bc0a8bed16f3b43ea23cb25e558e582393146f (diff)
parent96e87c5a63b84df443a67d35e838703108959873 (diff)
downloadrneovim-1eea2d236ff33245b426544ce4b90c8aafa53d90.tar.gz
rneovim-1eea2d236ff33245b426544ce4b90c8aafa53d90.tar.bz2
rneovim-1eea2d236ff33245b426544ce4b90c8aafa53d90.zip
Merge #10500 from ngortheone/pvs/V1028_misc1
-rw-r--r--src/nvim/misc1.c20
1 files changed, 14 insertions, 6 deletions
diff --git a/src/nvim/misc1.c b/src/nvim/misc1.c
index 6738e59bb2..5a5bd16b98 100644
--- a/src/nvim/misc1.c
+++ b/src/nvim/misc1.c
@@ -495,9 +495,14 @@ open_line (
}
if (lead_len > 0) {
// allocate buffer (may concatenate p_extra later)
- leader = xmalloc((size_t)(lead_len + lead_repl_len + extra_space
- + extra_len + (second_line_indent > 0
- ? second_line_indent : 0) + 1));
+ int bytes = lead_len
+ + lead_repl_len
+ + extra_space
+ + extra_len
+ + (second_line_indent > 0 ? second_line_indent : 0)
+ + 1;
+ assert(bytes >= 0);
+ leader = xmalloc((size_t)bytes);
allocated = leader; // remember to free it later
STRLCPY(leader, saved_line, lead_len + 1);
@@ -1556,11 +1561,14 @@ void ins_str(char_u *s)
oldp = ml_get(lnum);
oldlen = (int)STRLEN(oldp);
- newp = (char_u *) xmalloc((size_t)(oldlen + newlen + 1));
- if (col > 0)
+ newp = (char_u *)xmalloc((size_t)oldlen + (size_t)newlen + 1);
+ if (col > 0) {
memmove(newp, oldp, (size_t)col);
+ }
memmove(newp + col, s, (size_t)newlen);
- memmove(newp + col + newlen, oldp + col, (size_t)(oldlen - col + 1));
+ int bytes = oldlen - col + 1;
+ assert(bytes >= 0);
+ memmove(newp + col + newlen, oldp + col, (size_t)bytes);
ml_replace(lnum, newp, false);
changed_bytes(lnum, col);
curwin->w_cursor.col += newlen;