diff options
author | Campbell Barton <ideasman42@gmail.com> | 2012-04-09 08:39:47 +0400 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2012-04-09 08:39:47 +0400 |
commit | 9a6a791ff0c9b32f66831f5e09d7c283ac309b95 (patch) | |
tree | 0777f6caf5134d5d3e3babf7757340cb06d83686 | |
parent | b7113002dbea417617e3ef655d42732ade16577e (diff) |
fix [#30865] Crash when browsing last operators in outliner (or by Python API)
Operator descriptions can be NULL pointers,
fix this by making use of PROP_NEVER_NULL flag, when its not set, generated string funcs will test for NULL.
-rw-r--r-- | source/blender/makesrna/RNA_types.h | 3 | ||||
-rw-r--r-- | source/blender/makesrna/intern/makesrna.c | 18 | ||||
-rw-r--r-- | source/blender/makesrna/intern/rna_define.c | 7 | ||||
-rw-r--r-- | source/blender/makesrna/intern/rna_ui.c | 1 | ||||
-rw-r--r-- | source/blender/makesrna/intern/rna_wm.c | 2 |
5 files changed, 30 insertions, 1 deletions
diff --git a/source/blender/makesrna/RNA_types.h b/source/blender/makesrna/RNA_types.h index 8a668f68761..8f3e2c1f104 100644 --- a/source/blender/makesrna/RNA_types.h +++ b/source/blender/makesrna/RNA_types.h @@ -180,6 +180,9 @@ typedef enum PropertyFlag { /* disallow assigning a variable to its self, eg an object tracking its self * only apply this to types that are derived from an ID ()*/ PROP_ID_SELF_CHECK = 1<<20, + /* use for... + * - pointers: in the UI and python so unsetting or setting to None won't work + * - strings: so our internal generated get/length/set functions know to do NULL checks before access [#30865] */ PROP_NEVER_NULL = 1<<18, /* currently only used for UI, this is similar to PROP_NEVER_NULL * except that the value may be NULL at times, used for ObData, where an Empty's will be NULL diff --git a/source/blender/makesrna/intern/makesrna.c b/source/blender/makesrna/intern/makesrna.c index 02917f1bce8..87f00dc835d 100644 --- a/source/blender/makesrna/intern/makesrna.c +++ b/source/blender/makesrna/intern/makesrna.c @@ -539,6 +539,14 @@ static char *rna_def_property_get_func(FILE *f, StructRNA *srna, PropertyRNA *pr "BLI_strncpy" : "BLI_strncpy_utf8"; rna_print_data_get(f, dp); + + if (!(prop->flag & PROP_NEVER_NULL)) { + fprintf(f, " if (data->%s == NULL) {\n", dp->dnaname); + fprintf(f, " *value = '\\0';\n"); + fprintf(f, " return;\n"); + fprintf(f, " }\n"); + } + if (sprop->maxlength) fprintf(f, " %s(value, data->%s, %d);\n", string_copy_func, dp->dnaname, sprop->maxlength); else @@ -781,6 +789,13 @@ static char *rna_def_property_set_func(FILE *f, StructRNA *srna, PropertyRNA *pr "BLI_strncpy" : "BLI_strncpy_utf8"; rna_print_data_get(f, dp); + + if (!(prop->flag & PROP_NEVER_NULL)) { + fprintf(f, " if (data->%s == NULL) {\n", dp->dnaname); + fprintf(f, " return;\n"); + fprintf(f, " }\n"); + } + if (sprop->maxlength) fprintf(f, " %s(data->%s, value, %d);\n", string_copy_func, dp->dnaname, sprop->maxlength); else @@ -956,6 +971,9 @@ static char *rna_def_property_length_func(FILE *f, StructRNA *srna, PropertyRNA } else { rna_print_data_get(f, dp); + if (!(prop->flag & PROP_NEVER_NULL)) { + fprintf(f, " if (data->%s == NULL) return 0;\n", dp->dnaname); + } fprintf(f, " return strlen(data->%s);\n", dp->dnaname); } fprintf(f, "}\n\n"); diff --git a/source/blender/makesrna/intern/rna_define.c b/source/blender/makesrna/intern/rna_define.c index e106f8236c9..abaf598d4cc 100644 --- a/source/blender/makesrna/intern/rna_define.c +++ b/source/blender/makesrna/intern/rna_define.c @@ -949,7 +949,6 @@ PropertyRNA *RNA_def_property(StructOrFunctionRNA *cont_, const char *identifier StringPropertyRNA *sprop = (StringPropertyRNA*)prop; sprop->defaultvalue = ""; - sprop->maxlength = 0; break; } case PROP_ENUM: @@ -983,6 +982,12 @@ PropertyRNA *RNA_def_property(StructOrFunctionRNA *cont_, const char *identifier prop->flag |= PROP_ANIMATABLE; } + if (type == PROP_STRING) { + /* used so generated 'get/length/set' functions skip a NULL check + * in some cases we want it */ + RNA_def_property_flag(prop, PROP_NEVER_NULL); + } + if (DefRNA.preprocess) { switch (type) { case PROP_BOOLEAN: diff --git a/source/blender/makesrna/intern/rna_ui.c b/source/blender/makesrna/intern/rna_ui.c index a70eac58142..635dfb48b27 100644 --- a/source/blender/makesrna/intern/rna_ui.c +++ b/source/blender/makesrna/intern/rna_ui.c @@ -840,6 +840,7 @@ static void rna_def_menu(BlenderRNA *brna) RNA_def_property_string_funcs(prop, NULL, NULL, "rna_Menu_bl_description_set"); /* RNA_def_property_clear_flag(prop, PROP_EDITABLE); */ RNA_def_property_flag(prop, PROP_REGISTER_OPTIONAL); + RNA_def_property_clear_flag(prop, PROP_NEVER_NULL); /* check for NULL */ RNA_define_verify_sdna(1); } diff --git a/source/blender/makesrna/intern/rna_wm.c b/source/blender/makesrna/intern/rna_wm.c index 80dad69f124..db77be8dc31 100644 --- a/source/blender/makesrna/intern/rna_wm.c +++ b/source/blender/makesrna/intern/rna_wm.c @@ -1296,6 +1296,7 @@ static void rna_def_operator(BlenderRNA *brna) RNA_def_property_string_funcs(prop, NULL, NULL, "rna_Operator_bl_description_set"); /* RNA_def_property_clear_flag(prop, PROP_EDITABLE); */ RNA_def_property_flag(prop, PROP_REGISTER_OPTIONAL); + RNA_def_property_clear_flag(prop, PROP_NEVER_NULL); /* check for NULL */ prop = RNA_def_property(srna, "bl_options", PROP_ENUM, PROP_NONE); RNA_def_property_enum_sdna(prop, NULL, "type->flag"); @@ -1362,6 +1363,7 @@ static void rna_def_macro_operator(BlenderRNA *brna) RNA_def_property_string_funcs(prop, NULL, NULL, "rna_Operator_bl_description_set"); /* RNA_def_property_clear_flag(prop, PROP_EDITABLE); */ RNA_def_property_flag(prop, PROP_REGISTER_OPTIONAL); + RNA_def_property_clear_flag(prop, PROP_NEVER_NULL); /* check for NULL */ prop = RNA_def_property(srna, "bl_options", PROP_ENUM, PROP_NONE); RNA_def_property_enum_sdna(prop, NULL, "type->flag"); |