@@ -3801,7 +3801,7 @@ byteswriter_allocated(PyBytesWriter *writer)
3801
3801
3802
3802
3803
3803
static inline int
3804
- byteswriter_resize (PyBytesWriter * writer , Py_ssize_t size , int overallocate )
3804
+ byteswriter_resize (PyBytesWriter * writer , Py_ssize_t size , int resize )
3805
3805
{
3806
3806
assert (size >= 0 );
3807
3807
@@ -3810,7 +3810,7 @@ byteswriter_resize(PyBytesWriter *writer, Py_ssize_t size, int overallocate)
3810
3810
return 0 ;
3811
3811
}
3812
3812
3813
- if (overallocate & writer -> overallocate ) {
3813
+ if (resize & writer -> overallocate ) {
3814
3814
if (size <= (PY_SSIZE_T_MAX - size / OVERALLOCATE_FACTOR )) {
3815
3815
size += size / OVERALLOCATE_FACTOR ;
3816
3816
}
@@ -3834,25 +3834,29 @@ byteswriter_resize(PyBytesWriter *writer, Py_ssize_t size, int overallocate)
3834
3834
if (writer -> obj == NULL ) {
3835
3835
return -1 ;
3836
3836
}
3837
- assert ((size_t )size > sizeof (writer -> small_buffer ));
3838
- memcpy (PyByteArray_AS_STRING (writer -> obj ),
3839
- writer -> small_buffer ,
3840
- sizeof (writer -> small_buffer ));
3837
+ if (resize ) {
3838
+ assert ((size_t )size > sizeof (writer -> small_buffer ));
3839
+ memcpy (PyByteArray_AS_STRING (writer -> obj ),
3840
+ writer -> small_buffer ,
3841
+ sizeof (writer -> small_buffer ));
3842
+ }
3841
3843
}
3842
3844
else {
3843
3845
writer -> obj = PyBytes_FromStringAndSize (NULL , size );
3844
3846
if (writer -> obj == NULL ) {
3845
3847
return -1 ;
3846
3848
}
3847
- assert ((size_t )size > sizeof (writer -> small_buffer ));
3848
- memcpy (PyBytes_AS_STRING (writer -> obj ),
3849
- writer -> small_buffer ,
3850
- sizeof (writer -> small_buffer ));
3849
+ if (resize ) {
3850
+ assert ((size_t )size > sizeof (writer -> small_buffer ));
3851
+ memcpy (PyBytes_AS_STRING (writer -> obj ),
3852
+ writer -> small_buffer ,
3853
+ sizeof (writer -> small_buffer ));
3854
+ }
3851
3855
}
3852
3856
3853
3857
#ifdef Py_DEBUG
3854
3858
Py_ssize_t allocated = byteswriter_allocated (writer );
3855
- if (overallocate && allocated > old_allocated ) {
3859
+ if (resize && allocated > old_allocated ) {
3856
3860
memset (byteswriter_data (writer ) + old_allocated , 0xff ,
3857
3861
allocated - old_allocated );
3858
3862
}
0 commit comments