Mercurial > vim
comparison 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 |
comparison
equal
deleted
inserted
replaced
16428:6f69ef2913d7 | 16429:a1229400434a |
---|---|
6168 y_ptr->y_type = type; | 6168 y_ptr->y_type = type; |
6169 y_ptr->y_width = width; | 6169 y_ptr->y_width = width; |
6170 y_ptr->y_size = linecount; | 6170 y_ptr->y_size = linecount; |
6171 y_ptr->y_time_set = timestamp; | 6171 y_ptr->y_time_set = timestamp; |
6172 if (linecount == 0) | 6172 if (linecount == 0) |
6173 { | |
6173 y_ptr->y_array = NULL; | 6174 y_ptr->y_array = NULL; |
6174 else | 6175 return; |
6175 { | 6176 } |
6176 y_ptr->y_array = | 6177 y_ptr->y_array = (char_u **)alloc((unsigned)(linecount * sizeof(char_u *))); |
6177 (char_u **)alloc((unsigned)(linecount * sizeof(char_u *))); | 6178 if (y_ptr->y_array == NULL) |
6178 for (i = 0; i < linecount; i++) | 6179 { |
6179 { | 6180 y_ptr->y_size = 0; // ensure object state is consistent |
6180 if (vp[i + 6].bv_allocated) | 6181 return; |
6181 { | 6182 } |
6182 y_ptr->y_array[i] = vp[i + 6].bv_string; | 6183 for (i = 0; i < linecount; i++) |
6183 vp[i + 6].bv_string = NULL; | 6184 { |
6184 } | 6185 if (vp[i + 6].bv_allocated) |
6185 else | 6186 { |
6186 y_ptr->y_array[i] = vim_strsave(vp[i + 6].bv_string); | 6187 y_ptr->y_array[i] = vp[i + 6].bv_string; |
6187 } | 6188 vp[i + 6].bv_string = NULL; |
6189 } | |
6190 else | |
6191 y_ptr->y_array[i] = vim_strsave(vp[i + 6].bv_string); | |
6188 } | 6192 } |
6189 } | 6193 } |
6190 | 6194 |
6191 void | 6195 void |
6192 write_viminfo_registers(FILE *fp) | 6196 write_viminfo_registers(FILE *fp) |