1
0
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:
Bram Moolenaar
2019-04-27 22:06:37 +02:00
parent 00aa069db8
commit 6ee9658774
14 changed files with 83 additions and 37 deletions

View File

@@ -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);
}
}