summaryrefslogtreecommitdiff
path: root/src/blob.c
diff options
context:
space:
mode:
authorBram Moolenaar <Bram@vim.org>2019-01-23 21:56:21 +0100
committerBram Moolenaar <Bram@vim.org>2019-01-23 21:56:21 +0100
commitdd29ea18050284526174b5685781469240f5bc4a (patch)
tree2dd4aa32dab187e6a6973303da6fcb13c4ba5d38 /src/blob.c
parentbf821bccf18453b01d25bee53e4954b02a5dd0e6 (diff)
downloadvim-git-dd29ea18050284526174b5685781469240f5bc4a.tar.gz
patch 8.1.0798: changing a blob while iterating over it works strangelyv8.1.0798
Problem: Changing a blob while iterating over it works strangely. Solution: Make a copy of the Blob before iterating.
Diffstat (limited to 'src/blob.c')
-rw-r--r--src/blob.c22
1 files changed, 22 insertions, 0 deletions
diff --git a/src/blob.c b/src/blob.c
index bba998913..a95403033 100644
--- a/src/blob.c
+++ b/src/blob.c
@@ -57,6 +57,28 @@ rettv_blob_set(typval_T *rettv, blob_T *b)
++b->bv_refcount;
}
+ int
+blob_copy(typval_T *from, typval_T *to)
+{
+ int ret = OK;
+
+ to->v_type = VAR_BLOB;
+ if (from->vval.v_blob == NULL)
+ to->vval.v_blob = NULL;
+ else if (rettv_blob_alloc(to) == FAIL)
+ ret = FAIL;
+ else
+ {
+ int len = from->vval.v_blob->bv_ga.ga_len;
+
+ if (len > 0)
+ to->vval.v_blob->bv_ga.ga_data =
+ vim_memsave(from->vval.v_blob->bv_ga.ga_data, len);
+ to->vval.v_blob->bv_ga.ga_len = len;
+ }
+ return ret;
+}
+
void
blob_free(blob_T *b)
{