diff options
author | Sergey Sharybin <sergey.vfx@gmail.com> | 2017-10-19 14:55:08 +0300 |
---|---|---|
committer | Sergey Sharybin <sergey.vfx@gmail.com> | 2017-10-19 14:55:08 +0300 |
commit | 1cddab18ded9489f2f29b0655698f2e2e4e2076a (patch) | |
tree | 9da62f40bdcfa35af9650efe63945bb12b06f057 /source/blender/blenkernel/intern/library.c | |
parent | 529d365b4d2a91923b365f409389c1f4c89b0a1f (diff) |
Allow non-initialized memory to be passed to BKE_id_copy_ex
This only applies when LIB_ID_CREATE_NO_ALLOCATE flag is used and guarantees
that non-memset-zero memory can be used (or, that same memory chunk might be
used over and over again without need to clean it from the calleer).
Diffstat (limited to 'source/blender/blenkernel/intern/library.c')
-rw-r--r-- | source/blender/blenkernel/intern/library.c | 18 |
1 files changed, 14 insertions, 4 deletions
diff --git a/source/blender/blenkernel/intern/library.c b/source/blender/blenkernel/intern/library.c index 0aacb89c550..b659e59e83a 100644 --- a/source/blender/blenkernel/intern/library.c +++ b/source/blender/blenkernel/intern/library.c @@ -529,13 +529,23 @@ bool BKE_id_copy_ex(Main *bmain, const ID *id, ID **r_newid, const int flag, con ID_IP /* Deprecated */ BLI_assert(test || (r_newid != NULL)); - if (r_newid != NULL && (flag & LIB_ID_CREATE_NO_ALLOCATE) == 0) { - *r_newid = NULL; - } + /* Early output is source is NULL. */ if (id == NULL) { return false; } - + /* Make sure destination pointer is all good. */ + if ((flag & LIB_ID_CREATE_NO_ALLOCATE) == 0) { + if (r_newid != NULL) { + *r_newid = NULL; + } + } + else { + if (r_newid != NULL && *r_newid != NULL) { + /* Allow some garbage non-initialized memory to go in. */ + const size_t size = BKE_libblock_get_alloc_info(GS(id->name), NULL); + memset(*r_newid, 0, size); + } + } if (ELEM(GS(id->name), LIB_ID_TYPES_NOCOPY)) { return false; } |