avoid runtime overflow (1 << 31), for RNA and armature layer UI.

This commit is contained in:
Campbell Barton
2013-08-04 00:01:41 +00:00
parent dd037a85a0
commit 5881fe5d67
3 changed files with 11 additions and 13 deletions

View File

@@ -355,7 +355,7 @@ static void ui_item_array(uiLayout *layout, uiBlock *block, const char *name, in
PropertyType type; PropertyType type;
PropertySubType subtype; PropertySubType subtype;
uiLayout *sub; uiLayout *sub;
int a, b; unsigned int a, b;
/* retrieve type and subtype */ /* retrieve type and subtype */
type = RNA_property_type(prop); type = RNA_property_type(prop);
@@ -373,8 +373,8 @@ static void ui_item_array(uiLayout *layout, uiBlock *block, const char *name, in
/* special check for layer layout */ /* special check for layer layout */
int butw, buth, unit; int butw, buth, unit;
int cols = (len >= 20) ? 2 : 1; int cols = (len >= 20) ? 2 : 1;
int colbuts = len / (2 * cols); const unsigned int colbuts = len / (2 * cols);
int layer_used = 0; unsigned int layer_used = 0;
uiBlockSetCurLayout(block, uiLayoutAbsolute(layout, FALSE)); uiBlockSetCurLayout(block, uiLayoutAbsolute(layout, FALSE));

View File

@@ -646,13 +646,14 @@ static char *rna_def_property_get_func(FILE *f, StructRNA *srna, PropertyRNA *pr
if (prop->flag & PROP_DYNAMIC) { if (prop->flag & PROP_DYNAMIC) {
char *lenfunc = rna_alloc_function_name(srna->identifier, rna_safe_id(prop->identifier), char *lenfunc = rna_alloc_function_name(srna->identifier, rna_safe_id(prop->identifier),
"get_length"); "get_length");
fprintf(f, " int i, arraylen[RNA_MAX_ARRAY_DIMENSION];\n"); fprintf(f, " unsigned int arraylen[RNA_MAX_ARRAY_DIMENSION];\n");
fprintf(f, " int len = %s(ptr, arraylen);\n\n", lenfunc); fprintf(f, " unsigned int i;\n");
fprintf(f, " unsigned int len = %s(ptr, arraylen);\n\n", lenfunc);
fprintf(f, " for (i = 0; i < len; i++) {\n"); fprintf(f, " for (i = 0; i < len; i++) {\n");
MEM_freeN(lenfunc); MEM_freeN(lenfunc);
} }
else { else {
fprintf(f, " int i;\n\n"); fprintf(f, " unsigned int i;\n\n");
fprintf(f, " for (i = 0; i < %u; i++) {\n", prop->totarraylength); fprintf(f, " for (i = 0; i < %u; i++) {\n", prop->totarraylength);
} }

View File

@@ -387,16 +387,13 @@ PyObject *KX_MeshProxy::pyattr_get_materials(void *self_v, const KX_PYATTRIBUTE_
for (i=0; i<tot; mit++, i++) { for (i=0; i<tot; mit++, i++) {
RAS_IPolyMaterial *polymat = mit->m_bucket->GetPolyMaterial(); RAS_IPolyMaterial *polymat = mit->m_bucket->GetPolyMaterial();
if (polymat->GetFlag() & RAS_BLENDERMAT) {
/* Why do we need to check for RAS_BLENDERMAT if both are cast to a (PyObject *)? - Campbell */ KX_BlenderMaterial *mat = static_cast<KX_BlenderMaterial *>(polymat);
if (polymat->GetFlag() & RAS_BLENDERMAT)
{
KX_BlenderMaterial *mat = static_cast<KX_BlenderMaterial*>(polymat);
PyList_SET_ITEM(materials, i, mat->GetProxy()); PyList_SET_ITEM(materials, i, mat->GetProxy());
} }
else { else {
KX_PolygonMaterial *mat = static_cast<KX_PolygonMaterial*>(polymat); KX_PolygonMaterial *mat = static_cast<KX_PolygonMaterial *>(polymat);
PyList_SET_ITEM(materials, i, mat->GetProxy()); PyList_SET_ITEM(materials, i, mat->GetProxy());
} }
} }