diff options
author | Sean Dewar <seandewar@users.noreply.github.com> | 2021-07-29 20:25:46 +0100 |
---|---|---|
committer | Sean Dewar <seandewar@users.noreply.github.com> | 2021-09-15 22:30:31 +0100 |
commit | 23f5999d28cdee049661ed38e22812a063e78fad (patch) | |
tree | 92de335089813184df2704ea65aea2f664da04a5 /src/nvim/eval.c | |
parent | e140eec441006d0a05abcba49c6d9a0482609216 (diff) | |
download | rneovim-23f5999d28cdee049661ed38e22812a063e78fad.tar.gz rneovim-23f5999d28cdee049661ed38e22812a063e78fad.tar.bz2 rneovim-23f5999d28cdee049661ed38e22812a063e78fad.zip |
vim-patch:8.1.0798: changing a blob while iterating over it works strangely
Problem: Changing a blob while iterating over it works strangely.
Solution: Make a copy of the Blob before iterating.
https://github.com/vim/vim/commit/dd29ea18050284526174b5685781469240f5bc4a
Diffstat (limited to 'src/nvim/eval.c')
-rw-r--r-- | src/nvim/eval.c | 29 |
1 files changed, 10 insertions, 19 deletions
diff --git a/src/nvim/eval.c b/src/nvim/eval.c index 596ed19ff9..b7dc00dc08 100644 --- a/src/nvim/eval.c +++ b/src/nvim/eval.c @@ -2599,15 +2599,16 @@ void *eval_for_line(const char_u *arg, bool *errp, char_u **nextcmdp, int skip) fi->fi_lw.lw_item = tv_list_first(l); } } else if (tv.v_type == VAR_BLOB) { - blob_T *const b = tv.vval.v_blob; - if (b == NULL) { - tv_clear(&tv); - } else { - // No need to increment the refcount, it's already set for - // the blob being used in "tv". - fi->fi_blob = b; - fi->fi_bi = 0; + fi->fi_bi = 0; + if (tv.vval.v_blob != NULL) { + typval_T btv; + + // Make a copy, so that the iteration still works when the + // blob is changed. + tv_blob_copy(&tv, &btv); + fi->fi_blob = btv.vval.v_blob; } + tv_clear(&tv); } else { EMSG(_(e_listreq)); tv_clear(&tv); @@ -9737,17 +9738,7 @@ int var_item_copy(const vimconv_T *const conv, } break; case VAR_BLOB: - to->v_type = VAR_BLOB; - if (from->vval.v_blob == NULL) { - to->vval.v_blob = NULL; - } else { - tv_blob_alloc_ret(to); - const int len = from->vval.v_blob->bv_ga.ga_len; - - to->vval.v_blob->bv_ga.ga_data - = xmemdup(from->vval.v_blob->bv_ga.ga_data, (size_t)len); - to->vval.v_blob->bv_ga.ga_len = len; - } + tv_blob_copy(from, to); break; case VAR_DICT: to->v_type = VAR_DICT; |