mirror of
https://github.com/neovim/neovim.git
synced 2025-09-29 14:38:32 +00:00
No OOM error condition in get_register() and yank_copy_line()
This commit is contained in:

committed by
Thiago de Arruda

parent
f298be9fe1
commit
5421f84443
35
src/ops.c
35
src/ops.c
@@ -105,7 +105,7 @@ static void stuffescaped(char_u *arg, int literally);
|
|||||||
static void mb_adjust_opend(oparg_T *oap);
|
static void mb_adjust_opend(oparg_T *oap);
|
||||||
static void free_yank(long);
|
static void free_yank(long);
|
||||||
static void free_yank_all(void);
|
static void free_yank_all(void);
|
||||||
static int yank_copy_line(struct block_def *bd, long y_idx);
|
static void yank_copy_line(struct block_def *bd, long y_idx);
|
||||||
static void dis_msg(char_u *p, int skip_esc);
|
static void dis_msg(char_u *p, int skip_esc);
|
||||||
static char_u *skip_comment(char_u *line, int process,
|
static char_u *skip_comment(char_u *line, int process,
|
||||||
int include_space,
|
int include_space,
|
||||||
@@ -786,23 +786,18 @@ get_register (
|
|||||||
int copy /* make a copy, if FALSE make register empty. */
|
int copy /* make a copy, if FALSE make register empty. */
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
struct yankreg *reg;
|
|
||||||
int i;
|
|
||||||
|
|
||||||
|
|
||||||
get_yank_register(name, 0);
|
get_yank_register(name, 0);
|
||||||
reg = (struct yankreg *)alloc((unsigned)sizeof(struct yankreg));
|
|
||||||
|
struct yankreg *reg = xmalloc(sizeof(struct yankreg));
|
||||||
*reg = *y_current;
|
*reg = *y_current;
|
||||||
if (copy) {
|
if (copy) {
|
||||||
/* If we run out of memory some or all of the lines are empty. */
|
if (reg->y_size == 0) {
|
||||||
if (reg->y_size == 0)
|
|
||||||
reg->y_array = NULL;
|
reg->y_array = NULL;
|
||||||
else
|
} else
|
||||||
reg->y_array = (char_u **)alloc((unsigned)(sizeof(char_u *)
|
reg->y_array = xmalloc(reg->y_size * sizeof(char_u *));
|
||||||
* reg->y_size));
|
for (linenr_T i = 0; i < reg->y_size; ++i) {
|
||||||
if (reg->y_array != NULL) {
|
|
||||||
for (i = 0; i < reg->y_size; ++i)
|
|
||||||
reg->y_array[i] = vim_strsave(y_current->y_array[i]);
|
reg->y_array[i] = vim_strsave(y_current->y_array[i]);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} else
|
} else
|
||||||
y_current->y_array = NULL;
|
y_current->y_array = NULL;
|
||||||
@@ -2433,8 +2428,7 @@ int op_yank(oparg_T *oap, int deleting, int mess)
|
|||||||
switch (y_current->y_type) {
|
switch (y_current->y_type) {
|
||||||
case MBLOCK:
|
case MBLOCK:
|
||||||
block_prep(oap, &bd, lnum, FALSE);
|
block_prep(oap, &bd, lnum, FALSE);
|
||||||
if (yank_copy_line(&bd, y_idx) == FAIL)
|
yank_copy_line(&bd, y_idx);
|
||||||
goto fail;
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case MLINE:
|
case MLINE:
|
||||||
@@ -2501,8 +2495,7 @@ int op_yank(oparg_T *oap, int deleting, int mess)
|
|||||||
bd.textlen = endcol - startcol + oap->inclusive;
|
bd.textlen = endcol - startcol + oap->inclusive;
|
||||||
}
|
}
|
||||||
bd.textstart = p + startcol;
|
bd.textstart = p + startcol;
|
||||||
if (yank_copy_line(&bd, y_idx) == FAIL)
|
yank_copy_line(&bd, y_idx);
|
||||||
goto fail;
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
/* NOTREACHED */
|
/* NOTREACHED */
|
||||||
@@ -2584,13 +2577,10 @@ fail: /* free the allocated lines */
|
|||||||
return FAIL;
|
return FAIL;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int yank_copy_line(struct block_def *bd, long y_idx)
|
static void yank_copy_line(struct block_def *bd, long y_idx)
|
||||||
{
|
{
|
||||||
char_u *pnew;
|
char_u *pnew = xmallocz(bd->startspaces + bd->endspaces + bd->textlen);
|
||||||
|
|
||||||
if ((pnew = alloc(bd->startspaces + bd->endspaces + bd->textlen + 1))
|
|
||||||
== NULL)
|
|
||||||
return FAIL;
|
|
||||||
y_current->y_array[y_idx] = pnew;
|
y_current->y_array[y_idx] = pnew;
|
||||||
copy_spaces(pnew, (size_t)bd->startspaces);
|
copy_spaces(pnew, (size_t)bd->startspaces);
|
||||||
pnew += bd->startspaces;
|
pnew += bd->startspaces;
|
||||||
@@ -2599,7 +2589,6 @@ static int yank_copy_line(struct block_def *bd, long y_idx)
|
|||||||
copy_spaces(pnew, (size_t)bd->endspaces);
|
copy_spaces(pnew, (size_t)bd->endspaces);
|
||||||
pnew += bd->endspaces;
|
pnew += bd->endspaces;
|
||||||
*pnew = NUL;
|
*pnew = NUL;
|
||||||
return OK;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@@ -1,5 +1,9 @@
|
|||||||
#ifndef NEOVIM_OPS_H
|
#ifndef NEOVIM_OPS_H
|
||||||
#define NEOVIM_OPS_H
|
#define NEOVIM_OPS_H
|
||||||
|
|
||||||
|
#include "func_attr.h"
|
||||||
|
#include "types.h"
|
||||||
|
|
||||||
/* ops.c */
|
/* ops.c */
|
||||||
int get_op_type(int char1, int char2);
|
int get_op_type(int char1, int char2);
|
||||||
int op_on_lines(int op);
|
int op_on_lines(int op);
|
||||||
@@ -15,7 +19,7 @@ char_u *get_expr_line_src(void);
|
|||||||
int valid_yank_reg(int regname, int writing);
|
int valid_yank_reg(int regname, int writing);
|
||||||
void get_yank_register(int regname, int writing);
|
void get_yank_register(int regname, int writing);
|
||||||
int may_get_selection(int regname);
|
int may_get_selection(int regname);
|
||||||
void *get_register(int name, int copy);
|
void *get_register(int name, int copy) FUNC_ATTR_NONNULL_RET;
|
||||||
void put_register(int name, void *reg);
|
void put_register(int name, void *reg);
|
||||||
void free_register(void *reg);
|
void free_register(void *reg);
|
||||||
int yank_register_mline(int regname);
|
int yank_register_mline(int regname);
|
||||||
|
Reference in New Issue
Block a user