Skip to content

Commit

Permalink
Merge pull request #3077 from pygame-community/ankith26-frect-repr-fix
Browse files Browse the repository at this point in the history
Update `FRect` repr to handle larger values
  • Loading branch information
ankith26 authored Aug 24, 2024
2 parents dbdcd90 + 0916bf6 commit ae066f8
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src_c/rect.c
Original file line number Diff line number Diff line change
Expand Up @@ -615,11 +615,11 @@ pg_rect_repr(pgRectObject *self)
static PyObject *
pg_frect_repr(pgFRectObject *self)
{
char str[64];
char str[256];

int ret = PyOS_snprintf(str, 64, "FRect(%f, %f, %f, %f)", self->r.x,
int ret = PyOS_snprintf(str, 256, "FRect(%f, %f, %f, %f)", self->r.x,
self->r.y, self->r.w, self->r.h);
if (ret < 0 || ret >= 64) {
if (ret < 0 || ret >= 256) {
return RAISE(PyExc_RuntimeError,
"Internal PyOS_snprintf call failed!");
}
Expand Down
3 changes: 3 additions & 0 deletions test/rect_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -2877,6 +2877,9 @@ def testRepr(self):
repr(rect), "FRect(12.345679, 34.000000, 56.000000, 78.000000)"
)

# test that a large rect repr doesn't error
self.assertIsInstance(repr(Rect(-2e38, -2e38, -2e38, -2e38)), str)

def test_clipline__equal_endpoints_no_overlap(self):
"""Ensures clipline handles lines with both endpoints the same.
Expand Down

0 comments on commit ae066f8

Please sign in to comment.