Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Raise TypeError on invalid point arguments (fix #521) #558

Closed
wants to merge 3 commits into from
Closed
Changes from 1 commit
Commits
File filter...
Filter file types
Jump to…
Jump to file or symbol
Failed to load files and symbols.
+28 −13
Diff settings

Always

Just for now

Next

added fix and test for #521

  • Loading branch information...
IchMageBaume committed Oct 14, 2018
commit 7e380a90184a540a21c1d569dbb142adc1e93974
@@ -249,11 +249,17 @@ aalines(PyObject *self, PyObject *arg)
return RAISE(PyExc_ValueError,
"points argument must contain more than 1 points");

for(loop = 0; loop < length; ++loop) {
item = PySequence_GetItem(points, loop);
result = pg_TwoIntsFromObj(item, &x, &y);
Py_DECREF(item);
if(!result)
return RAISE(PyExc_TypeError, "all points must be number pairs");
}

item = PySequence_GetItem(points, 0);
result = pg_TwoFloatsFromObj(item, &x, &y);
Py_DECREF(item);
if (!result)
return RAISE(PyExc_TypeError, "points must be number pairs");

startx = pts[0] = x;
starty = pts[1] = y;
@@ -268,8 +274,6 @@ aalines(PyObject *self, PyObject *arg)
item = PySequence_GetItem(points, loop);
result = pg_TwoFloatsFromObj(item, &x, &y);
Py_DECREF(item);
if (!result)
continue; /*note, we silently skip over bad points :[ */
++drawn;
pts[0] = startx;
pts[1] = starty;
@@ -342,11 +346,17 @@ lines(PyObject *self, PyObject *arg)
return RAISE(PyExc_ValueError,
"points argument must contain more than 1 points");

for(loop = 0; loop < length; ++loop) {
item = PySequence_GetItem(points, loop);
result = pg_TwoIntsFromObj(item, &x, &y);
Py_DECREF(item);
if(!result)
return RAISE(PyExc_TypeError, "all points must be number pairs");
}

item = PySequence_GetItem(points, 0);
result = pg_TwoIntsFromObj(item, &x, &y);
Py_DECREF(item);
if (!result)
return RAISE(PyExc_TypeError, "points must be number pairs");

startx = pts[0] = left = right = x;
starty = pts[1] = top = bottom = y;
@@ -362,8 +372,6 @@ lines(PyObject *self, PyObject *arg)
item = PySequence_GetItem(points, loop);
result = pg_TwoIntsFromObj(item, &x, &y);
Py_DECREF(item);
if (!result)
continue; /*note, we silently skip over bad points :[ */
++drawn;
pts[0] = startx;
pts[1] = starty;
@@ -628,11 +636,17 @@ polygon(PyObject *self, PyObject *arg)
return RAISE(PyExc_ValueError,
"points argument must contain more than 2 points");

for(loop = 0; loop < length; ++loop) {
item = PySequence_GetItem(points, loop);
result = pg_TwoIntsFromObj(item, &x, &y);
Py_DECREF(item);
if(!result)
return RAISE(PyExc_TypeError, "all points must be number pairs");
}

item = PySequence_GetItem(points, 0);
result = pg_TwoIntsFromObj(item, &x, &y);
Py_DECREF(item);
if (!result)
return RAISE(PyExc_TypeError, "points must be number pairs");
left = right = x;
top = bottom = y;

@@ -644,8 +658,6 @@ polygon(PyObject *self, PyObject *arg)
item = PySequence_GetItem(points, loop);
result = pg_TwoIntsFromObj(item, &x, &y);
Py_DECREF(item);
if (!result)
continue; /*note, we silently skip over bad points :[ */
xlist[numpoints] = x;
ylist[numpoints] = y;
++numpoints;
@@ -665,7 +665,10 @@ def test_illumine_shape(self):
self.draw_polygon(GREEN, path_data, 0)
for x in range(4, rect.width-5 +1):
self.assertEqual(self.surface.get_at((x, 4)), GREEN) # upper inner


def test_invalid_points(self):
self.assertRaises(TypeError, lambda: self.draw_polygon(
RED, ((0, 0), (0, 20), (20, 20), 20), 0))

class DrawPolygonTest(DrawPolygonMixin, unittest.TestCase):

ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.