Revision: 40927
          
http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=40927
Author:   campbellbarton
Date:     2011-10-11 05:45:59 +0000 (Tue, 11 Oct 2011)
Log Message:
-----------
fix for py/rna assigning an invalid index. also give better error message in 
this case.

Modified Paths:
--------------
    trunk/blender/source/blender/makesrna/intern/rna_ID.c
    trunk/blender/source/blender/python/intern/bpy_rna.c

Modified: trunk/blender/source/blender/makesrna/intern/rna_ID.c
===================================================================
--- trunk/blender/source/blender/makesrna/intern/rna_ID.c       2011-10-11 
05:21:24 UTC (rev 40926)
+++ trunk/blender/source/blender/makesrna/intern/rna_ID.c       2011-10-11 
05:45:59 UTC (rev 40927)
@@ -317,9 +317,15 @@
 int rna_IDMaterials_assign_int(PointerRNA *ptr, int key, const PointerRNA 
*assign_ptr)
 {
        ID *id=           ptr->id.data;
+       short *totcol= give_totcolp_id(id);
        Material *mat_id= assign_ptr->id.data;
-       assign_material_id(id, mat_id, key + 1);
-       return 1;
+       if(totcol && (key >= 0 && key < *totcol)) {
+               assign_material_id(id, mat_id, key + 1);
+               return 1;
+       }
+       else {
+               return 0;
+       }
 }
 
 #else

Modified: trunk/blender/source/blender/python/intern/bpy_rna.c
===================================================================
--- trunk/blender/source/blender/python/intern/bpy_rna.c        2011-10-11 
05:21:24 UTC (rev 40926)
+++ trunk/blender/source/blender/python/intern/bpy_rna.c        2011-10-11 
05:45:59 UTC (rev 40927)
@@ -1928,10 +1928,10 @@
 }
 
 
+/* notice getting the length of the collection is avoided unless negative
+ * index is used or to detect internal error with a valid index.
+ * This is done for faster lookups. */
 #define PYRNA_PROP_COLLECTION_ABS_INDEX(ret_err)                              \
-       /* notice getting the length of the collection is avoided unless 
negative \
-        * index is used or to detect internal error with a valid index.        
  \
-        * This is done for faster lookups. */                                  
  \
        if(keynum < 0) {                                                        
  \
                keynum_abs += RNA_property_collection_length(&self->ptr, 
self->prop); \
                if(keynum_abs < 0) {                                            
      \
@@ -1984,11 +1984,18 @@
        PYRNA_PROP_COLLECTION_ABS_INDEX(-1);
 
        if(RNA_property_collection_assign_int(&self->ptr, self->prop, 
keynum_abs, ptr) == 0) {
+               const int len= RNA_property_collection_length(&self->ptr, 
self->prop);
+               if(keynum_abs >= len) {
+                       PyErr_Format(PyExc_IndexError,
+                                    "bpy_prop_collection[index] = value: "
+                                    "index %d out of range, size %d", keynum, 
len);
+               }
+               else {
 
-               PyErr_Format(PyExc_IndexError,
-                            "bpy_prop_collection[index] = value: "
-                            "failed assignment (unknown reason)", keynum);
-
+                       PyErr_Format(PyExc_IndexError,
+                                    "bpy_prop_collection[index] = value: "
+                                    "failed assignment (unknown reason)", 
keynum);
+               }
                return -1;
        }
 

_______________________________________________
Bf-blender-cvs mailing list
[email protected]
http://lists.blender.org/mailman/listinfo/bf-blender-cvs

Reply via email to