fix [#30865] Crash when browsing last operators in outliner (or by Python API)
authorCampbell Barton <ideasman42@gmail.com>
Mon, 9 Apr 2012 04:39:47 +0000 (04:39 +0000)
committerCampbell Barton <ideasman42@gmail.com>
Mon, 9 Apr 2012 04:39:47 +0000 (04:39 +0000)
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.

source/blender/makesrna/RNA_types.h
source/blender/makesrna/intern/makesrna.c
source/blender/makesrna/intern/rna_define.c
source/blender/makesrna/intern/rna_ui.c
source/blender/makesrna/intern/rna_wm.c

index 8a668f68761be2b8ee04984a05b557c702d232d2..8f3e2c1f10403914e3d94ef9c40b8c3be15604f8 100644 (file)
@@ -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
index 02917f1bce8c75a619d5d417e1310f189e14647e..87f00dc835d4e2b99e74f5022aff08b0c1e3d56f 100644 (file)
@@ -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");
index e106f8236c9a68692435ab4e2dd12fa0268a255a..abaf598d4cc525b035a593fc1fdd122bbb95a822 100644 (file)
@@ -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:
index a70eac581424b54f2c9e1b735a627c212492ffae..635dfb48b275a0c79e9d291e76f2d338765ddcb1 100644 (file)
@@ -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);
 }
index 80dad69f124f597448bf714694ea0643909e716e..db77be8dc315f35086d3c363d0a8fe62770054b3 100644 (file)
@@ -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");