From e8a6a67b3c84fce435c3320b20d789001a158379 Mon Sep 17 00:00:00 2001 From: Mark Wooding Date: Fri, 11 Oct 2019 09:53:00 +0100 Subject: [PATCH] bytestring.c (bytestring_pyrepeat): Don't divide by zero. --- bytestring.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bytestring.c b/bytestring.c index a7fe5cb..82d117f 100644 --- a/bytestring.c +++ b/bytestring.c @@ -165,7 +165,7 @@ static PyObject *bytestring_pyrepeat(PyObject *me, Py_ssize_t n) xp = (const unsigned char *)PyString_AS_STRING(me); xsz = PyString_GET_SIZE(me); - if (n < 0 || xsz >= (size_t)-1/n) VALERR("too long"); + if (n < 0 || (n && xsz >= (size_t)-1/n)) VALERR("too long"); zsz = n*xsz; z = bytestring_pywrap(0, zsz); zp = PyString_AS_STRING(z); if (xsz == 1) memset(zp, *xp, zsz); else while (zsz) { memcpy(zp, xp, xsz); zp += xsz; zsz -= xsz; } -- 2.11.0