[Bf-blender-cvs] [996586860b0] master: Cleanup: Do not pass stack allocated string to MEM_callocN

Hans Goudey noreply at git.blender.org
Tue Mar 9 19:31:57 CET 2021


Commit: 996586860b0e2c86e515df1e38316afda32df4a0
Author: Hans Goudey
Date:   Tue Mar 9 13:31:51 2021 -0500
Branches: master
https://developer.blender.org/rB996586860b0e2c86e515df1e38316afda32df4a0

Cleanup: Do not pass stack allocated string to MEM_callocN

===================================================================

M	source/blender/editors/animation/fmodifier_ui.c
M	source/blender/gpencil_modifiers/intern/MOD_gpencil_ui_common.c
M	source/blender/modifiers/intern/MOD_ui_common.c
M	source/blender/shader_fx/intern/FX_ui_common.c

===================================================================

diff --git a/source/blender/editors/animation/fmodifier_ui.c b/source/blender/editors/animation/fmodifier_ui.c
index 1809daa3fcb..653bd72b364 100644
--- a/source/blender/editors/animation/fmodifier_ui.c
+++ b/source/blender/editors/animation/fmodifier_ui.c
@@ -173,15 +173,11 @@ static PanelType *fmodifier_panel_register(ARegionType *region_type,
                                            PanelTypePollFn poll,
                                            const char *id_prefix)
 {
-  /* Get the name for the modifier's panel. */
-  char panel_idname[BKE_ST_MAXNAME];
-  const FModifierTypeInfo *fmi = get_fmodifier_typeinfo(type);
-  BLI_snprintf(panel_idname, BKE_ST_MAXNAME, "%s_PT_%s", id_prefix, fmi->name);
-
-  PanelType *panel_type = MEM_callocN(sizeof(PanelType), panel_idname);
+  PanelType *panel_type = MEM_callocN(sizeof(PanelType), __func__);
 
   /* Intentionally leave the label field blank. The header is filled with buttons. */
-  BLI_strncpy(panel_type->idname, panel_idname, BKE_ST_MAXNAME);
+  const FModifierTypeInfo *fmi = get_fmodifier_typeinfo(type);
+  BLI_snprintf(panel_type->idname, BKE_ST_MAXNAME, "%s_PT_%s", id_prefix, fmi->name);
   BLI_strncpy(panel_type->category, "Modifiers", BKE_ST_MAXNAME);
   BLI_strncpy(panel_type->translation_context, BLT_I18NCONTEXT_DEFAULT_BPYRNA, BKE_ST_MAXNAME);
 
@@ -215,13 +211,9 @@ static PanelType *fmodifier_subpanel_register(ARegionType *region_type,
                                               PanelTypePollFn poll,
                                               PanelType *parent)
 {
-  /* Create the subpanel's ID name. */
-  char panel_idname[BKE_ST_MAXNAME];
-  BLI_snprintf(panel_idname, BKE_ST_MAXNAME, "%s_%s", parent->idname, name);
-
-  PanelType *panel_type = MEM_callocN(sizeof(PanelType), panel_idname);
+  PanelType *panel_type = MEM_callocN(sizeof(PanelType), __func__);
 
-  BLI_strncpy(panel_type->idname, panel_idname, BKE_ST_MAXNAME);
+  BLI_snprintf(panel_type->idname, BKE_ST_MAXNAME, "%s_%s", parent->idname, name);
   BLI_strncpy(panel_type->label, label, BKE_ST_MAXNAME);
   BLI_strncpy(panel_type->category, "Modifiers", BKE_ST_MAXNAME);
   BLI_strncpy(panel_type->translation_context, BLT_I18NCONTEXT_DEFAULT_BPYRNA, BKE_ST_MAXNAME);
diff --git a/source/blender/gpencil_modifiers/intern/MOD_gpencil_ui_common.c b/source/blender/gpencil_modifiers/intern/MOD_gpencil_ui_common.c
index 05e7a23bc82..10383a9417d 100644
--- a/source/blender/gpencil_modifiers/intern/MOD_gpencil_ui_common.c
+++ b/source/blender/gpencil_modifiers/intern/MOD_gpencil_ui_common.c
@@ -371,14 +371,9 @@ PanelType *gpencil_modifier_panel_register(ARegionType *region_type,
                                            GpencilModifierType type,
                                            PanelDrawFn draw)
 {
+  PanelType *panel_type = MEM_callocN(sizeof(PanelType), __func__);
 
-  /* Get the name for the modifier's panel. */
-  char panel_idname[BKE_ST_MAXNAME];
-  BKE_gpencil_modifierType_panel_id(type, panel_idname);
-
-  PanelType *panel_type = MEM_callocN(sizeof(PanelType), panel_idname);
-
-  BLI_strncpy(panel_type->idname, panel_idname, BKE_ST_MAXNAME);
+  BKE_gpencil_modifierType_panel_id(type, panel_type->idname);
   BLI_strncpy(panel_type->label, "", BKE_ST_MAXNAME);
   BLI_strncpy(panel_type->context, "modifier", BKE_ST_MAXNAME);
   BLI_strncpy(panel_type->translation_context, BLT_I18NCONTEXT_DEFAULT_BPYRNA, BKE_ST_MAXNAME);
@@ -412,13 +407,9 @@ PanelType *gpencil_modifier_subpanel_register(ARegionType *region_type,
                                               PanelDrawFn draw,
                                               PanelType *parent)
 {
-  /* Create the subpanel's ID name. */
-  char panel_idname[BKE_ST_MAXNAME];
-  BLI_snprintf(panel_idname, BKE_ST_MAXNAME, "%s_%s", parent->idname, name);
-
-  PanelType *panel_type = MEM_callocN(sizeof(PanelType), panel_idname);
+  PanelType *panel_type = MEM_callocN(sizeof(PanelType), __func__);
 
-  BLI_strncpy(panel_type->idname, panel_idname, BKE_ST_MAXNAME);
+  BLI_snprintf(panel_type->idname, BKE_ST_MAXNAME, "%s_%s", parent->idname, name);
   BLI_strncpy(panel_type->label, label, BKE_ST_MAXNAME);
   BLI_strncpy(panel_type->context, "modifier", BKE_ST_MAXNAME);
   BLI_strncpy(panel_type->translation_context, BLT_I18NCONTEXT_DEFAULT_BPYRNA, BKE_ST_MAXNAME);
diff --git a/source/blender/modifiers/intern/MOD_ui_common.c b/source/blender/modifiers/intern/MOD_ui_common.c
index 821c74496f2..6b2facc16a2 100644
--- a/source/blender/modifiers/intern/MOD_ui_common.c
+++ b/source/blender/modifiers/intern/MOD_ui_common.c
@@ -409,13 +409,9 @@ static void modifier_panel_header(const bContext *C, Panel *panel)
  */
 PanelType *modifier_panel_register(ARegionType *region_type, ModifierType type, PanelDrawFn draw)
 {
-  /* Get the name for the modifier's panel. */
-  char panel_idname[BKE_ST_MAXNAME];
-  BKE_modifier_type_panel_id(type, panel_idname);
+  PanelType *panel_type = MEM_callocN(sizeof(PanelType), __func__);
 
-  PanelType *panel_type = MEM_callocN(sizeof(PanelType), panel_idname);
-
-  BLI_strncpy(panel_type->idname, panel_idname, BKE_ST_MAXNAME);
+  BKE_modifier_type_panel_id(type, panel_type->idname);
   BLI_strncpy(panel_type->label, "", BKE_ST_MAXNAME);
   BLI_strncpy(panel_type->context, "modifier", BKE_ST_MAXNAME);
   BLI_strncpy(panel_type->translation_context, BLT_I18NCONTEXT_DEFAULT_BPYRNA, BKE_ST_MAXNAME);
@@ -450,13 +446,9 @@ PanelType *modifier_subpanel_register(ARegionType *region_type,
                                       PanelDrawFn draw,
                                       PanelType *parent)
 {
-  /* Create the subpanel's ID name. */
-  char panel_idname[BKE_ST_MAXNAME];
-  BLI_snprintf(panel_idname, BKE_ST_MAXNAME, "%s_%s", parent->idname, name);
-
-  PanelType *panel_type = MEM_callocN(sizeof(PanelType), panel_idname);
+  PanelType *panel_type = MEM_callocN(sizeof(PanelType), __func__);
 
-  BLI_strncpy(panel_type->idname, panel_idname, BKE_ST_MAXNAME);
+  BLI_snprintf(panel_type->idname, BKE_ST_MAXNAME, "%s_%s", parent->idname, name);
   BLI_strncpy(panel_type->label, label, BKE_ST_MAXNAME);
   BLI_strncpy(panel_type->context, "modifier", BKE_ST_MAXNAME);
   BLI_strncpy(panel_type->translation_context, BLT_I18NCONTEXT_DEFAULT_BPYRNA, BKE_ST_MAXNAME);
diff --git a/source/blender/shader_fx/intern/FX_ui_common.c b/source/blender/shader_fx/intern/FX_ui_common.c
index 9a86e1e96f5..8a259c6aaff 100644
--- a/source/blender/shader_fx/intern/FX_ui_common.c
+++ b/source/blender/shader_fx/intern/FX_ui_common.c
@@ -241,14 +241,9 @@ static bool shaderfx_ui_poll(const bContext *C, PanelType *UNUSED(pt))
  */
 PanelType *shaderfx_panel_register(ARegionType *region_type, ShaderFxType type, PanelDrawFn draw)
 {
+  PanelType *panel_type = MEM_callocN(sizeof(PanelType), __func__);
 
-  /* Get the name for the effect's panel. */
-  char panel_idname[BKE_ST_MAXNAME];
-  BKE_shaderfxType_panel_id(type, panel_idname);
-
-  PanelType *panel_type = MEM_callocN(sizeof(PanelType), panel_idname);
-
-  BLI_strncpy(panel_type->idname, panel_idname, BKE_ST_MAXNAME);
+  BKE_shaderfxType_panel_id(type, panel_type->idname);
   BLI_strncpy(panel_type->label, "", BKE_ST_MAXNAME);
   BLI_strncpy(panel_type->context, "shaderfx", BKE_ST_MAXNAME);
   BLI_strncpy(panel_type->translation_context, BLT_I18NCONTEXT_DEFAULT_BPYRNA, BKE_ST_MAXNAME);
@@ -282,13 +277,9 @@ PanelType *shaderfx_subpanel_register(ARegionType *region_type,
                                       PanelDrawFn draw,
                                       PanelType *parent)
 {
-  /* Create the subpanel's ID name. */
-  char panel_idname[BKE_ST_MAXNAME];
-  BLI_snprintf(panel_idname, BKE_ST_MAXNAME, "%s_%s", parent->idname, name);
-
-  PanelType *panel_type = MEM_callocN(sizeof(PanelType), panel_idname);
+  PanelType *panel_type = MEM_callocN(sizeof(PanelType), __func__);
 
-  BLI_strncpy(panel_type->idname, panel_idname, BKE_ST_MAXNAME);
+  BLI_snprintf(panel_type->idname, BKE_ST_MAXNAME, "%s_%s", parent->idname, name);
   BLI_strncpy(panel_type->label, label, BKE_ST_MAXNAME);
   BLI_strncpy(panel_type->context, "shaderfx", BKE_ST_MAXNAME);
   BLI_strncpy(panel_type->translation_context, BLT_I18NCONTEXT_DEFAULT_BPYRNA, BKE_ST_MAXNAME);



More information about the Bf-blender-cvs mailing list