diff options
author | Campbell Barton <ideasman42@gmail.com> | 2011-02-13 06:21:27 +0300 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2011-02-13 06:21:27 +0300 |
commit | 867fc4b463ef39ea16103f18f332c3d259624d29 (patch) | |
tree | 7d20c416241afb7b878b767a9955e284d3cddbe2 /source/blender/modifiers | |
parent | 9e03a0d4762b4734fe7ccb20e03b4a3c8f939620 (diff) |
enforce string limits (reported by pedantic checking tools & some developers).
mostly replace strcpy with BLI_strncpy and multiple strcat's with a BLI_snprintf().
also fix possible crash if CWD isnt available.
Diffstat (limited to 'source/blender/modifiers')
-rw-r--r-- | source/blender/modifiers/intern/MOD_collision.c | 9 | ||||
-rw-r--r-- | source/blender/modifiers/intern/MOD_explode.c | 5 | ||||
-rw-r--r-- | source/blender/modifiers/intern/MOD_fluidsim_util.c | 5 | ||||
-rw-r--r-- | source/blender/modifiers/intern/MOD_mask.c | 2 | ||||
-rw-r--r-- | source/blender/modifiers/intern/MOD_screw.c | 10 | ||||
-rw-r--r-- | source/blender/modifiers/intern/MOD_shapekey.c | 5 | ||||
-rw-r--r-- | source/blender/modifiers/intern/MOD_shrinkwrap.c | 4 | ||||
-rw-r--r-- | source/blender/modifiers/intern/MOD_simpledeform.c | 3 | ||||
-rw-r--r-- | source/blender/modifiers/intern/MOD_surface.c | 2 |
9 files changed, 24 insertions, 21 deletions
diff --git a/source/blender/modifiers/intern/MOD_collision.c b/source/blender/modifiers/intern/MOD_collision.c index 8decb460d6a..bdc0f0ea2e9 100644 --- a/source/blender/modifiers/intern/MOD_collision.c +++ b/source/blender/modifiers/intern/MOD_collision.c @@ -110,8 +110,6 @@ static void deformVerts(ModifierData *md, Object *ob, { CollisionModifierData *collmd = (CollisionModifierData*) md; DerivedMesh *dm = NULL; - float current_time = 0; - unsigned int numverts = 0, i = 0; MVert *tempVert = NULL; /* if possible use/create DerivedMesh */ @@ -126,6 +124,9 @@ static void deformVerts(ModifierData *md, Object *ob, if(dm) { + float current_time = 0; + unsigned int numverts = 0; + CDDM_apply_vert_coords(dm, vertexCos); CDDM_calc_normals(dm); @@ -137,7 +138,9 @@ static void deformVerts(ModifierData *md, Object *ob, numverts = dm->getNumVerts ( dm ); if((current_time > collmd->time)|| (BKE_ptcache_get_continue_physics())) - { + { + unsigned int i; + // check if mesh has changed if(collmd->x && (numverts != collmd->numverts)) freeData((ModifierData *)collmd); diff --git a/source/blender/modifiers/intern/MOD_explode.c b/source/blender/modifiers/intern/MOD_explode.c index a0765b56808..8c3b4f7db47 100644 --- a/source/blender/modifiers/intern/MOD_explode.c +++ b/source/blender/modifiers/intern/MOD_explode.c @@ -128,11 +128,10 @@ static void createFacepa(ExplodeModifierData *emd, /* set protected verts */ if(emd->vgroup){ MDeformVert *dvert = dm->getVertDataArray(dm, CD_MDEFORMVERT); - float val; if(dvert){ - int defgrp_index= emd->vgroup-1; + const int defgrp_index= emd->vgroup-1; for(i=0; i<totvert; i++, dvert++){ - val = BLI_frand(); + float val = BLI_frand(); val = (1.0f-emd->protect)*val + emd->protect*0.5f; if(val < defvert_find_weight(dvert, defgrp_index)) vertpa[i] = -1; diff --git a/source/blender/modifiers/intern/MOD_fluidsim_util.c b/source/blender/modifiers/intern/MOD_fluidsim_util.c index eb556e31aba..7d5c9a0ec13 100644 --- a/source/blender/modifiers/intern/MOD_fluidsim_util.c +++ b/source/blender/modifiers/intern/MOD_fluidsim_util.c @@ -459,7 +459,7 @@ DerivedMesh *fluidsim_read_cache(DerivedMesh *orgdm, FluidsimModifierData *fluid displaymode = fss->renderDisplayMode; } - strncpy(targetDir, fss->surfdataPath, FILE_MAXDIR); + BLI_strncpy(targetDir, fss->surfdataPath, sizeof(targetDir)); // use preview or final mesh? if(displaymode==1) @@ -479,8 +479,7 @@ DerivedMesh *fluidsim_read_cache(DerivedMesh *orgdm, FluidsimModifierData *fluid BLI_path_abs(targetDir, G.main->name); BLI_path_frame(targetDir, curFrame, 0); // fixed #frame-no - strcpy(targetFile,targetDir); - strcat(targetFile, ".bobj.gz"); + BLI_snprintf(targetFile, sizeof(targetFile), "%s.bobj.gz", targetDir); dm = fluidsim_read_obj(targetFile); diff --git a/source/blender/modifiers/intern/MOD_mask.c b/source/blender/modifiers/intern/MOD_mask.c index b2f2c86c46d..a8a48eb720f 100644 --- a/source/blender/modifiers/intern/MOD_mask.c +++ b/source/blender/modifiers/intern/MOD_mask.c @@ -53,7 +53,7 @@ static void copyData(ModifierData *md, ModifierData *target) MaskModifierData *mmd = (MaskModifierData*) md; MaskModifierData *tmmd = (MaskModifierData*) target; - strcpy(tmmd->vgroup, mmd->vgroup); + BLI_strncpy(tmmd->vgroup, mmd->vgroup, sizeof(tmmd->vgroup)); tmmd->flag = mmd->flag; } diff --git a/source/blender/modifiers/intern/MOD_screw.c b/source/blender/modifiers/intern/MOD_screw.c index 7e8fad2801e..7bbb07eb658 100644 --- a/source/blender/modifiers/intern/MOD_screw.c +++ b/source/blender/modifiers/intern/MOD_screw.c @@ -433,15 +433,15 @@ static DerivedMesh *applyModifier(ModifierData *md, Object *ob, /* find the first vert */ vc= vert_connect; for (i=0; i < totvert; i++, vc++) { - int v_best=-1, ed_loop_closed=0; /* vert and vert new */ - int ed_loop_flip= 0; /* compiler complains if not initialized, but it should be initialized below */ - float fl= -1.0f; - ScrewVertIter lt_iter; - /* Now do search for connected verts, order all edges and flip them * so resulting faces are flipped the right way */ vc_tot_linked= 0; /* count the number of linked verts for this loop */ if (vc->flag == 0) { + int v_best=-1, ed_loop_closed=0; /* vert and vert new */ + ScrewVertIter lt_iter; + int ed_loop_flip= 0; /* compiler complains if not initialized, but it should be initialized below */ + float fl= -1.0f; + /*printf("Loop on connected vert: %i\n", i);*/ for(j=0; j<2; j++) { diff --git a/source/blender/modifiers/intern/MOD_shapekey.c b/source/blender/modifiers/intern/MOD_shapekey.c index e03783e8eeb..874efd77c9e 100644 --- a/source/blender/modifiers/intern/MOD_shapekey.c +++ b/source/blender/modifiers/intern/MOD_shapekey.c @@ -70,11 +70,12 @@ static void deformMatrices(ModifierData *md, Object *ob, DerivedMesh *derivedDat Key *key= ob_get_key(ob); KeyBlock *kb= ob_get_keyblock(ob); float scale[3][3]; - int a; (void)vertexCos; /* unused */ if(kb && kb->totelem==numVerts && kb!=key->refkey) { + int a; + if(ob->shapeflag & OB_SHAPE_LOCK) scale_m3_fl(scale, 1); else scale_m3_fl(scale, kb->curval); @@ -107,11 +108,11 @@ static void deformMatricesEM(ModifierData *UNUSED(md), Object *ob, Key *key= ob_get_key(ob); KeyBlock *kb= ob_get_keyblock(ob); float scale[3][3]; - int a; (void)vertexCos; /* unused */ if(kb && kb->totelem==numVerts && kb!=key->refkey) { + int a; scale_m3_fl(scale, kb->curval); for(a=0; a<numVerts; a++) diff --git a/source/blender/modifiers/intern/MOD_shrinkwrap.c b/source/blender/modifiers/intern/MOD_shrinkwrap.c index 56a5b4b8577..c7f15a94bf2 100644 --- a/source/blender/modifiers/intern/MOD_shrinkwrap.c +++ b/source/blender/modifiers/intern/MOD_shrinkwrap.c @@ -32,9 +32,9 @@ #include <string.h> +#include "BLI_string.h" #include "BLI_utildefines.h" - #include "BKE_cdderivedmesh.h" #include "BKE_modifier.h" #include "BKE_shrinkwrap.h" @@ -65,7 +65,7 @@ static void copyData(ModifierData *md, ModifierData *target) tsmd->target = smd->target; tsmd->auxTarget = smd->auxTarget; - strcpy(tsmd->vgroup_name, smd->vgroup_name); + BLI_strncpy(tsmd->vgroup_name, smd->vgroup_name, sizeof(tsmd->vgroup_name)); tsmd->keepDist = smd->keepDist; tsmd->shrinkType= smd->shrinkType; diff --git a/source/blender/modifiers/intern/MOD_simpledeform.c b/source/blender/modifiers/intern/MOD_simpledeform.c index 1c3e40a4193..7c95b460838 100644 --- a/source/blender/modifiers/intern/MOD_simpledeform.c +++ b/source/blender/modifiers/intern/MOD_simpledeform.c @@ -34,6 +34,7 @@ #include "DNA_object_types.h" #include "BLI_math.h" +#include "BLI_string.h" #include "BLI_utildefines.h" #include "BKE_cdderivedmesh.h" @@ -288,7 +289,7 @@ static void copyData(ModifierData *md, ModifierData *target) tsmd->originOpts= smd->originOpts; tsmd->factor= smd->factor; memcpy(tsmd->limit, smd->limit, sizeof(tsmd->limit)); - strcpy(tsmd->vgroup_name, smd->vgroup_name); + BLI_strncpy(tsmd->vgroup_name, smd->vgroup_name, sizeof(tsmd->vgroup_name)); } static CustomDataMask requiredDataMask(Object *UNUSED(ob), ModifierData *md) diff --git a/source/blender/modifiers/intern/MOD_surface.c b/source/blender/modifiers/intern/MOD_surface.c index 8d6f6954e18..b5d25d8e146 100644 --- a/source/blender/modifiers/intern/MOD_surface.c +++ b/source/blender/modifiers/intern/MOD_surface.c @@ -91,7 +91,6 @@ static void deformVerts(ModifierData *md, Object *ob, int UNUSED(isFinalCalc)) { SurfaceModifierData *surmd = (SurfaceModifierData*) md; - unsigned int numverts = 0, i = 0; if(surmd->dm) surmd->dm->release(surmd->dm); @@ -108,6 +107,7 @@ static void deformVerts(ModifierData *md, Object *ob, if(surmd->dm) { + unsigned int numverts = 0, i = 0; int init = 0; float *vec; MVert *x, *v; |