Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCampbell Barton <ideasman42@gmail.com>2011-10-11 09:45:59 +0400
committerCampbell Barton <ideasman42@gmail.com>2011-10-11 09:45:59 +0400
commit93e4de755243f7f8b839375d4dd4f75965198334 (patch)
treecfa9db7e1451bf12794b7473e48dd6a43c9e9233
parent85a2280c861122da70a26da0c664bc1c4615efcd (diff)
fix for py/rna assigning an invalid index. also give better error message in this case.
-rw-r--r--source/blender/makesrna/intern/rna_ID.c10
-rw-r--r--source/blender/python/intern/bpy_rna.c21
2 files changed, 22 insertions, 9 deletions
diff --git a/source/blender/makesrna/intern/rna_ID.c b/source/blender/makesrna/intern/rna_ID.c
index ddd0fcc1007..b366a23c19a 100644
--- a/source/blender/makesrna/intern/rna_ID.c
+++ b/source/blender/makesrna/intern/rna_ID.c
@@ -317,9 +317,15 @@ static int rna_IDPArray_length(PointerRNA *ptr)
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
diff --git a/source/blender/python/intern/bpy_rna.c b/source/blender/python/intern/bpy_rna.c
index f5ecf91305d..ba7e2d41e69 100644
--- a/source/blender/python/intern/bpy_rna.c
+++ b/source/blender/python/intern/bpy_rna.c
@@ -1928,10 +1928,10 @@ static int pyrna_prop_collection_bool(BPy_PropertyRNA *self)
}
+/* 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 @@ static int pyrna_prop_collection_ass_subscript_int(BPy_PropertyRNA *self, Py_ssi
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;
}