forked from aniani/vim
patch 8.1.1219: not checking for NULL return from alloc()
Problem: Not checking for NULL return from alloc(). Solution: Add checks. (Martin Kunev, closes #4303, closes #4174)
This commit is contained in:
28
src/ops.c
28
src/ops.c
@@ -6170,21 +6170,25 @@ handle_viminfo_register(garray_T *values, int force)
|
||||
y_ptr->y_size = linecount;
|
||||
y_ptr->y_time_set = timestamp;
|
||||
if (linecount == 0)
|
||||
y_ptr->y_array = NULL;
|
||||
else
|
||||
{
|
||||
y_ptr->y_array =
|
||||
(char_u **)alloc((unsigned)(linecount * sizeof(char_u *)));
|
||||
for (i = 0; i < linecount; i++)
|
||||
y_ptr->y_array = NULL;
|
||||
return;
|
||||
}
|
||||
y_ptr->y_array = (char_u **)alloc((unsigned)(linecount * sizeof(char_u *)));
|
||||
if (y_ptr->y_array == NULL)
|
||||
{
|
||||
y_ptr->y_size = 0; // ensure object state is consistent
|
||||
return;
|
||||
}
|
||||
for (i = 0; i < linecount; i++)
|
||||
{
|
||||
if (vp[i + 6].bv_allocated)
|
||||
{
|
||||
if (vp[i + 6].bv_allocated)
|
||||
{
|
||||
y_ptr->y_array[i] = vp[i + 6].bv_string;
|
||||
vp[i + 6].bv_string = NULL;
|
||||
}
|
||||
else
|
||||
y_ptr->y_array[i] = vim_strsave(vp[i + 6].bv_string);
|
||||
y_ptr->y_array[i] = vp[i + 6].bv_string;
|
||||
vp[i + 6].bv_string = NULL;
|
||||
}
|
||||
else
|
||||
y_ptr->y_array[i] = vim_strsave(vp[i + 6].bv_string);
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user