summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGuido van Rossum <guido@python.org>2007-08-08 21:55:33 (GMT)
committerGuido van Rossum <guido@python.org>2007-08-08 21:55:33 (GMT)
commiteb29e9ab2b037db198591a9cacb5993385c7f83d (patch)
tree0748abafc847fcd708af120f2834e2737aceabe9
parent2fb5ac745bf2edd03261ca8144eb73a1f6e54af3 (diff)
downloadcpython-eb29e9ab2b037db198591a9cacb5993385c7f83d.zip
cpython-eb29e9ab2b037db198591a9cacb5993385c7f83d.tar.gz
cpython-eb29e9ab2b037db198591a9cacb5993385c7f83d.tar.bz2
Fix core dump in an endcase of b.strip() that I missed.
-rw-r--r--Lib/test/test_bytes.py1
-rw-r--r--Objects/bytesobject.c5
2 files changed, 5 insertions, 1 deletions
diff --git a/Lib/test/test_bytes.py b/Lib/test/test_bytes.py
index 094c56c..654cb86 100644
--- a/Lib/test/test_bytes.py
+++ b/Lib/test/test_bytes.py
@@ -653,6 +653,7 @@ class BytesTest(unittest.TestCase):
self.assertEqual(b.strip(b'pi'), b'mississ')
self.assertEqual(b.strip(b'im'), b'ssissipp')
self.assertEqual(b.strip(b'pim'), b'ssiss')
+ self.assertEqual(b.strip(b), b'')
def test_lstrip(self):
b = b'mississippi'
diff --git a/Objects/bytesobject.c b/Objects/bytesobject.c
index 47ee8a4..b409a28 100644
--- a/Objects/bytesobject.c
+++ b/Objects/bytesobject.c
@@ -2502,7 +2502,10 @@ bytes_strip(PyBytesObject *self, PyObject *arg)
argptr = ((PyBytesObject *)arg)->ob_bytes;
argsize = Py_Size(arg);
left = lstrip_helper(myptr, mysize, argptr, argsize);
- right = rstrip_helper(myptr, mysize, argptr, argsize);
+ if (left == mysize)
+ right = left;
+ else
+ right = rstrip_helper(myptr, mysize, argptr, argsize);
return PyBytes_FromStringAndSize(self->ob_bytes + left, right - left);
}