neovim

Neovim text editor
git clone https://git.dasho.dev/neovim.git
Log | Files | Refs | README

commit d2d1b5e944b5888f3237d48e1a88aa6c8e156edc
parent 5333d6371bfa2fe048e5d99e0e843657b3b0e33f
Author: zeertzjq <zeertzjq@outlook.com>
Date:   Wed, 16 Apr 2025 06:47:51 +0800

vim-patch:9.1.1303: missing out-of-memory check in linematch.c (#33487)

Problem:  missing out-of-memory check in linematch.c
Solution: return early in case of memory allocation failure, move the
          pow() calculation ouside of the for() loop
          (John Marriott)

closes: vim/vim#17118

https://github.com/vim/vim/commit/2137710b436e481168382c50aa4838a4b9730163

Co-authored-by: John Marriott <basilisk@internode.on.net>
Diffstat:
Msrc/nvim/linematch.c | 3++-
1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/src/nvim/linematch.c b/src/nvim/linematch.c @@ -345,10 +345,11 @@ size_t linematch_nbuffers(const mmfile_t **diff_blk, const int *diff_len, const // create the flattened path matrix diffcmppath_T *diffcmppath = xmalloc(sizeof(diffcmppath_T) * memsize); // allocate memory here + size_t n = (size_t)pow(2.0, (double)ndiffs); for (size_t i = 0; i < memsize; i++) { diffcmppath[i].df_lev_score = 0; diffcmppath[i].df_path_n = 0; - for (size_t j = 0; j < (size_t)pow(2, (double)ndiffs); j++) { + for (size_t j = 0; j < n; j++) { diffcmppath[i].df_choice_mem[j] = -1; } }