diff options
author | Bram Moolenaar <Bram@vim.org> | 2019-04-27 22:06:37 +0200 |
---|---|---|
committer | Bram Moolenaar <Bram@vim.org> | 2019-04-27 22:06:37 +0200 |
commit | 6ee9658774942f7448af700fc04df0335796a3db (patch) | |
tree | 87f99c37e22f07e73e244da78686c7e59a8457f1 /src/ops.c | |
parent | 00aa069db8132851a91cfc5ca7f58ef945c75c73 (diff) | |
download | vim-git-6ee9658774942f7448af700fc04df0335796a3db.tar.gz |
patch 8.1.1219: not checking for NULL return from alloc()v8.1.1219
Problem: Not checking for NULL return from alloc().
Solution: Add checks. (Martin Kunev, closes #4303, closes #4174)
Diffstat (limited to 'src/ops.c')
-rw-r--r-- | src/ops.c | 26 |
1 files changed, 15 insertions, 11 deletions
@@ -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 + 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++) { - y_ptr->y_array = - (char_u **)alloc((unsigned)(linecount * sizeof(char_u *))); - 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); } } |