Skip to content

Commit 2eb18a5

Browse files
committed
Fix byteswriter_resize()
1 parent c70ddb9 commit 2eb18a5

1 file changed

Lines changed: 7 additions & 0 deletions

File tree

Objects/bytesobject.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3632,8 +3632,12 @@ static inline Py_ssize_t
36323632
byteswriter_allocated(PyBytesWriter *writer)
36333633
{
36343634
if (writer->obj == NULL) {
3635+
#ifndef Py_DEBUG
3636+
return sizeof(writer->small_buffer);
3637+
#else
36353638
// Reserve the last byte for the canary byte
36363639
return sizeof(writer->small_buffer) - 1;
3640+
#endif
36373641
}
36383642
else if (writer->use_bytearray) {
36393643
return PyByteArray_GET_SIZE(writer->obj);
@@ -3708,6 +3712,9 @@ byteswriter_resize(PyBytesWriter *writer, Py_ssize_t size, int resize)
37083712

37093713
if (writer->obj != NULL) {
37103714
if (writer->use_bytearray) {
3715+
#ifdef Py_DEBUG
3716+
byteswriter_reset_trailing_byte(writer);
3717+
#endif
37113718
if (PyByteArray_Resize(writer->obj, size)) {
37123719
#ifdef Py_DEBUG
37133720
// bytearray can override the canary byte on error

0 commit comments

Comments
 (0)