diff options
Diffstat (limited to 'src/nvim/ops.c')
| -rw-r--r-- | src/nvim/ops.c | 18 |
1 files changed, 11 insertions, 7 deletions
diff --git a/src/nvim/ops.c b/src/nvim/ops.c index e07e93060a..7c38ecff4a 100644 --- a/src/nvim/ops.c +++ b/src/nvim/ops.c @@ -379,8 +379,10 @@ static void shift_block(oparg_T *oap, int amount) /* if we're splitting a TAB, allow for it */ bd.textcol -= bd.pre_whitesp_c - (bd.startspaces != 0); const int len = (int)STRLEN(bd.textstart) + 1; - newp = (char_u *)xmalloc((size_t)(bd.textcol + i + j + len)); - memset(newp, NUL, (size_t)(bd.textcol + i + j + len)); + int col = bd.textcol + i +j + len; + assert(col >= 0); + newp = (char_u *)xmalloc((size_t)col); + memset(newp, NUL, (size_t)col); memmove(newp, oldp, (size_t)bd.textcol); memset(newp + bd.textcol, TAB, (size_t)i); memset(newp + bd.textcol + i, ' ', (size_t)j); @@ -1471,7 +1473,8 @@ int op_delete(oparg_T *oap) // copy up to deleted part memmove(newp, oldp, (size_t)bd.textcol); // insert spaces - memset(newp + bd.textcol, ' ', (size_t)(bd.startspaces + bd.endspaces)); + memset(newp + bd.textcol, ' ', (size_t)bd.startspaces + + (size_t)bd.endspaces); // copy the part after the deleted part oldp += bd.textcol + bd.textlen; STRMOVE(newp + bd.textcol + bd.startspaces + bd.endspaces, oldp); @@ -1743,7 +1746,7 @@ int op_replace(oparg_T *oap, int c) oldp = get_cursor_line_ptr(); oldlen = (int)STRLEN(oldp); - size_t newp_size = (size_t)(bd.textcol + bd.startspaces); + size_t newp_size = (size_t)bd.textcol + (size_t)bd.startspaces; if (had_ctrl_v_cr || (c != '\r' && c != '\n')) { newp_size += (size_t)numc; if (!bd.is_short) { @@ -1760,6 +1763,8 @@ int op_replace(oparg_T *oap, int c) // insert replacement chars CHECK FOR ALLOCATED SPACE // REPLACE_CR_NCHAR/REPLACE_NL_NCHAR is used for entering CR literally. size_t after_p_len = 0; + int col = oldlen - bd.textcol - bd.textlen + 1; + assert(col >= 0); if (had_ctrl_v_cr || (c != '\r' && c != '\n')) { // strlen(newp) at this point int newp_len = bd.textcol + bd.startspaces; @@ -1771,12 +1776,11 @@ int op_replace(oparg_T *oap, int c) memset(newp + newp_len, ' ', (size_t)bd.endspaces); newp_len += bd.endspaces; // copy the part after the changed part - memmove(newp + newp_len, oldp, - (size_t)(oldlen - bd.textcol - bd.textlen + 1)); + memmove(newp + newp_len, oldp, (size_t)col); } } else { // Replacing with \r or \n means splitting the line. - after_p_len = (size_t)(oldlen - bd.textcol - bd.textlen + 1); + after_p_len = (size_t)col; after_p = (char_u *)xmalloc(after_p_len); memmove(after_p, oldp, after_p_len); } |
