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/typval.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/typval.c')
-rw-r--r-- | src/nvim/eval/typval.c | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/src/nvim/eval/typval.c b/src/nvim/eval/typval.c index e689571788..68fab1dacd 100644 --- a/src/nvim/eval/typval.c +++ b/src/nvim/eval/typval.c @@ -2252,6 +2252,30 @@ void tv_blob_alloc_ret(typval_T *const ret_tv) tv_blob_set_ret(ret_tv, b); } +/// Copy a blob typval to a different typval. +/// +/// @param[in] from Blob object to copy from. +/// @param[out] to Blob object to copy to. +void tv_blob_copy(typval_T *const from, typval_T *const to) + FUNC_ATTR_NONNULL_ALL +{ + assert(from->v_type == 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; + + if (len > 0) { + 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; + } +} + //{{{3 Clear #define TYPVAL_ENCODE_ALLOW_SPECIALS false |