bytestring.c (bytestring_pyrepeat): Don't divide by zero.
authorMark Wooding <mdw@distorted.org.uk>
Fri, 11 Oct 2019 08:53:00 +0000 (09:53 +0100)
committerMark Wooding <mdw@distorted.org.uk>
Sun, 17 Nov 2019 22:33:53 +0000 (22:33 +0000)
bytestring.c

index a7fe5cb..82d117f 100644 (file)
@@ -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; }