aboutsummaryrefslogtreecommitdiff
path: root/src/ops.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/ops.c')
-rw-r--r--src/ops.c48
1 files changed, 20 insertions, 28 deletions
diff --git a/src/ops.c b/src/ops.c
index f729f4e06b..30606b077e 100644
--- a/src/ops.c
+++ b/src/ops.c
@@ -885,9 +885,6 @@ int do_record(int c)
*/
static int stuff_yank(int regname, char_u *p)
{
- char_u *lp;
- char_u **pp;
-
/* check for read-only register */
if (regname != 0 && !valid_yank_reg(regname, TRUE)) {
free(p);
@@ -899,9 +896,10 @@ static int stuff_yank(int regname, char_u *p)
}
get_yank_register(regname, TRUE);
if (y_append && y_current->y_array != NULL) {
- pp = &(y_current->y_array[y_current->y_size - 1]);
- lp = lalloc((long_u)(STRLEN(*pp) + STRLEN(p) + 1), TRUE);
+ char_u **pp = &(y_current->y_array[y_current->y_size - 1]);
+ char_u *lp = xmalloc(STRLEN(*pp) + STRLEN(p) + 1);
STRCPY(lp, *pp);
+ // TODO(philix): use xstpcpy() in stuff_yank()
STRCAT(lp, p);
free(p);
free(*pp);
@@ -2486,10 +2484,7 @@ int op_yank(oparg_T *oap, int deleting, int mess)
}
if (curr != y_current) { /* append the new block to the old block */
- new_ptr = (char_u **)lalloc(
- (long_u)(sizeof(char_u *) *
- (curr->y_size + y_current->y_size)),
- TRUE);
+ new_ptr = xmalloc(sizeof(char_u *) * (curr->y_size + y_current->y_size));
for (j = 0; j < curr->y_size; ++j)
new_ptr[j] = curr->y_array[j];
free(curr->y_array);
@@ -2501,8 +2496,8 @@ int op_yank(oparg_T *oap, int deleting, int mess)
/* Concatenate the last line of the old block with the first line of
* the new block, unless being Vi compatible. */
if (curr->y_type == MCHAR && vim_strchr(p_cpo, CPO_REGAPPEND) == NULL) {
- pnew = lalloc((long_u)(STRLEN(curr->y_array[curr->y_size - 1])
- + STRLEN(y_current->y_array[0]) + 1), TRUE);
+ pnew = xmalloc(STRLEN(curr->y_array[curr->y_size - 1])
+ + STRLEN(y_current->y_array[0]) + 1);
STRCPY(pnew, curr->y_array[--j]);
STRCAT(pnew, y_current->y_array[0]);
free(curr->y_array[j]);
@@ -4676,7 +4671,6 @@ get_reg_contents (
long i;
char_u *retval;
int allocated;
- long len;
/* Don't allow using an expression register inside an expression */
if (regname == '=') {
@@ -4711,9 +4705,9 @@ get_reg_contents (
/*
* Compute length of resulting string.
*/
- len = 0;
+ size_t len = 0;
for (i = 0; i < y_current->y_size; ++i) {
- len += (long)STRLEN(y_current->y_array[i]);
+ len += STRLEN(y_current->y_array[i]);
/*
* Insert a newline between lines and after last line if
* y_type is MLINE.
@@ -4722,26 +4716,24 @@ get_reg_contents (
++len;
}
- retval = lalloc(len + 1, TRUE);
+ retval = xmalloc(len + 1);
/*
* Copy the lines of the yank register into the string.
*/
- if (retval != NULL) {
- len = 0;
- for (i = 0; i < y_current->y_size; ++i) {
- STRCPY(retval + len, y_current->y_array[i]);
- len += (long)STRLEN(retval + len);
+ len = 0;
+ for (i = 0; i < y_current->y_size; ++i) {
+ STRCPY(retval + len, y_current->y_array[i]);
+ len += STRLEN(retval + len);
- /*
- * Insert a NL between lines and after the last line if y_type is
- * MLINE.
- */
- if (y_current->y_type == MLINE || i < y_current->y_size - 1)
- retval[len++] = '\n';
- }
- retval[len] = NUL;
+ /*
+ * Insert a NL between lines and after the last line if y_type is
+ * MLINE.
+ */
+ if (y_current->y_type == MLINE || i < y_current->y_size - 1)
+ retval[len++] = '\n';
}
+ retval[len] = NUL;
return retval;
}