[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [50517] trunk/blender: add some missing NULL checks, a few parts of the code used a pointer then checked it for NULL after.

Campbell Barton ideasman42 at gmail.com
Tue Sep 11 04:18:30 CEST 2012


Revision: 50517
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=50517
Author:   campbellbarton
Date:     2012-09-11 02:18:27 +0000 (Tue, 11 Sep 2012)
Log Message:
-----------
add some missing NULL checks, a few parts of the code used a pointer then checked it for NULL after.
also made it more clear that some areas assume the pointer isnt null (remove redundant NULL checks).

Modified Paths:
--------------
    trunk/blender/release/scripts/startup/bl_ui/space_image.py
    trunk/blender/source/blender/blenkernel/intern/dynamicpaint.c
    trunk/blender/source/blender/blenkernel/intern/fcurve.c
    trunk/blender/source/blender/blenkernel/intern/softbody.c
    trunk/blender/source/blender/blenlib/intern/scanfill.c
    trunk/blender/source/blender/editors/animation/keyframing.c
    trunk/blender/source/blender/editors/mesh/editmesh_bvh.c
    trunk/blender/source/blender/editors/mesh/editmesh_select.c
    trunk/blender/source/blender/editors/physics/particle_edit.c
    trunk/blender/source/blender/editors/transform/transform_conversions.c
    trunk/blender/source/gameengine/Rasterizer/RAS_MeshObject.cpp

Modified: trunk/blender/release/scripts/startup/bl_ui/space_image.py
===================================================================
--- trunk/blender/release/scripts/startup/bl_ui/space_image.py	2012-09-11 01:30:05 UTC (rev 50516)
+++ trunk/blender/release/scripts/startup/bl_ui/space_image.py	2012-09-11 02:18:27 UTC (rev 50517)
@@ -774,7 +774,7 @@
         toolsettings = context.tool_settings.image_paint
         brush = toolsettings.brush
 
-        layout.template_curve_mapping(brush, "curve", type='COLOR')
+        layout.template_curve_mapping(brush, "curve")
 
         row = layout.row(align=True)
         row.operator("brush.curve_preset", icon='SMOOTHCURVE', text="").shape = 'SMOOTH'

Modified: trunk/blender/source/blender/blenkernel/intern/dynamicpaint.c
===================================================================
--- trunk/blender/source/blender/blenkernel/intern/dynamicpaint.c	2012-09-11 01:30:05 UTC (rev 50516)
+++ trunk/blender/source/blender/blenkernel/intern/dynamicpaint.c	2012-09-11 02:18:27 UTC (rev 50517)
@@ -2595,7 +2595,7 @@
 	int format = (surface->image_fileformat & MOD_DPAINT_IMGFORMAT_OPENEXR) ? R_IMF_IMTYPE_OPENEXR : R_IMF_IMTYPE_PNG;
 	char output_file[FILE_MAX];
 
-	if (!sData || !sData->type_data) { setError(surface->canvas, "Image save failed: Invalid surface."); return; }
+	if (!sData->type_data) { setError(surface->canvas, "Image save failed: Invalid surface."); return; }
 	/* if selected format is openexr, but current build doesnt support one */
 	#ifndef WITH_OPENEXR
 	if (format == R_IMF_IMTYPE_OPENEXR) format = R_IMF_IMTYPE_PNG;
@@ -4800,7 +4800,7 @@
 	PaintBakeData *bData = sData->bData;
 	DynamicPaintCanvasSettings *canvas = surface->canvas;
 	int ret = 1;
-	if (!sData || sData->total_points < 1) return 0;
+	if (sData->total_points < 1) return 0;
 
 	dynamicPaint_surfacePreStep(surface, timescale);
 	/*
@@ -4875,7 +4875,7 @@
 					/* Apply brush on the surface depending on it's collision type */
 					/* Particle brush: */
 					if (brush->collision == MOD_DPAINT_COL_PSYS) {
-						if (brush && brush->psys && brush->psys->part && brush->psys->part->type == PART_EMITTER &&
+						if (brush->psys && brush->psys->part && brush->psys->part->type == PART_EMITTER &&
 						    psys_check_enabled(brushObj, brush->psys))
 						{
 

Modified: trunk/blender/source/blender/blenkernel/intern/fcurve.c
===================================================================
--- trunk/blender/source/blender/blenkernel/intern/fcurve.c	2012-09-11 01:30:05 UTC (rev 50516)
+++ trunk/blender/source/blender/blenkernel/intern/fcurve.c	2012-09-11 02:18:27 UTC (rev 50517)
@@ -74,12 +74,10 @@
 {
 	if (fcu == NULL) 
 		return;
-	
+
 	/* free curve data */
-	if (fcu) {
-		if (fcu->bezt) MEM_freeN(fcu->bezt);
-		if (fcu->fpt) MEM_freeN(fcu->fpt);
-	}
+	if (fcu->bezt) MEM_freeN(fcu->bezt);
+	if (fcu->fpt)  MEM_freeN(fcu->fpt);
 	
 	/* free RNA-path, as this were allocated when getting the path string */
 	if (fcu->rna_path)

Modified: trunk/blender/source/blender/blenkernel/intern/softbody.c
===================================================================
--- trunk/blender/source/blender/blenkernel/intern/softbody.c	2012-09-11 01:30:05 UTC (rev 50516)
+++ trunk/blender/source/blender/blenkernel/intern/softbody.c	2012-09-11 02:18:27 UTC (rev 50517)
@@ -2291,7 +2291,7 @@
 			/* done goal stuff */
 
 			/* gravitation */
-			if (sb && scene->physics_settings.flag & PHYS_GLOBAL_GRAVITY) {
+			if (scene->physics_settings.flag & PHYS_GLOBAL_GRAVITY) {
 				float gravity[3];
 				copy_v3_v3(gravity, scene->physics_settings.gravity);
 				mul_v3_fl(gravity, sb_grav_force_scale(ob)*_final_mass(ob, bp)*sb->effector_weights->global_gravity); /* individual mass of node here */

Modified: trunk/blender/source/blender/blenlib/intern/scanfill.c
===================================================================
--- trunk/blender/source/blender/blenlib/intern/scanfill.c	2012-09-11 01:30:05 UTC (rev 50516)
+++ trunk/blender/source/blender/blenlib/intern/scanfill.c	2012-09-11 02:18:27 UTC (rev 50517)
@@ -423,12 +423,16 @@
 
 	for (eve = sf_ctx->fillvertbase.first; eve; eve = eve->next) {
 		if (eve->h == 1) {
-			/* find the edge which has vertex eve */
-			ed1 = sf_ctx->filledgebase.first;
-			while (ed1) {
-				if (ed1->v1 == eve || ed1->v2 == eve) break;
-				ed1 = ed1->next;
+			/* find the edge which has vertex eve,
+			 * note: we _know_ this will crash if 'ed1' becomes NULL
+			 * but this will never happen. */
+			for (ed1 = sf_ctx->filledgebase.first;
+			     !(ed1->v1 == eve || ed1->v2 == eve);
+			     ed1 = ed1->next)
+			{
+				/* do nothing */
 			}
+
 			if (ed1->v1 == eve) {
 				ed1->v1 = ed1->v2;
 				ed1->v2 = eve;

Modified: trunk/blender/source/blender/editors/animation/keyframing.c
===================================================================
--- trunk/blender/source/blender/editors/animation/keyframing.c	2012-09-11 01:30:05 UTC (rev 50516)
+++ trunk/blender/source/blender/editors/animation/keyframing.c	2012-09-11 02:18:27 UTC (rev 50517)
@@ -164,10 +164,7 @@
 	 *	- add if not found and allowed to add one
 	 *		TODO: add auto-grouping support? how this works will need to be resolved
 	 */
-	if (act)
-		fcu = list_find_fcurve(&act->curves, rna_path, array_index);
-	else
-		fcu = NULL;
+	fcu = list_find_fcurve(&act->curves, rna_path, array_index);
 	
 	if ((fcu == NULL) && (add)) {
 		/* use default settings to make a F-Curve */

Modified: trunk/blender/source/blender/editors/mesh/editmesh_bvh.c
===================================================================
--- trunk/blender/source/blender/editors/mesh/editmesh_bvh.c	2012-09-11 01:30:05 UTC (rev 50516)
+++ trunk/blender/source/blender/editors/mesh/editmesh_bvh.c	2012-09-11 02:18:27 UTC (rev 50517)
@@ -398,11 +398,6 @@
 	float end[3];
 	const float mval_f[2] = {ar->winx / 2.0f,
 	                         ar->winy / 2.0f};
-	
-	if (!ar) {
-		printf("error in BMBVH_EdgeVisible!\n");
-		return 0;
-	}
 
 	ED_view3d_win_to_segment_clip(ar, v3d, mval_f, origin, end);
 	

Modified: trunk/blender/source/blender/editors/mesh/editmesh_select.c
===================================================================
--- trunk/blender/source/blender/editors/mesh/editmesh_select.c	2012-09-11 01:30:05 UTC (rev 50516)
+++ trunk/blender/source/blender/editors/mesh/editmesh_select.c	2012-09-11 02:18:27 UTC (rev 50517)
@@ -268,11 +268,14 @@
 	
 	/* grab mask */
 	bufmask = view3d_read_backbuf(vc, xmin, ymin, xmax, ymax);
-	drm = bufmask->rect;
+
 	if (bufmask == NULL) {
 		return 0; /* only when mem alloc fails, go crash somewhere else! */
 	}
-	
+	else {
+		drm = bufmask->rect;
+	}
+
 	/* build selection lookup */
 	selbuf = MEM_callocN(bm_vertoffs + 1, "selbuf");
 	

Modified: trunk/blender/source/blender/editors/physics/particle_edit.c
===================================================================
--- trunk/blender/source/blender/editors/physics/particle_edit.c	2012-09-11 01:30:05 UTC (rev 50516)
+++ trunk/blender/source/blender/editors/physics/particle_edit.c	2012-09-11 02:18:27 UTC (rev 50517)
@@ -4135,7 +4135,7 @@
 	if (cache && cache->flag & PTCACHE_DISK_CACHE)
 		return;
 
-	if (psys == NULL && cache->mem_cache.first == NULL)
+	if (psys == NULL && (cache && cache->mem_cache.first == NULL))
 		return;
 
 	if (!edit) {

Modified: trunk/blender/source/blender/editors/transform/transform_conversions.c
===================================================================
--- trunk/blender/source/blender/editors/transform/transform_conversions.c	2012-09-11 01:30:05 UTC (rev 50516)
+++ trunk/blender/source/blender/editors/transform/transform_conversions.c	2012-09-11 02:18:27 UTC (rev 50517)
@@ -861,7 +861,7 @@
 	data->rootbone = 0; /* watch-it! has to be 0 here, since we're still on the same bone for the first time through the loop [#25885] */
 	
 	/* we only include bones that are part of a continual connected chain */
-	while (pchan) {
+	do {
 		/* here, we set ik-settings for bone from pchan->protectflag */
 		// XXX: careful with quats/axis-angle rotations where we're locking 4d components
 		if (pchan->protectflag & OB_LOCK_ROTX) pchan->ikflag |= BONE_IK_NO_XDOF_TEMP;
@@ -876,7 +876,7 @@
 			pchan = pchan->parent;
 		else
 			pchan = NULL;
-	}
+	} while (pchan);
 
 	/* make a copy of maximum chain-length */
 	data->max_rootbone = data->rootbone;

Modified: trunk/blender/source/gameengine/Rasterizer/RAS_MeshObject.cpp
===================================================================
--- trunk/blender/source/gameengine/Rasterizer/RAS_MeshObject.cpp	2012-09-11 01:30:05 UTC (rev 50516)
+++ trunk/blender/source/gameengine/Rasterizer/RAS_MeshObject.cpp	2012-09-11 02:18:27 UTC (rev 50517)
@@ -536,18 +536,18 @@
 		const MT_Vector3 pnorm(transform.getBasis()[2]);
 		// unneeded: const MT_Scalar pval = transform.getOrigin()[2];
 
-		vector<polygonSlot> slots(totpoly);
+		vector<polygonSlot> poly_slots(totpoly);
 
 		/* get indices and z into temporary array */
 		for (j=0; j<totpoly; j++)
-			slots[j].get(it.vertex, it.index, j*nvert, nvert, pnorm);
+			poly_slots[j].get(it.vertex, it.index, j*nvert, nvert, pnorm);
 
 		/* sort (stable_sort might be better, if flickering happens?) */
-		std::sort(slots.begin(), slots.end(), backtofront());
+		std::sort(poly_slots.begin(), poly_slots.end(), backtofront());
 
 		/* get indices from temporary array again */
 		for (j=0; j<totpoly; j++)
-			slots[j].set(it.index, j*nvert, nvert);
+			poly_slots[j].set(it.index, j*nvert, nvert);
 	}
 }
 




More information about the Bf-blender-cvs mailing list