@@ -2818,8 +2818,9 @@ _PyBytes_FromList(PyObject *x)
2818
2818
2819
2819
if (i >= size ) {
2820
2820
str = _PyBytesWriter_Resize (& writer , str , size + 1 );
2821
- if (str == NULL )
2822
- return NULL ;
2821
+ if (str == NULL ) {
2822
+ goto error ;
2823
+ }
2823
2824
size = writer .allocated ;
2824
2825
}
2825
2826
* str ++ = (char ) value ;
@@ -2913,8 +2914,9 @@ _PyBytes_FromIterator(PyObject *it, PyObject *x)
2913
2914
/* Append the byte */
2914
2915
if (i >= size ) {
2915
2916
str = _PyBytesWriter_Resize (& writer , str , size + 1 );
2916
- if (str == NULL )
2917
- return NULL ;
2917
+ if (str == NULL ) {
2918
+ goto error ;
2919
+ }
2918
2920
size = writer .allocated ;
2919
2921
}
2920
2922
* str ++ = (char ) value ;
@@ -3506,32 +3508,32 @@ PyBytesWriter_CheckPtr(PyBytesWriter *pub_writer, char *str)
3506
3508
void *
3507
3509
_PyBytesWriter_Resize (_PyBytesWriter * writer , void * str , Py_ssize_t size )
3508
3510
{
3509
- Py_ssize_t allocated , pos ;
3510
-
3511
3511
assert (_PyBytesWriter_CheckConsistency (writer , str ));
3512
3512
assert (writer -> allocated < size );
3513
3513
3514
- allocated = size ;
3514
+ Py_ssize_t allocated = size ;
3515
3515
if (writer -> overallocate
3516
3516
&& allocated <= (PY_SSIZE_T_MAX - allocated / OVERALLOCATE_FACTOR )) {
3517
3517
/* overallocate to limit the number of realloc() */
3518
3518
allocated += allocated / OVERALLOCATE_FACTOR ;
3519
3519
}
3520
3520
3521
- pos = _PyBytesWriter_GetSize (writer , str );
3521
+ Py_ssize_t pos = _PyBytesWriter_GetSize (writer , str );
3522
3522
if (!writer -> use_small_buffer ) {
3523
3523
if (writer -> use_bytearray ) {
3524
- if (PyByteArray_Resize (writer -> buffer , allocated ))
3525
- goto error ;
3524
+ if (PyByteArray_Resize (writer -> buffer , allocated )) {
3525
+ return NULL ;
3526
+ }
3526
3527
/* writer->allocated can be smaller than writer->buffer->ob_alloc,
3527
3528
but we cannot use ob_alloc because bytes may need to be moved
3528
3529
to use the whole buffer. bytearray uses an internal optimization
3529
3530
to avoid moving or copying bytes when bytes are removed at the
3530
3531
beginning (ex: del bytearray[:1]). */
3531
3532
}
3532
3533
else {
3533
- if (_PyBytes_Resize (& writer -> buffer , allocated ))
3534
- goto error ;
3534
+ if (_PyBytes_Resize (& writer -> buffer , allocated )) {
3535
+ return NULL ;
3536
+ }
3535
3537
}
3536
3538
}
3537
3539
else {
@@ -3542,8 +3544,9 @@ _PyBytesWriter_Resize(_PyBytesWriter *writer, void *str, Py_ssize_t size)
3542
3544
writer -> buffer = PyByteArray_FromStringAndSize (NULL , allocated );
3543
3545
else
3544
3546
writer -> buffer = PyBytes_FromStringAndSize (NULL , allocated );
3545
- if (writer -> buffer == NULL )
3546
- goto error ;
3547
+ if (writer -> buffer == NULL ) {
3548
+ return NULL ;
3549
+ }
3547
3550
3548
3551
if (pos != 0 ) {
3549
3552
char * dest ;
@@ -3567,17 +3570,11 @@ _PyBytesWriter_Resize(_PyBytesWriter *writer, void *str, Py_ssize_t size)
3567
3570
str = _PyBytesWriter_AsString (writer ) + pos ;
3568
3571
assert (_PyBytesWriter_CheckConsistency (writer , str ));
3569
3572
return str ;
3570
-
3571
- error :
3572
- _PyBytesWriter_Dealloc (writer );
3573
- return NULL ;
3574
3573
}
3575
3574
3576
3575
void *
3577
3576
_PyBytesWriter_Prepare (_PyBytesWriter * writer , void * str , Py_ssize_t size )
3578
3577
{
3579
- Py_ssize_t new_min_size ;
3580
-
3581
3578
assert (_PyBytesWriter_CheckConsistency (writer , str ));
3582
3579
assert (size >= 0 );
3583
3580
@@ -3588,13 +3585,16 @@ _PyBytesWriter_Prepare(_PyBytesWriter *writer, void *str, Py_ssize_t size)
3588
3585
3589
3586
if (writer -> min_size > PY_SSIZE_T_MAX - size ) {
3590
3587
PyErr_NoMemory ();
3591
- _PyBytesWriter_Dealloc (writer );
3592
3588
return NULL ;
3593
3589
}
3594
- new_min_size = writer -> min_size + size ;
3590
+ Py_ssize_t new_min_size = writer -> min_size + size ;
3595
3591
3596
- if (new_min_size > writer -> allocated )
3592
+ if (new_min_size > writer -> allocated ) {
3597
3593
str = _PyBytesWriter_Resize (writer , str , new_min_size );
3594
+ if (str == NULL ) {
3595
+ return NULL ;
3596
+ }
3597
+ }
3598
3598
3599
3599
writer -> min_size = new_min_size ;
3600
3600
return str ;
0 commit comments