1
0
forked from aniani/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.
This commit is contained in:
Bram Moolenaar
2019-01-23 21:56:21 +01:00
parent bf821bccf1
commit dd29ea1805
5 changed files with 50 additions and 23 deletions

View File

@@ -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)
{