comparison src/blob.c @ 15581:c2382f0d1279 v8.1.0798

patch 8.1.0798: changing a blob while iterating over it works strangely commit https://github.com/vim/vim/commit/dd29ea18050284526174b5685781469240f5bc4a Author: Bram Moolenaar <Bram@vim.org> Date: Wed Jan 23 21:56:21 2019 +0100 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.
author Bram Moolenaar <Bram@vim.org>
date Wed, 23 Jan 2019 22:00:06 +0100
parents 99a4cc4782ac
children 44ea60ca593b
comparison
equal deleted inserted replaced
15580:0bf6ce525d42 15581:c2382f0d1279
55 rettv->vval.v_blob = b; 55 rettv->vval.v_blob = b;
56 if (b != NULL) 56 if (b != NULL)
57 ++b->bv_refcount; 57 ++b->bv_refcount;
58 } 58 }
59 59
60 int
61 blob_copy(typval_T *from, typval_T *to)
62 {
63 int ret = OK;
64
65 to->v_type = VAR_BLOB;
66 if (from->vval.v_blob == NULL)
67 to->vval.v_blob = NULL;
68 else if (rettv_blob_alloc(to) == FAIL)
69 ret = FAIL;
70 else
71 {
72 int len = from->vval.v_blob->bv_ga.ga_len;
73
74 if (len > 0)
75 to->vval.v_blob->bv_ga.ga_data =
76 vim_memsave(from->vval.v_blob->bv_ga.ga_data, len);
77 to->vval.v_blob->bv_ga.ga_len = len;
78 }
79 return ret;
80 }
81
60 void 82 void
61 blob_free(blob_T *b) 83 blob_free(blob_T *b)
62 { 84 {
63 ga_clear(&b->bv_ga); 85 ga_clear(&b->bv_ga);
64 vim_free(b); 86 vim_free(b);