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-01-18 06:49:28 +0300
committerCampbell Barton <ideasman42@gmail.com>2011-01-18 06:49:28 +0300
commit2431e8e045f9fee8454ecd97f287d0e171b1ee94 (patch)
tree74e1e73222edf41b168002603d84dceb1c440f26
parent8cf1184c045d37b7aecd5b8a08ecefefeed17850 (diff)
bgl.Buffer()
- invalid dimension type could be passed without raising an error. - negative dimensions could crash blender, now they raise errors. - zero length dimension arg was not detected. - floating point lengths were accepted, now only allow ints. also comment unused vars.
-rw-r--r--source/blender/editors/gpencil/gpencil_paint.c4
-rw-r--r--source/blender/python/generic/bgl.c37
2 files changed, 29 insertions, 12 deletions
diff --git a/source/blender/editors/gpencil/gpencil_paint.c b/source/blender/editors/gpencil/gpencil_paint.c
index 86f3e3c0b91..baa6f7d6a25 100644
--- a/source/blender/editors/gpencil/gpencil_paint.c
+++ b/source/blender/editors/gpencil/gpencil_paint.c
@@ -899,8 +899,8 @@ static tGPsdata *gp_session_initpaint (bContext *C)
/* supported views first */
case SPACE_VIEW3D:
{
- View3D *v3d= curarea->spacedata.first;
- RegionView3D *rv3d= ar->regiondata;
+ // View3D *v3d= curarea->spacedata.first;
+ // RegionView3D *rv3d= ar->regiondata;
/* set current area
* - must verify that region data is 3D-view (and not something else)
diff --git a/source/blender/python/generic/bgl.c b/source/blender/python/generic/bgl.c
index 3d525b08ecc..474259fe0e3 100644
--- a/source/blender/python/generic/bgl.c
+++ b/source/blender/python/generic/bgl.c
@@ -187,43 +187,60 @@ Buffer *BGL_MakeBuffer(int type, int ndimensions, int *dimensions, void *initbuf
#define MAX_DIMENSIONS 256
static PyObject *Method_Buffer (PyObject *UNUSED(self), PyObject *args)
{
- PyObject *length_ob= NULL, *template= NULL;
+ PyObject *length_ob= NULL, *init= NULL;
Buffer *buffer;
int dimensions[MAX_DIMENSIONS];
int i, type;
int ndimensions = 0;
- if (!PyArg_ParseTuple(args, "iO|O", &type, &length_ob, &template)) {
+ if (!PyArg_ParseTuple(args, "iO|O", &type, &length_ob, &init)) {
PyErr_SetString(PyExc_AttributeError, "expected an int and one or two PyObjects");
return NULL;
}
- if (type!=GL_BYTE && type!=GL_SHORT && type!=GL_INT && type!=GL_FLOAT && type!=GL_DOUBLE) {
+ if (!ELEM5(type, GL_BYTE, GL_SHORT, GL_INT, GL_FLOAT, GL_DOUBLE)) {
PyErr_SetString(PyExc_AttributeError, "invalid first argument type, should be one of GL_BYTE, GL_SHORT, GL_INT, GL_FLOAT or GL_DOUBLE");
return NULL;
}
- if (PyNumber_Check(length_ob)) {
+ if (PyLong_Check(length_ob)) {
ndimensions= 1;
- dimensions[0]= PyLong_AsLong(length_ob);
- } else if (PySequence_Check(length_ob)) {
+ if(((dimensions[0]= PyLong_AsLong(length_ob)) < 1)) {
+ PyErr_SetString(PyExc_AttributeError, "dimensions must be between 1 and "STRINGIFY(MAX_DIMENSIONS));
+ return NULL;
+ }
+ }
+ else if (PySequence_Check(length_ob)) {
ndimensions= PySequence_Size(length_ob);
if (ndimensions > MAX_DIMENSIONS) {
- PyErr_SetString(PyExc_AttributeError, "too many dimensions, max is 256");
+ PyErr_SetString(PyExc_AttributeError, "too many dimensions, max is "STRINGIFY(MAX_DIMENSIONS));
+ return NULL;
+ }
+ else if (ndimensions < 1) {
+ PyErr_SetString(PyExc_AttributeError, "sequence must have at least one dimension");
return NULL;
}
for (i=0; i<ndimensions; i++) {
PyObject *ob= PySequence_GetItem(length_ob, i);
- if (!PyNumber_Check(ob)) dimensions[i]= 1;
+ if (!PyLong_Check(ob)) dimensions[i]= 1;
else dimensions[i]= PyLong_AsLong(ob);
Py_DECREF(ob);
+
+ if(dimensions[i] < 1) {
+ PyErr_SetString(PyExc_AttributeError, "dimensions must be between 1 and "STRINGIFY(MAX_DIMENSIONS));
+ return NULL;
+ }
}
}
+ else {
+ PyErr_Format(PyExc_TypeError, "invalid second argument argument expected a sequence or an int, not a %.200s", Py_TYPE(length_ob)->tp_name);
+ return NULL;
+ }
buffer= BGL_MakeBuffer(type, ndimensions, dimensions, NULL);
- if (template && ndimensions) {
- if (Buffer_ass_slice((PyObject *) buffer, 0, dimensions[0], template)) {
+ if (init && ndimensions) {
+ if (Buffer_ass_slice((PyObject *) buffer, 0, dimensions[0], init)) {
Py_DECREF(buffer);
return NULL;
}