From: Mark Wooding Date: Fri, 11 Oct 2019 08:53:00 +0000 (+0100) Subject: bytestring.c (bytestring_pyrepeat): Don't divide by zero. X-Git-Url: https://git.distorted.org.uk/~mdw/catacomb-python/commitdiff_plain/e8a6a67b3c84fce435c3320b20d789001a158379 bytestring.c (bytestring_pyrepeat): Don't divide by zero. --- 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; }