add some missing NULL checks, a few parts of the code used a pointer then checked...
authorCampbell Barton <ideasman42@gmail.com>
Tue, 11 Sep 2012 02:18:27 +0000 (02:18 +0000)
committerCampbell Barton <ideasman42@gmail.com>
Tue, 11 Sep 2012 02:18:27 +0000 (02:18 +0000)
also made it more clear that some areas assume the pointer isnt null (remove redundant NULL checks).

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

index 0b4d4cd19e409f2d25687a001c8c377af074da69..5302ad9b4711ca1636127f8e9c171ff1a16789db 100644 (file)
@@ -774,7 +774,7 @@ class IMAGE_PT_paint_curve(BrushButtonsPanel, Panel):
         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'
index 06807dfcbad5b18750f5e02d0ae548819f7de095..f47ac641cf92f068063699d125bafb640dc4b5d7 100644 (file)
@@ -2595,7 +2595,7 @@ void dynamicPaint_outputSurfaceImage(DynamicPaintSurface *surface, char *filenam
        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 @@ static int dynamicPaint_doStep(Scene *scene, Object *ob, DynamicPaintSurface *su
        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 @@ static int dynamicPaint_doStep(Scene *scene, Object *ob, DynamicPaintSurface *su
                                        /* 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))
                                                {
 
index b78ab9b28cd2620f2f47fb3e8a2fa2a720309364..5fea74d52debee926fac09c0e248214363536a95 100644 (file)
@@ -74,12 +74,10 @@ void free_fcurve(FCurve *fcu)
 {
        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)
index 008dc332710596007b0ca3f36a6be5b90f733837..4a88bfbfdad717dccdc2c6b634d3813f449b64c0 100644 (file)
@@ -2291,7 +2291,7 @@ static int _softbody_calc_forces_slice_in_a_thread(Scene *scene, Object *ob, flo
                        /* 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 */
index 4ce718aeb1645a842efc5218ec4cedaee107283b..32afaba2b5ca387de684d50b2ca0b2227f235f74 100644 (file)
@@ -423,12 +423,16 @@ static void testvertexnearedge(ScanFillContext *sf_ctx)
 
        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;
index 3ef686910e6773950d06fd4026b2ec26bab1e9e0..8cd8cfaea51db7ae8807b40bd30026a3a13fe5ab 100644 (file)
@@ -164,10 +164,7 @@ FCurve *verify_fcurve(bAction *act, const char group[], PointerRNA *ptr,
         *      - 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 */
index 580592c02f68dabae4c575e101191c208724ec2b..0b7d396b69648d6a396647840335b4a5da5566b3 100644 (file)
@@ -398,11 +398,6 @@ int BMBVH_EdgeVisible(BMBVHTree *tree, BMEdge *e, ARegion *ar, View3D *v3d, Obje
        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);
        
index 3ac011550bea5c16532ae3686c49906420f51d9b..dc5d1cea4434738604f479087e07011cec6e8450 100644 (file)
@@ -268,11 +268,14 @@ int EDBM_backbuf_border_mask_init(ViewContext *vc, int mcords[][2], short tot, s
        
        /* 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");
        
index 3ed31abca942360e8be5fd52b4ba1eef929a04d6..b7ce32aa10a9924b89b43f0b0c268b57dcec8c53 100644 (file)
@@ -4135,7 +4135,7 @@ static void PE_create_particle_edit(Scene *scene, Object *ob, PointCache *cache,
        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) {
index e635c4b3fb8ab15a83363873acb80d69f0d3f095..c1859407789ebd0de2852df7e520252221762d6e 100644 (file)
@@ -861,7 +861,7 @@ static short pose_grab_with_ik_add(bPoseChannel *pchan)
        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 @@ static short pose_grab_with_ik_add(bPoseChannel *pchan)
                        pchan = pchan->parent;
                else
                        pchan = NULL;
-       }
+       } while (pchan);
 
        /* make a copy of maximum chain-length */
        data->max_rootbone = data->rootbone;
index 7da0be3a5069c82e2b4cc3f56e7c23f6044b6066..25afefbcc5a32062893df39019e9bf4541414ff1 100644 (file)
@@ -536,18 +536,18 @@ void RAS_MeshObject::SortPolygons(RAS_MeshSlot& ms, const MT_Transform &transfor
                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);
        }
 }