@@ -3805,12 +3805,12 @@ byteswriter_resize(PyBytesWriter *writer, Py_ssize_t size, int overallocate)
3805
3805
{
3806
3806
assert (size >= 0 );
3807
3807
3808
- if (size <= byteswriter_allocated (writer )) {
3808
+ Py_ssize_t old_allocated = byteswriter_allocated (writer );
3809
+ if (size <= old_allocated ) {
3809
3810
return 0 ;
3810
3811
}
3811
3812
3812
- overallocate &= writer -> overallocate ;
3813
- if (overallocate ) {
3813
+ if (overallocate & writer -> overallocate ) {
3814
3814
if (size <= (PY_SSIZE_T_MAX - size / OVERALLOCATE_FACTOR )) {
3815
3815
size += size / OVERALLOCATE_FACTOR ;
3816
3816
}
@@ -3849,6 +3849,15 @@ byteswriter_resize(PyBytesWriter *writer, Py_ssize_t size, int overallocate)
3849
3849
writer -> small_buffer ,
3850
3850
sizeof (writer -> small_buffer ));
3851
3851
}
3852
+
3853
+ #ifdef Py_DEBUG
3854
+ Py_ssize_t allocated = byteswriter_allocated (writer );
3855
+ if (overallocate && allocated > old_allocated ) {
3856
+ memset (byteswriter_data (writer ) + old_allocated , 0xff ,
3857
+ allocated - old_allocated );
3858
+ }
3859
+ #endif
3860
+
3852
3861
return 0 ;
3853
3862
}
3854
3863
@@ -3869,9 +3878,6 @@ byteswriter_create(Py_ssize_t size, int use_bytearray)
3869
3878
return NULL ;
3870
3879
}
3871
3880
}
3872
- #ifdef Py_DEBUG
3873
- memset (writer -> small_buffer , 0xff , sizeof (writer -> small_buffer ));
3874
- #endif
3875
3881
writer -> obj = NULL ;
3876
3882
writer -> size = 0 ;
3877
3883
writer -> use_bytearray = use_bytearray ;
@@ -3884,6 +3890,9 @@ byteswriter_create(Py_ssize_t size, int use_bytearray)
3884
3890
}
3885
3891
writer -> size = size ;
3886
3892
}
3893
+ #ifdef Py_DEBUG
3894
+ memset (byteswriter_data (writer ), 0xff , byteswriter_allocated (writer ));
3895
+ #endif
3887
3896
return writer ;
3888
3897
}
3889
3898
0 commit comments