- fix for access past the buffer size (paint / sculpt used some 2d vecs as 3d)
authorCampbell Barton <ideasman42@gmail.com>
Fri, 16 Sep 2011 06:47:01 +0000 (06:47 +0000)
committerCampbell Barton <ideasman42@gmail.com>
Fri, 16 Sep 2011 06:47:01 +0000 (06:47 +0000)
- remove redundant NULL checks on old code where it would crash if the result was NULL later on.
- add some missing NULL checks.

12 files changed:
source/blender/editors/interface/interface_regions.c
source/blender/editors/object/object_modifier.c
source/blender/editors/sculpt_paint/paint_image.c
source/blender/editors/sculpt_paint/paint_stroke.c
source/blender/editors/sculpt_paint/sculpt.c
source/blender/editors/space_file/file_ops.c
source/blender/gpu/intern/gpu_extensions.c
source/blender/imbuf/intern/filter.c
source/blender/imbuf/intern/iris.c
source/blender/makesrna/intern/rna_texture_api.c
source/blender/render/intern/source/shadeinput.c
source/blender/render/intern/source/zbuf.c

index a55ee01..f31c16c 100644 (file)
@@ -1235,7 +1235,7 @@ static void ui_block_position(wmWindow *window, ARegion *butregion, uiBut *but,
        ysize= block->maxy - block->miny+4;
        /*aspect/= (float)xsize;*/ /*UNUSED*/
 
-       if(but) {
+       {
                int left=0, right=0, top=0, down=0;
                int winx, winy;
                // int offscreen;
index 8813b00..17f174a 100644 (file)
@@ -724,7 +724,7 @@ static int modifier_remove_exec(bContext *C, wmOperator *op)
        Scene *scene= CTX_data_scene(C);
        Object *ob = ED_object_active_context(C);
        ModifierData *md = edit_modifier_property_get(op, ob, 0);
-       int mode_orig = ob->mode;
+       int mode_orig = ob ? ob->mode : 0;
        
        if(!ob || !md || !ED_object_modifier_remove(op->reports, bmain, scene, ob, md))
                return OPERATOR_CANCELLED;
index 79a3251..7f563b1 100644 (file)
@@ -749,7 +749,7 @@ static int project_paint_occlude_ptv(float pt[3], float v1[3], float v2[3], floa
 
 static int project_paint_occlude_ptv_clip(
                const ProjPaintState *ps, const MFace *mf,
-               float pt[3], float v1[3], float v2[3], float v3[3],
+               float pt[3], float v1[4], float v2[4], float v3[4],
                const int side )
 {
        float w[3], wco[3];
index 9500c7f..73a6e4f 100644 (file)
@@ -683,7 +683,7 @@ static void paint_brush_stroke_add_step(bContext *C, wmOperator *op, wmEvent *ev
        /* TODO: as sculpt and other paint modes are unified, this
           separation will go away */
        if(stroke->vc.obact->sculpt) {
-               float delta[3];
+               float delta[2];
 
                brush_jitter_pos(brush, mouse_in, mouse);
 
@@ -691,13 +691,14 @@ static void paint_brush_stroke_add_step(bContext *C, wmOperator *op, wmEvent *ev
                   brush_jitter_pos isn't written in the best way to
                   be reused here */
                if(brush->flag & BRUSH_JITTER_PRESSURE) {
-                       sub_v3_v3v3(delta, mouse, mouse_in);
-                       mul_v3_fl(delta, pressure);
-                       add_v3_v3v3(mouse, mouse_in, delta);
+                       sub_v2_v2v2(delta, mouse, mouse_in);
+                       mul_v2_fl(delta, pressure);
+                       add_v2_v2v2(mouse, mouse_in, delta);
                }
        }
-       else
-               copy_v3_v3(mouse, mouse_in);
+       else {
+               copy_v2_v2(mouse, mouse_in);
+       }
 
        /* TODO: can remove the if statement once all modes have this */
        if(stroke->get_location)
index 92bc60e..0bdb027 100644 (file)
@@ -2996,7 +2996,7 @@ static void sculpt_update_brush_delta(Sculpt *sd, Object *ob, Brush *brush)
                        copy_v3_v3(cache->true_location, cache->orig_grab_location);
 
                        sd->draw_anchored = 1;
-                       copy_v3_v3(sd->anchored_initial_mouse, cache->initial_mouse);
+                       copy_v2_v2(sd->anchored_initial_mouse, cache->initial_mouse);
                        sd->anchored_size = cache->pixel_radius;
                }
        }
index 1b0893e..43d5a5c 100644 (file)
@@ -164,22 +164,26 @@ static FileSelect file_select_do(bContext* C, int selected_idx)
        SpaceFile *sfile= CTX_wm_space_file(C);
        FileSelectParams *params = ED_fileselect_get_params(sfile);
        int numfiles = filelist_numfiles(sfile->files);
+       struct direntry* file;
 
        /* make the selected file active */
-       if ( (selected_idx >= 0) && (selected_idx < numfiles)) {
-               struct direntry* file = filelist_file(sfile->files, selected_idx);
+       if (            (selected_idx >= 0) &&
+                   (selected_idx < numfiles) &&
+                   (file= filelist_file(sfile->files, selected_idx)))
+       {
                params->active_file = selected_idx;
 
-               if(file && S_ISDIR(file->type)) {
+               if(S_ISDIR(file->type)) {
                        /* the path is too long and we are not going up! */
-                       if (strcmp(file->relname, "..") && strlen(params->dir) + strlen(file->relname) >= FILE_MAX ) 
-                       {
+                       if (strcmp(file->relname, "..") && strlen(params->dir) + strlen(file->relname) >= FILE_MAX )  {
                                // XXX error("Path too long, cannot enter this directory");
-                       } else {
-                               if (strcmp(file->relname, "..")==0) {    
-                                       /* avoids /../../ */     
-                                       BLI_parent_dir(params->dir);     
-                               } else {
+                       }
+                       else {
+                               if (strcmp(file->relname, "..")==0) {
+                                       /* avoids /../../ */
+                                       BLI_parent_dir(params->dir);
+                               }
+                               else {
                                        BLI_cleanup_dir(G.main->name, params->dir);
                                        strcat(params->dir, file->relname);
                                        BLI_add_slash(params->dir);
@@ -189,8 +193,7 @@ static FileSelect file_select_do(bContext* C, int selected_idx)
                                retval = FILE_SELECT_DIR;
                        }
                }
-               else if (file)
-               {
+               else  {
                        if (file->relname) {
                                BLI_strncpy(params->file, file->relname, FILE_MAXFILE);
                        }
index fb9f21c..9cd6240 100644 (file)
@@ -514,8 +514,7 @@ GPUTexture *GPU_texture_create_3D(int w, int h, int depth, float *fpixels)
        if (pixels)
                MEM_freeN(pixels);
 
-       if (tex)
-               GPU_texture_unbind(tex);
+       GPU_texture_unbind(tex);
 
        return tex;
 }
index 2677913..3719242 100644 (file)
@@ -518,7 +518,7 @@ void IMB_makemipmap(ImBuf *ibuf, int use_filter)
                hbuf= ibuf->mipmap[curmap];
                hbuf->miplevel= curmap+1;
 
-               if(!hbuf || (hbuf->x <= 2 && hbuf->y <= 2))
+               if(hbuf->x <= 2 && hbuf->y <= 2)
                        break;
 
                curmap++;
index adbf365..c6aaf33 100644 (file)
@@ -515,14 +515,15 @@ struct ImBuf *imb_loadiris(unsigned char *mem, size_t size, int flags)
                
        }
 
-       ibuf->ftype = IMAGIC;
-       ibuf->profile = IB_PROFILE_SRGB;
-       
-       test_endian_zbuf(ibuf);
-       
        if (ibuf) {
-               if (ibuf->rect) 
+               ibuf->ftype = IMAGIC;
+               ibuf->profile = IB_PROFILE_SRGB;
+
+               test_endian_zbuf(ibuf);
+
+               if (ibuf->rect) {
                        IMB_convert_rgba_to_abgr(ibuf);
+               }
        }
 
        return(ibuf);
index 8c63d5d..4941c75 100644 (file)
@@ -68,7 +68,7 @@ void clear_envmap(struct EnvMap *env, bContext *C)
                }
 }
 
-void texture_evaluate(struct Tex *tex, float value[3], float color_r[3])
+void texture_evaluate(struct Tex *tex, float value[3], float color_r[4])
 {
        TexResult texres= {0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0, NULL};
        multitex_ext(tex, value, NULL, NULL, 1, &texres);
index 128900d..d8231c7 100644 (file)
@@ -1165,8 +1165,9 @@ void shade_input_set_shade_texco(ShadeInput *shi)
                                                shi->vcol[2]= 1.0f;
                                                shi->vcol[3]= 1.0f;
                                        }
-                                       if(tface && tface->tpage)
+                                       if(tface->tpage) {
                                                render_realtime_texture(shi, tface->tpage);
+                                       }
                                }
 
 
index ba92262..b8fbd5c 100644 (file)
@@ -239,7 +239,7 @@ static short cliptestf(float p, float q, float *u1, float *u2)
        return 1;
 }
 
-int testclip(const float v[3])
+int testclip(const float v[4])
 {
        float abs4;     /* WATCH IT: this function should do the same as cliptestf, otherwise troubles in zbufclip()*/
        short c=0;