diff src/ops.c @ 16429:a1229400434a v8.1.1219

patch 8.1.1219: not checking for NULL return from alloc() commit https://github.com/vim/vim/commit/6ee9658774942f7448af700fc04df0335796a3db Author: Bram Moolenaar <Bram@vim.org> Date: Sat Apr 27 22:06:37 2019 +0200 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 https://github.com/vim/vim/issues/4303, closes https://github.com/vim/vim/issues/4174)
author Bram Moolenaar <Bram@vim.org>
date Sat, 27 Apr 2019 22:15:05 +0200
parents cd5c83115ec6
children 6f453673eb19
line wrap: on
line diff
--- a/src/ops.c
+++ b/src/ops.c
@@ -6170,21 +6170,25 @@ handle_viminfo_register(garray_T *values
     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++)
-	{
-	    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);
-	}
+	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)
+	{
+	    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);
     }
 }