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