Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCampbell Barton <ideasman42@gmail.com>2011-12-09 12:20:27 +0400
committerCampbell Barton <ideasman42@gmail.com>2011-12-09 12:20:27 +0400
commitf025b7b51159cf3cdf49e9ec0eeaf4427010e1f7 (patch)
tree7f1995589018b4044553c201a738127eae24f1fe /source/blender/blenkernel/intern/deform.c
parent6a6c9fc160ef292e5949a27842cd4cae9653d346 (diff)
went over all uses of MDeformWeight.def_nr and made sure the value is clamped when used as an array index.
Diffstat (limited to 'source/blender/blenkernel/intern/deform.c')
-rw-r--r--source/blender/blenkernel/intern/deform.c28
1 files changed, 16 insertions, 12 deletions
diff --git a/source/blender/blenkernel/intern/deform.c b/source/blender/blenkernel/intern/deform.c
index e5176663228..94be15e27c0 100644
--- a/source/blender/blenkernel/intern/deform.c
+++ b/source/blender/blenkernel/intern/deform.c
@@ -161,12 +161,14 @@ void defvert_sync_mapped(MDeformVert *dvert_dst, const MDeformVert *dvert_src,
}
/* be sure all flip_map values are valid */
-void defvert_remap(MDeformVert *dvert, int *map)
+void defvert_remap(MDeformVert *dvert, int *map, const int map_len)
{
MDeformWeight *dw;
int i;
for (i=0, dw=dvert->dw; i<dvert->totweight; i++, dw++) {
- dw->def_nr= map[dw->def_nr];
+ if (dw->def_nr < map_len) {
+ dw->def_nr= map[dw->def_nr];
+ }
}
}
@@ -198,8 +200,10 @@ void defvert_flip(MDeformVert *dvert, const int *flip_map, const int flip_map_le
int i;
for (dw= dvert->dw, i=0; i<dvert->totweight; dw++, i++) {
- if ((dw->def_nr < flip_map_len) && (flip_map[dw->def_nr] >= 0)) {
- dw->def_nr= flip_map[dw->def_nr];
+ if (dw->def_nr < flip_map_len) {
+ if (flip_map[dw->def_nr] >= 0) {
+ dw->def_nr= flip_map[dw->def_nr];
+ }
}
}
}
@@ -283,17 +287,17 @@ int defgroup_find_index(Object *ob, bDeformGroup *dg)
/* note, must be freed */
int *defgroup_flip_map(Object *ob, int *flip_map_len, int use_default)
{
- int totdg= *flip_map_len= BLI_countlist(&ob->defbase);
+ int defbase_tot= *flip_map_len= BLI_countlist(&ob->defbase);
- if (totdg==0) {
+ if (defbase_tot==0) {
return NULL;
}
else {
bDeformGroup *dg;
char name[sizeof(dg->name)];
- int i, flip_num, *map= MEM_mallocN(totdg * sizeof(int), __func__);
+ int i, flip_num, *map= MEM_mallocN(defbase_tot * sizeof(int), __func__);
- for (i=0; i < totdg; i++) {
+ for (i=0; i < defbase_tot; i++) {
map[i]= -1;
}
@@ -321,17 +325,17 @@ int *defgroup_flip_map(Object *ob, int *flip_map_len, int use_default)
/* note, must be freed */
int *defgroup_flip_map_single(Object *ob, int *flip_map_len, int use_default, int defgroup)
{
- int totdg= *flip_map_len= BLI_countlist(&ob->defbase);
+ int defbase_tot= *flip_map_len= BLI_countlist(&ob->defbase);
- if (totdg==0) {
+ if (defbase_tot==0) {
return NULL;
}
else {
bDeformGroup *dg;
char name[sizeof(dg->name)];
- int i, flip_num, *map= MEM_mallocN(totdg * sizeof(int), __func__);
+ int i, flip_num, *map= MEM_mallocN(defbase_tot * sizeof(int), __func__);
- for (i=0; i < totdg; i++) {
+ for (i=0; i < defbase_tot; i++) {
if (use_default) map[i]= i;
else map[i]= -1;
}