From 9e77f5f17fcadf12316ed855ac47abf32592d84f Mon Sep 17 00:00:00 2001 From: Bastien Montagne Date: Fri, 14 Oct 2022 18:35:28 +0200 Subject: Fix T101803: Max length Operator bl_idname is truncated 1 character. There were quite a few issues here: * Bad usage of nagic number leading to confusing code * Forgetting to take into accoun final `NULL` char * RNA code thinkin `bl_idname` is python version, when it is actually BL/C version. --- source/blender/makesrna/intern/rna_wm.c | 16 ++++------------ 1 file changed, 4 insertions(+), 12 deletions(-) (limited to 'source/blender/makesrna') diff --git a/source/blender/makesrna/intern/rna_wm.c b/source/blender/makesrna/intern/rna_wm.c index 7fd590005fd..5b5544120a1 100644 --- a/source/blender/makesrna/intern/rna_wm.c +++ b/source/blender/makesrna/intern/rna_wm.c @@ -1644,12 +1644,7 @@ static StructRNA *rna_MacroOperator_register(Main *bmain, return NULL; } - if (strlen(identifier) >= sizeof(dummyop.idname)) { - BKE_reportf(reports, - RPT_ERROR, - "Registering operator class: '%s' is too long, maximum length is %d", - identifier, - (int)sizeof(dummyop.idname)); + if (!WM_operator_py_idname_ok_or_report(reports, identifier, dummyot.idname)) { return NULL; } @@ -1661,10 +1656,6 @@ static StructRNA *rna_MacroOperator_register(Main *bmain, } } - if (!WM_operator_py_idname_ok_or_report(reports, identifier, dummyot.idname)) { - return NULL; - } - char idname_conv[sizeof(dummyop.idname)]; WM_operator_bl_idname(idname_conv, dummyot.idname); /* convert the idname from python */ @@ -1867,8 +1858,9 @@ static void rna_def_operator_common(StructRNA *srna) /* Registration */ prop = RNA_def_property(srna, "bl_idname", PROP_STRING, PROP_NONE); RNA_def_property_string_sdna(prop, NULL, "type->idname"); - /* Without setting the length the pointer size would be used. -3 because `.` -> `_OT_`. */ - RNA_def_property_string_maxlength(prop, OP_MAX_TYPENAME - 3); + /* String stored here is the 'BL' identifier (`OPMODULE_OT_my_op`), + * not the 'python' identifier (`opmodule.my_op`). */ + RNA_def_property_string_maxlength(prop, OP_MAX_TYPENAME); RNA_def_property_string_funcs(prop, NULL, NULL, "rna_Operator_bl_idname_set"); // RNA_def_property_clear_flag(prop, PROP_EDITABLE); RNA_def_property_flag(prop, PROP_REGISTER); -- cgit v1.2.3