code cleanup/bugfix uninitialized values
authorCampbell Barton <ideasman42@gmail.com>
Mon, 12 Mar 2012 06:53:47 +0000 (06:53 +0000)
committerCampbell Barton <ideasman42@gmail.com>
Mon, 12 Mar 2012 06:53:47 +0000 (06:53 +0000)
- edgebisect bmesh operator used uninialized beauty field.
- BLI_join_dirfile could read from before the string bounds when passed an empty dir string.
- pransform could use an uninitialized projected coordinate (unlikely but possible)
- RNA_property_path_from_ID_check would compare against an uninitialized pointer when the path wasn't found.

also have bmesh walker use BM_edge_other_vert() utility function.

source/blender/blenlib/intern/path_util.c
source/blender/bmesh/intern/bmesh_walkers_impl.c
source/blender/bmesh/operators/bmo_subdivide.c
source/blender/editors/transform/transform.c
source/blender/editors/transform/transform.h
source/blender/makesrna/intern/rna_access.c

index 0d251133e0d4efd2da3e5d9e3c4660192eb833f2..dccec7a6a42776b5b0350edaee18f23c52661946 100644 (file)
@@ -1523,9 +1523,9 @@ void BLI_join_dirfile(char *dst, const size_t maxlen, const char *dir, const cha
        }
 
        /* inline BLI_add_slash */
