[Bf-blender-cvs] [aff1cfc] alembic: Fix for potential NULL pointer access when looking up strands data from caches.

Lukas Tönne noreply at git.blender.org
Mon May 11 13:59:45 CEST 2015


Commit: aff1cfc013b7f1736d1a773b8382969f6fb8a2f5
Author: Lukas Tönne
Date:   Mon May 11 13:58:15 2015 +0200
Branches: alembic
https://developer.blender.org/rBaff1cfc013b7f1736d1a773b8382969f6fb8a2f5

Fix for potential NULL pointer access when looking up strands data from
caches.

The 'find' function was returning a bool value, but this does not
guarantee non-null pointers. Removed the return value to avoid
confusion, now callers should simply check the returned pointers.

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

M	source/blender/blenkernel/BKE_anim.h
M	source/blender/blenkernel/intern/object_dupli.c
M	source/blender/makesrna/intern/rna_object.c

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

diff --git a/source/blender/blenkernel/BKE_anim.h b/source/blender/blenkernel/BKE_anim.h
index e3d6b41..bfba221 100644
--- a/source/blender/blenkernel/BKE_anim.h
+++ b/source/blender/blenkernel/BKE_anim.h
@@ -93,7 +93,7 @@ void BKE_dupli_object_data_clear(struct DupliObjectData *data);
 void BKE_dupli_object_data_set_mesh(struct DupliObjectData *data, struct DerivedMesh *dm);
 void BKE_dupli_object_data_add_strands(struct DupliObjectData *data, const char *name, struct Strands *strands);
 void BKE_dupli_object_data_add_strands_children(struct DupliObjectData *data, const char *name, struct StrandsChildren *children);
-bool BKE_dupli_object_data_find_strands(struct DupliObjectData *data, const char *name, struct Strands **r_strands, struct StrandsChildren **r_children);
+void BKE_dupli_object_data_find_strands(struct DupliObjectData *data, const char *name, struct Strands **r_strands, struct StrandsChildren **r_children);
 bool BKE_dupli_object_data_acquire_strands(struct DupliObjectData *data, struct Strands *strands);
 bool BKE_dupli_object_data_acquire_strands_children(struct DupliObjectData *data, struct StrandsChildren *children);
 
diff --git a/source/blender/blenkernel/intern/object_dupli.c b/source/blender/blenkernel/intern/object_dupli.c
index 20fd286..4690dbd 100644
--- a/source/blender/blenkernel/intern/object_dupli.c
+++ b/source/blender/blenkernel/intern/object_dupli.c
@@ -1463,20 +1463,19 @@ void BKE_dupli_object_data_add_strands_children(DupliObjectData *data, const cha
 	dupli_cache_calc_boundbox(data);
 }
 
-bool BKE_dupli_object_data_find_strands(DupliObjectData *data, const char *name, Strands **r_strands, StrandsChildren **r_children)
+void BKE_dupli_object_data_find_strands(DupliObjectData *data, const char *name, Strands **r_strands, StrandsChildren **r_children)
 {
 	DupliObjectDataStrands *link;
 	for (link = data->strands.first; link; link = link->next) {
 		if (STREQ(link->name, name)) {
 			if (r_strands) *r_strands = link->strands;
 			if (r_children) *r_children = link->strands_children;
-			return true;
+			return;
 		}
 	}
 	
 	if (r_strands) *r_strands = NULL;
 	if (r_children) *r_children = NULL;
-	return false;
 }
 
 bool BKE_dupli_object_data_acquire_strands(DupliObjectData *data, Strands *strands)
diff --git a/source/blender/makesrna/intern/rna_object.c b/source/blender/makesrna/intern/rna_object.c
index b038950..80b6ea5 100644
--- a/source/blender/makesrna/intern/rna_object.c
+++ b/source/blender/makesrna/intern/rna_object.c
@@ -1548,7 +1548,8 @@ Strands *rna_DupliObject_strands_new(DupliObject *dob, ReportList *UNUSED(report
 				/* TODO(sergey): Consider sharing the data between viewport and
 				 * render engine.
 				 */
-				if (BKE_dupli_object_data_find_strands(data, psys->name, &strands, NULL)) {
+				BKE_dupli_object_data_find_strands(data, psys->name, &strands, NULL);
+				if (strands) {
 					strands = BKE_strands_copy(strands);
 				}
 			}
@@ -1558,7 +1559,8 @@ Strands *rna_DupliObject_strands_new(DupliObject *dob, ReportList *UNUSED(report
 			
 			memset(&data, 0, sizeof(data));
 			if (BKE_cache_read_dupli_object(parent->cache_library, &data, scene, dob->ob, frame, eval_mode, true)) {
-				if (BKE_dupli_object_data_find_strands(&data, psys->name, &strands, NULL))
+				BKE_dupli_object_data_find_strands(&data, psys->name, &strands, NULL);
+				if (strands)
 					BKE_dupli_object_data_acquire_strands(&data, strands);
 			}
 			
@@ -1602,7 +1604,8 @@ StrandsChildren *rna_DupliObject_strands_children_new(DupliObject *dob, ReportLi
 				/* TODO(sergey): Consider sharing the data between viewport and
 				 * render engine.
 				 */
-				if (BKE_dupli_object_data_find_strands(data, psys->name, NULL, &strands)) {
+				BKE_dupli_object_data_find_strands(data, psys->name, NULL, &strands);
+				if (strands) {
 					strands = BKE_strands_children_copy(strands);
 				}
 			}
@@ -1613,14 +1616,16 @@ StrandsChildren *rna_DupliObject_strands_children_new(DupliObject *dob, ReportLi
 			memset(&data, 0, sizeof(data));
 			if (BKE_cache_read_dupli_object(parent->cache_library, &data, scene, dob->ob, frame, eval_mode, true)) {
 				Strands *parents;
-				if (BKE_dupli_object_data_find_strands(&data, psys->name, &parents, &strands)) {
+				BKE_dupli_object_data_find_strands(&data, psys->name, &parents, &strands);
+				if (strands) {
 					BKE_dupli_object_data_acquire_strands_children(&data, strands);
 					
 					/* Deform child strands to follow parent motion.
 					 * Note that this is an optional feature for viewport/render display,
 					 * strand motion is not applied to raw child data in caches.
 					 */
-					BKE_strands_children_deform(strands, parents, true);
+					if (parents)
+						BKE_strands_children_deform(strands, parents, true);
 				}
 			}




More information about the Bf-blender-cvs mailing list