diff options
author | Bastien Montagne <montagne29@wanadoo.fr> | 2019-01-16 18:14:10 +0300 |
---|---|---|
committer | Bastien Montagne <montagne29@wanadoo.fr> | 2019-01-16 18:15:52 +0300 |
commit | 0a378b8ebce46acfec405ca1403b126989e124ef (patch) | |
tree | 01cdd390c249192a319e6ad122a779da47391fff /source/blender/blenkernel | |
parent | 792c453b2a59a27d77940351d6d42a0f2ec7055e (diff) |
Fix BKE_id_copy_ex() being able to 'return' garbage in copied ID.
Reported/noted in D4178, it would return immediatly in case of NULL
source ID, without ensuring that return 'copied' ID was properly
initialized.
Diffstat (limited to 'source/blender/blenkernel')
-rw-r--r-- | source/blender/blenkernel/intern/library.c | 11 |
1 files changed, 6 insertions, 5 deletions
diff --git a/source/blender/blenkernel/intern/library.c b/source/blender/blenkernel/intern/library.c index 0f33fc49ca2..e6c99e6a57b 100644 --- a/source/blender/blenkernel/intern/library.c +++ b/source/blender/blenkernel/intern/library.c @@ -566,10 +566,6 @@ 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)); - /* 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) { @@ -578,11 +574,16 @@ bool BKE_id_copy_ex(Main *bmain, const ID *id, ID **r_newid, const int flag, con } else { if (r_newid != NULL && *r_newid != NULL) { - /* Allow some garbage non-initialized memory to go in. */ + /* Allow some garbage non-initialized memory to go in, and clean it up here. */ const size_t size = BKE_libblock_get_alloc_info(GS(id->name), NULL); memset(*r_newid, 0, size); } } + + /* Early output is source is NULL. */ + if (id == NULL) { + return false; + } if (ELEM(GS(id->name), LIB_ID_TYPES_NOCOPY)) { return false; } |