|
|
7444ce |
diff --git a/Tests/test_imagepath.py b/Tests/test_imagepath.py
|
|
|
7444ce |
index 98a6d34..733fd29 100644
|
|
|
7444ce |
--- a/Tests/test_imagepath.py
|
|
|
7444ce |
+++ b/Tests/test_imagepath.py
|
|
|
7444ce |
@@ -67,6 +67,11 @@ class TestImagePath(PillowTestCase):
|
|
|
7444ce |
p = ImagePath.Path(arr.tostring())
|
|
|
7444ce |
self.assertEqual(list(p), [(0.0, 1.0)])
|
|
|
7444ce |
|
|
|
7444ce |
+ def test_getbbox(self):
|
|
|
7444ce |
+ for coords in (0,1):
|
|
|
7444ce |
+ p = ImagePath.Path(coords)
|
|
|
7444ce |
+ self.assertEqual(p.getbbox(), (0.0, 0.0, 0.0, 0.0))
|
|
|
7444ce |
+
|
|
|
7444ce |
def test_overflow_segfault(self):
|
|
|
7444ce |
# Some Pythons fail getting the argument as an integer, and it falls
|
|
|
7444ce |
# through to the sequence. Seeing this on 32-bit Windows.
|
|
|
7444ce |
diff --git a/src/path.c b/src/path.c
|
|
|
7444ce |
index eb1e065..5215f87 100644
|
|
|
7444ce |
--- a/src/path.c
|
|
|
7444ce |
+++ b/src/path.c
|
|
|
7444ce |
@@ -62,7 +62,7 @@ alloc_array(Py_ssize_t count)
|
|
|
7444ce |
PyErr_NoMemory();
|
|
|
7444ce |
return NULL;
|
|
|
7444ce |
}
|
|
|
7444ce |
- xy = malloc(2 * count * sizeof(double) + 1);
|
|
|
7444ce |
+ xy = calloc(2 * count + 1, sizeof(double));
|
|
|
7444ce |
if (!xy)
|
|
|
7444ce |
PyErr_NoMemory();
|
|
|
7444ce |
return xy;
|
|
|
7444ce |
@@ -330,18 +330,27 @@ path_getbbox(PyPathObject* self, PyObject* args)
|
|
|
7444ce |
|
|
|
7444ce |
xy = self->xy;
|
|
|
7444ce |
|
|
|
7444ce |
- x0 = x1 = xy[0];
|
|
|
7444ce |
- y0 = y1 = xy[1];
|
|
|
7444ce |
-
|
|
|
7444ce |
- for (i = 1; i < self->count; i++) {
|
|
|
7444ce |
- if (xy[i+i] < x0)
|
|
|
7444ce |
- x0 = xy[i+i];
|
|
|
7444ce |
- if (xy[i+i] > x1)
|
|
|
7444ce |
- x1 = xy[i+i];
|
|
|
7444ce |
- if (xy[i+i+1] < y0)
|
|
|
7444ce |
- y0 = xy[i+i+1];
|
|
|
7444ce |
- if (xy[i+i+1] > y1)
|
|
|
7444ce |
- y1 = xy[i+i+1];
|
|
|
7444ce |
+ if (self->count == 0) {
|
|
|
7444ce |
+ x0 = x1 = 0;
|
|
|
7444ce |
+ y0 = y1 = 0;
|
|
|
7444ce |
+ } else {
|
|
|
7444ce |
+ x0 = x1 = xy[0];
|
|
|
7444ce |
+ y0 = y1 = xy[1];
|
|
|
7444ce |
+
|
|
|
7444ce |
+ for (i = 1; i < self->count; i++) {
|
|
|
7444ce |
+ if (xy[i + i] < x0) {
|
|
|
7444ce |
+ x0 = xy[i + i];
|
|
|
7444ce |
+ }
|
|
|
7444ce |
+ if (xy[i + i] > x1) {
|
|
|
7444ce |
+ x1 = xy[i + i];
|
|
|
7444ce |
+ }
|
|
|
7444ce |
+ if (xy[i + i + 1] < y0) {
|
|
|
7444ce |
+ y0 = xy[i + i + 1];
|
|
|
7444ce |
+ }
|
|
|
7444ce |
+ if (xy[i + i + 1] > y1) {
|
|
|
7444ce |
+ y1 = xy[i + i + 1];
|
|
|
7444ce |
+ }
|
|
|
7444ce |
+ }
|
|
|
7444ce |
}
|
|
|
7444ce |
|
|
|
7444ce |
return Py_BuildValue("dddd", x0, y0, x1, y1);
|