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:
authorAndrew Hale <TrumanBlending@gmail.com>2012-02-02 05:07:04 +0400
committerAndrew Hale <TrumanBlending@gmail.com>2012-02-02 05:07:04 +0400
commit5a221dd0dea81fbe31f5e6431911288e8e3f4b53 (patch)
treee445b6b7d370a8d2052cfac1a1dbf3d0db6557d9 /source/blender/python/mathutils
parentca927b5771aba924b6f13242b4483e9f861d3153 (diff)
Fix for possible memory leak on creation of a vector using Vector.Range.
It was possible to allocate an array of size<2 which would then raise an error on vector creation without freeing. Fix to ensure the behaviour of Vector.Range was the same as for builtin range() function. When specifying 3 arguments, the step argument wasn't being used to correctly calculate the vector size. Minor formatting edits for error messages.
Diffstat (limited to 'source/blender/python/mathutils')
-rw-r--r--source/blender/python/mathutils/mathutils_Vector.c21
1 files changed, 16 insertions, 5 deletions
diff --git a/source/blender/python/mathutils/mathutils_Vector.c b/source/blender/python/mathutils/mathutils_Vector.c
index 5848e6e8c75..0ca8878c96a 100644
--- a/source/blender/python/mathutils/mathutils_Vector.c
+++ b/source/blender/python/mathutils/mathutils_Vector.c
@@ -174,7 +174,7 @@ static PyObject *C_Vector_Range(PyObject *cls, PyObject *args)
case 2:
if (start >= stop) {
PyErr_SetString(PyExc_RuntimeError,
- "Start value is larger"
+ "Start value is larger "
"than the stop value");
return NULL;
}
@@ -184,16 +184,27 @@ static PyObject *C_Vector_Range(PyObject *cls, PyObject *args)
default:
if (start >= stop) {
PyErr_SetString(PyExc_RuntimeError,
- "Start value is larger"
+ "Start value is larger "
"than the stop value");
return NULL;
}
- size = (stop - start)/step;
- if (size%step)
- size++;
+
+ size = (stop - start);
+
+ if ((size % step) != 0)
+ size += step;
+
+ size /= step;
+
break;
}
+ if (size < 2) {
+ PyErr_SetString(PyExc_RuntimeError,
+ "Vector(): invalid size");
+ return NULL;
+ }
+
vec = PyMem_Malloc(size * sizeof(float));
if (vec == NULL) {