From 0abe1911d57b4d4a806a5de6f8cdf4f421abb7cf Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Fri, 16 Sep 2011 06:47:01 +0000 Subject: - fix for access past the buffer size (paint / sculpt used some 2d vecs as 3d) - remove redundant NULL checks on old code where it would crash if the result was NULL later on. - add some missing NULL checks. --- .../blender/editors/interface/interface_regions.c | 2 +- source/blender/editors/object/object_modifier.c | 2 +- source/blender/editors/sculpt_paint/paint_image.c | 2 +- source/blender/editors/sculpt_paint/paint_stroke.c | 13 ++++++----- source/blender/editors/sculpt_paint/sculpt.c | 2 +- source/blender/editors/space_file/file_ops.c | 27 ++++++++++++---------- source/blender/gpu/intern/gpu_extensions.c | 3 +-- source/blender/imbuf/intern/filter.c | 2 +- source/blender/imbuf/intern/iris.c | 13 ++++++----- source/blender/makesrna/intern/rna_texture_api.c | 2 +- source/blender/render/intern/source/shadeinput.c | 3 ++- source/blender/render/intern/source/zbuf.c | 2 +- 12 files changed, 39 insertions(+), 34 deletions(-) diff --git a/source/blender/editors/interface/interface_regions.c b/source/blender/editors/interface/interface_regions.c index a55ee01202c..f31c16cd020 100644 --- a/source/blender/editors/interface/interface_regions.c +++ b/source/blender/editors/interface/interface_regions.c @@ -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; diff --git a/source/blender/editors/object/object_modifier.c b/source/blender/editors/object/object_modifier.c index 8813b0027cd..17f174a5069 100644 --- a/source/blender/editors/object/object_modifier.c +++ b/source/blender/editors/object/object_modifier.c @@ -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; diff --git a/source/blender/editors/sculpt_paint/paint_image.c b/source/blender/editors/sculpt_paint/paint_image.c index 79a3251cdf1..7f563b1c80c 100644 --- a/source/blender/editors/sculpt_paint/paint_image.c +++ b/source/blender/editors/sculpt_paint/paint_image.c @@ -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]; diff --git a/source/blender/editors/sculpt_paint/paint_stroke.c b/source/blender/editors/sculpt_paint/paint_stroke.c index 9500c7f663c..73a6e4fad20 100644 --- a/source/blender/editors/sculpt_paint/paint_stroke.c +++ b/source/blender/editors/sculpt_paint/paint_stroke.c @@ -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) diff --git a/source/blender/editors/sculpt_paint/sculpt.c b/source/blender/editors/sculpt_paint/sculpt.c index 92bc60e8b77..0bdb027a903 100644 --- a/source/blender/editors/sculpt_paint/sculpt.c +++ b/source/blender/editors/sculpt_paint/sculpt.c @@ -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; } } diff --git a/source/blender/editors/space_file/file_ops.c b/source/blender/editors/space_file/file_ops.c index 1b0893e50e0..43d5a5c9b4b 100644 --- a/source/blender/editors/space_file/file_ops.c +++ b/source/blender/editors/space_file/file_ops.c @@ -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); } diff --git a/source/blender/gpu/intern/gpu_extensions.c b/source/blender/gpu/intern/gpu_extensions.c index fb9f21cde8c..9cd6240d37d 100644 --- a/source/blender/gpu/intern/gpu_extensions.c +++ b/source/blender/gpu/intern/gpu_extensions.c @@ -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; } diff --git a/source/blender/imbuf/intern/filter.c b/source/blender/imbuf/intern/filter.c index 2677913caed..3719242aaba 100644 --- a/source/blender/imbuf/intern/filter.c +++ b/source/blender/imbuf/intern/filter.c @@ -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++; diff --git a/source/blender/imbuf/intern/iris.c b/source/blender/imbuf/intern/iris.c index adbf3659d3a..c6aaf336fb7 100644 --- a/source/blender/imbuf/intern/iris.c +++ b/source/blender/imbuf/intern/iris.c @@ -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); diff --git a/source/blender/makesrna/intern/rna_texture_api.c b/source/blender/makesrna/intern/rna_texture_api.c index 8c63d5da8fd..4941c75c400 100644 --- a/source/blender/makesrna/intern/rna_texture_api.c +++ b/source/blender/makesrna/intern/rna_texture_api.c @@ -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); diff --git a/source/blender/render/intern/source/shadeinput.c b/source/blender/render/intern/source/shadeinput.c index 128900d1fd2..d8231c7e7d4 100644 --- a/source/blender/render/intern/source/shadeinput.c +++ b/source/blender/render/intern/source/shadeinput.c @@ -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); + } } diff --git a/source/blender/render/intern/source/zbuf.c b/source/blender/render/intern/source/zbuf.c index ba922620ee1..b8fbd5c44f7 100644 --- a/source/blender/render/intern/source/zbuf.c +++ b/source/blender/render/intern/source/zbuf.c @@ -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; -- cgit v1.2.3