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.
This commit is contained in:
Bastien Montagne
2019-01-16 16:14:10 +01:00
parent 792c453b2a
commit 0a378b8ebc

View File

@@ -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;
}