[Bf-blender-cvs] [1cddab18ded] master: Allow non-initialized memory to be passed to BKE_id_copy_ex

Sergey Sharybin noreply at git.blender.org
Thu Oct 19 13:57:27 CEST 2017


Commit: 1cddab18ded9489f2f29b0655698f2e2e4e2076a
Author: Sergey Sharybin
Date:   Thu Oct 19 13:55:08 2017 +0200
Branches: master
https://developer.blender.org/rB1cddab18ded9489f2f29b0655698f2e2e4e2076a

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).

===================================================================

M	source/blender/blenkernel/intern/library.c

===================================================================

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



More information about the Bf-blender-cvs mailing list