diff options
author | Sergey Sharybin <sergey@blender.org> | 2022-02-16 13:56:04 +0300 |
---|---|---|
committer | Sergey Sharybin <sergey@blender.org> | 2022-02-16 17:40:03 +0300 |
commit | 03ff58b67d50a714c5609e584a6942996cfdee1b (patch) | |
tree | d48c540ef4252afb2ec5966273a1834318e9f6da /source/blender/blenkernel/intern/modifier.c | |
parent | 7e312f89d970744eb90351de01101358613b89ec (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
Diffstat (limited to 'source/blender/blenkernel/intern/modifier.c')
-rw-r--r-- | source/blender/blenkernel/intern/modifier.c | 19 |
1 files changed, 18 insertions, 1 deletions
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)) |