Skip to content

Commit ae066f8

Browse files
authored
Merge pull request #3077 from pygame-community/ankith26-frect-repr-fix
Update `FRect` repr to handle larger values
2 parents dbdcd90 + 0916bf6 commit ae066f8

File tree

2 files changed

+6
-3
lines changed

2 files changed

+6
-3
lines changed

src_c/rect.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -615,11 +615,11 @@ pg_rect_repr(pgRectObject *self)
615615
static PyObject *
616616
pg_frect_repr(pgFRectObject *self)
617617
{
618-
char str[64];
618+
char str[256];
619619

620-
int ret = PyOS_snprintf(str, 64, "FRect(%f, %f, %f, %f)", self->r.x,
620+
int ret = PyOS_snprintf(str, 256, "FRect(%f, %f, %f, %f)", self->r.x,
621621
self->r.y, self->r.w, self->r.h);
622-
if (ret < 0 || ret >= 64) {
622+
if (ret < 0 || ret >= 256) {
623623
return RAISE(PyExc_RuntimeError,
624624
"Internal PyOS_snprintf call failed!");
625625
}

test/rect_test.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2877,6 +2877,9 @@ def testRepr(self):
28772877
repr(rect), "FRect(12.345679, 34.000000, 56.000000, 78.000000)"
28782878
)
28792879

2880+
# test that a large rect repr doesn't error
2881+
self.assertIsInstance(repr(Rect(-2e38, -2e38, -2e38, -2e38)), str)
2882+
28802883
def test_clipline__equal_endpoints_no_overlap(self):
28812884
"""Ensures clipline handles lines with both endpoints the same.
28822885

0 commit comments

Comments
 (0)