Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit eb29e9a

Browse files
committed
Fix core dump in an endcase of b.strip() that I missed.
1 parent 2fb5ac7 commit eb29e9a

2 files changed

Lines changed: 5 additions & 1 deletion

File tree

Lib/test/test_bytes.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -653,6 +653,7 @@ def test_strip(self):
653653
self.assertEqual(b.strip(b'pi'), b'mississ')
654654
self.assertEqual(b.strip(b'im'), b'ssissipp')
655655
self.assertEqual(b.strip(b'pim'), b'ssiss')
656+
self.assertEqual(b.strip(b), b'')
656657

657658
def test_lstrip(self):
658659
b = b'mississippi'

Objects/bytesobject.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2502,7 +2502,10 @@ bytes_strip(PyBytesObject *self, PyObject *arg)
25022502
argptr = ((PyBytesObject *)arg)->ob_bytes;
25032503
argsize = Py_Size(arg);
25042504
left = lstrip_helper(myptr, mysize, argptr, argsize);
2505-
right = rstrip_helper(myptr, mysize, argptr, argsize);
2505+
if (left == mysize)
2506+
right = left;
2507+
else
2508+
right = rstrip_helper(myptr, mysize, argptr, argsize);
25062509
return PyBytes_FromStringAndSize(self->ob_bytes + left, right - left);
25072510
}
25082511

0 commit comments

Comments
 (0)