vim-patch:8.1.0756: copy() does not make a copy of a Blob

Problem:    copy() does not make a copy of a Blob.
Solution:   Make a copy.
3d28b58c51

Replace vim_memsave() with xmemdup().
This commit is contained in:
Sean Dewar
2020-11-25 16:21:00 +00:00
parent c1b8731ece
commit 2b98bdd75b
2 changed files with 20 additions and 1 deletions

View File

@@ -9700,7 +9700,6 @@ int var_item_copy(const vimconv_T *const conv,
case VAR_PARTIAL:
case VAR_BOOL:
case VAR_SPECIAL:
case VAR_BLOB:
tv_copy(from, to);
break;
case VAR_STRING:
@@ -9734,6 +9733,19 @@ int var_item_copy(const vimconv_T *const conv,
ret = FAIL;
}
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;
}
break;
case VAR_DICT:
to->v_type = VAR_DICT;
to->v_lock = VAR_UNLOCKED;

View File

@@ -112,7 +112,14 @@ func Test_blob_compare()
call assert_false(b1 is b2)
let b2 = b1
call assert_true(b1 == b2)
call assert_true(b1 is b2)
let b2 = copy(b1)
call assert_true(b1 == b2)
call assert_false(b1 is b2)
let b2 = b1[:]
call assert_true(b1 == b2)
call assert_false(b1 is b2)
call assert_fails('let x = b1 > b2')
call assert_fails('let x = b1 < b2')