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).
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user