-       if (dst[dirlen - 1] != SEP) {
-               dst[dirlen++]= SEP;
-               dst[dirlen  ]= '\0';
+       if ((dirlen > 0) && (dst[dirlen - 1] != SEP)) {
+               dst[dirlen++] = SEP;
+               dst[dirlen  ] = '\0';
        }
 
        if (dirlen >= maxlen) {
index cd815c9be83121930aec1875f3c29a95294a1e02..23d82f0ab3460004b0bee041d90aade419ad956c 100644 (file)
@@ -256,8 +256,7 @@ static void *bmw_IslandboundWalker_step(BMWalker *walker)
 
        owalk = *iwalk;
 
-       if (iwalk->lastv == e->v1) v = e->v2;
-       else v = e->v1;
+       v = BM_edge_other_vert(e, iwalk->lastv);
 
        if (!BM_vert_is_manifold(walker->bm, v)) {
                BMW_reset(walker);
@@ -411,10 +410,7 @@ static void bmw_LoopWalker_begin(BMWalker *walker, void *data)
        lwalk = BMW_state_add(walker);
        *lwalk = owalk;
 
-       if (lwalk->lastv == owalk.cur->v1) lwalk->lastv = owalk.cur->v2;
-       else lwalk->lastv = owalk.cur->v1;
-
-       lwalk->startv = lwalk->lastv;
+       lwalk->lastv = lwalk->startv = BM_edge_other_vert(owalk.cur, lwalk->lastv);
 
        BLI_ghash_free(walker->visithash, NULL, NULL);
        walker->visithash = BLI_ghash_new(BLI_ghashutil_ptrhash, BLI_ghashutil_ptrcmp, "bmesh walkers 2");
@@ -625,8 +621,9 @@ static void *bmw_FaceLoopWalker_step(BMWalker *walker)
 
        l = l->radial_next;
        
-       if (lwalk->nocalc)
+       if (lwalk->nocalc) {
                return f;
+       }
 
        if (!bmw_FaceLoopWalker_include_face(walker, l)) {
                l = lwalk->l;
index 9a6d9e7b8369f46f4df8d5997b8e235e2c02be6d..24f9c1e99373b3968ee898d6de10db88f2924b52 100644 (file)
@@ -1080,10 +1080,10 @@ void bmo_edgebisect_exec(BMesh *bm, BMOperator *op)
 {
        BMOIter siter;
        BMEdge *e;
-       SubDParams params;
+       SubDParams params = {0};
        int skey;
        
-       params.numcuts = BMO_slot_get(op, "numcuts")->data.i;
+       params.numcuts = BMO_slot_int_get(op, "numcuts");
        params.op = op;
        
        BM_data_layer_add(bm, &bm->vdata, CD_SHAPEKEY);
index 7b98a2f00831be63203a103655b7b28feb5cea6b..4334d323737db0578ff0842d59d8994ee5c23408 100644 (file)
@@ -136,28 +136,28 @@ static void convertViewVec2D(View2D *v2d, float vec[3], int dx, int dy)
        vec[2]= 0.0f;
 }
 
-void convertViewVec(TransInfo *t, float vec[3], int dx, int dy)
+void convertViewVec(TransInfo *t, float r_vec[3], int dx, int dy)
 {
        if ((t->spacetype == SPACE_VIEW3D) && (t->ar->regiontype == RGN_TYPE_WINDOW)) {
                float mval_f[2];
                mval_f[0] = dx;
                mval_f[1] = dy;
-               ED_view3d_win_to_delta(t->ar, mval_f, vec);
+               ED_view3d_win_to_delta(t->ar, mval_f, r_vec);
        }
        else if(t->spacetype==SPACE_IMAGE) {
                float aspx, aspy;
 
-               convertViewVec2D(t->view, vec, dx, dy);
+               convertViewVec2D(t->view, r_vec, dx, dy);
 
                ED_space_image_uv_aspect(t->sa->spacedata.first, &aspx, &aspy);
-               vec[0]*= aspx;
-               vec[1]*= aspy;
+               r_vec[0] *= aspx;
+               r_vec[1] *= aspy;
        }
        else if(ELEM(t->spacetype, SPACE_IPO, SPACE_NLA)) {
-               convertViewVec2D(t->view, vec, dx, dy);
+               convertViewVec2D(t->view, r_vec, dx, dy);
        }
        else if(ELEM(t->spacetype, SPACE_NODE, SPACE_SEQ)) {
-               convertViewVec2D(&t->ar->v2d, vec, dx, dy);
+               convertViewVec2D(&t->ar->v2d, r_vec, dx, dy);
        }
        else if(t->spacetype==SPACE_CLIP) {
                View2D *v2d = t->view;
@@ -166,17 +166,17 @@ void convertViewVec(TransInfo *t, float vec[3], int dx, int dy)
                divx= v2d->mask.xmax-v2d->mask.xmin;
                divy= v2d->mask.ymax-v2d->mask.ymin;
 
-               vec[0]= (v2d->cur.xmax-v2d->cur.xmin)*(dx)/divx;
-               vec[1]= (v2d->cur.ymax-v2d->cur.ymin)*(dy)/divy;
-               vec[2]= 0.0f;
+               r_vec[0] = (v2d->cur.xmax-v2d->cur.xmin)*(dx)/divx;
+               r_vec[1] = (v2d->cur.ymax-v2d->cur.ymin)*(dy)/divy;
+               r_vec[2] = 0.0f;
        }
        else {
                printf("%s: called in an invalid context\n", __func__);
-               zero_v3(vec);
+               zero_v3(r_vec);
        }
 }
 
-void projectIntView(TransInfo *t, float *vec, int *adr)
+void projectIntView(TransInfo *t, const float vec[3], int adr[2])
 {
        if (t->spacetype==SPACE_VIEW3D) {
                if(t->ar->regiontype == RGN_TYPE_WINDOW)
@@ -229,26 +229,31 @@ void projectIntView(TransInfo *t, float *vec, int *adr)
        }
 }
 
-void projectFloatView(TransInfo *t, float *vec, float *adr)
+void projectFloatView(TransInfo *t, const float vec[3], float adr[2])
 {
-       if (t->spacetype==SPACE_VIEW3D) {
-               if(t->ar->regiontype == RGN_TYPE_WINDOW)
-                       project_float_noclip(t->ar, vec, adr);
-       }
-       else if(ELEM(t->spacetype, SPACE_IMAGE, SPACE_CLIP)) {
-               int a[2];
-
-               projectIntView(t, vec, a);
-               adr[0]= a[0];
-               adr[1]= a[1];
+       switch (t->spacetype) {
+               case SPACE_VIEW3D:
+               {
+                       if (t->ar->regiontype == RGN_TYPE_WINDOW) {
+                               project_float_noclip(t->ar, vec, adr);
+                               return;
+                       }
+                       break;
+               }
+               case SPACE_IMAGE:
+               case SPACE_CLIP:
+               case SPACE_IPO:
+               case SPACE_NLA:
+               {
+                       int a[2];
+                       projectIntView(t, vec, a);
+                       adr[0] = a[0];
+                       adr[1] = a[1];
+                       return;
+               }
        }
-       else if(ELEM(t->spacetype, SPACE_IPO, SPACE_NLA)) {
-               int a[2];
 
-               projectIntView(t, vec, a);
-               adr[0]= a[0];
-               adr[1]= a[1];
-       }
+       zero_v2(adr);
 }
 
 void applyAspectRatio(TransInfo *t, float *vec)
index 48c05f00ea8f3253ffe28987fe2be767f896f1ae..0bef33149d7b2ef4823983f2fb0dbf8775cdbf0d 100644 (file)
@@ -444,9 +444,9 @@ void transformApply(struct bContext *C, TransInfo *t);
 int  transformEnd(struct bContext *C, TransInfo *t);
 
 void setTransformViewMatrices(TransInfo *t);
-void convertViewVec(TransInfo *t, float *vec, int dx, int dy);
-void projectIntView(TransInfo *t, float *vec, int *adr);
-void projectFloatView(TransInfo *t, float *vec, float *adr);
+void convertViewVec(TransInfo *t, float r_vec[3], int dx, int dy);
+void projectIntView(TransInfo *t, const float vec[3], int adr[2]);
+void projectFloatView(TransInfo *t, const float vec[3], float adr[2]);
 
 void applyAspectRatio(TransInfo *t, float *vec);
 void removeAspectRatio(TransInfo *t, float *vec);
index 2ccd7d293d3cb42c06e6fe8040556a24ed01e119..543824eb5d59c37bed7b067dc4584908355a8f85 100644 (file)
@@ -1430,8 +1430,12 @@ int RNA_property_path_from_ID_check(PointerRNA *ptr, PropertyRNA *prop)
                PropertyRNA *r_prop;
 
                RNA_id_pointer_create(ptr->id.data, &id_ptr);
-               RNA_path_resolve(&id_ptr, path, &r_ptr, &r_prop);
-               ret = (prop == r_prop);
+               if (RNA_path_resolve(&id_ptr, path, &r_ptr, &r_prop) == TRUE) {
+                       ret = (prop == r_prop);
+               }
+               else {
+                       ret = FALSE;
+               }
                MEM_freeN(path);
        }