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:
authorSergey Sharybin <sergey@blender.org>2022-02-16 13:56:04 +0300
committerSergey Sharybin <sergey@blender.org>2022-02-16 17:40:03 +0300
commit03ff58b67d50a714c5609e584a6942996cfdee1b (patch)
treed48c540ef4252afb2ec5966273a1834318e9f6da
parent7e312f89d970744eb90351de01101358613b89ec (diff)
Cleanup: Use const qualifier in modifier data copy
Fix possible overflow of Modifier UUID The code prior this change was re-generating modifier's session UUID prior to copying this id from the source. This approach has a higher risk of modifiers session UUID to overflow and start colliding with existing modifiers. This change makes it so that modifier copy does not re-generated the session UUID unless it is needed. Differential Revision: https://developer.blender.org/D14125
-rw-r--r--source/blender/blenkernel/BKE_modifier.h2
-rw-r--r--source/blender/blenkernel/intern/modifier.c19
-rw-r--r--source/blender/blenkernel/intern/object.cc4
3 files changed, 21 insertions, 4 deletions
diff --git a/source/blender/blenkernel/BKE_modifier.h b/source/blender/blenkernel/BKE_modifier.h
index 6df503153b9..acdca23b21c 100644
--- a/source/blender/blenkernel/BKE_modifier.h
+++ b/source/blender/blenkernel/BKE_modifier.h
@@ -409,6 +409,8 @@ void BKE_modifier_session_uuid_generate(struct ModifierData *md);
bool BKE_modifier_unique_name(struct ListBase *modifiers, struct ModifierData *md);
+struct ModifierData *BKE_modifier_copy_ex(const struct ModifierData *md, int flag);
+
/**
* Callback's can use this to avoid copying every member.
*/
diff --git a/source/blender/blenkernel/intern/modifier.c b/source/blender/blenkernel/intern/modifier.c
index 0e8838d16ce..837c1fe179f 100644
--- a/source/blender/blenkernel/intern/modifier.c
+++ b/source/blender/blenkernel/intern/modifier.c
@@ -131,7 +131,7 @@ void BKE_modifier_panel_expand(ModifierData *md)
/***/
-ModifierData *BKE_modifier_new(int type)
+static ModifierData *modifier_allocate_and_init(int type)
{
const ModifierTypeInfo *mti = BKE_modifier_get_info(type);
ModifierData *md = MEM_callocN(mti->structSize, mti->structName);
@@ -152,6 +152,13 @@ ModifierData *BKE_modifier_new(int type)
mti->initData(md);
}
+ return md;
+}
+
+ModifierData *BKE_modifier_new(int type)
+{
+ ModifierData *md = modifier_allocate_and_init(type);
+
BKE_modifier_session_uuid_generate(md);
return md;
@@ -315,6 +322,16 @@ void BKE_modifiers_foreach_tex_link(Object *ob, TexWalkFunc walk, void *userData
}
}
+ModifierData *BKE_modifier_copy_ex(const ModifierData *md, int flag)
+{
+ ModifierData *md_dst = modifier_allocate_and_init(md->type);
+
+ BLI_strncpy(md_dst->name, md->name, sizeof(md_dst->name));
+ BKE_modifier_copydata_ex(md, md_dst, flag);
+
+ return md_dst;
+}
+
void BKE_modifier_copydata_generic(const ModifierData *md_src,
ModifierData *md_dst,
const int UNUSED(flag))
diff --git a/source/blender/blenkernel/intern/object.cc b/source/blender/blenkernel/intern/object.cc
index 579e61750f0..3a8d7d6bc8a 100644
--- a/source/blender/blenkernel/intern/object.cc
+++ b/source/blender/blenkernel/intern/object.cc
@@ -1599,9 +1599,7 @@ bool BKE_object_modifier_stack_copy(Object *ob_dst,
continue;
}
- ModifierData *md_dst = BKE_modifier_new(md_src->type);
- BLI_strncpy(md_dst->name, md_src->name, sizeof(md_dst->name));
- BKE_modifier_copydata_ex(md_src, md_dst, flag_subdata);
+ ModifierData *md_dst = BKE_modifier_copy_ex(md_src, flag_subdata);
BLI_addtail(&ob_dst->modifiers, md_dst);
}