Skip to content

Commit f03b895

Browse files
committed
Simplify resize error handling
1 parent 28cb8c5 commit f03b895

File tree

1 file changed

+11
-15
lines changed

1 file changed

+11
-15
lines changed

Objects/bytearrayobject.c

Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -246,25 +246,21 @@ bytearray_resize_lock_held(PyObject *self, Py_ssize_t requested_size)
246246
Py_MIN(requested_size, Py_SIZE(self)));
247247
}
248248

249-
int ret;
250249
if (obj->ob_bytes_object == NULL) {
251250
obj->ob_bytes_object = PyBytes_FromStringAndSize(NULL, alloc);
252-
if (obj->ob_bytes_object == NULL) {
253-
/* Object state valid and resize failed. */
254-
return -1;
255-
}
256-
ret = 0;
257251
}
258252
else {
259-
if (_PyBytes_Resize(&obj->ob_bytes_object, alloc) == -1) {
260-
/* storage gone and resize failed. */
261-
obj->ob_bytes_object = Py_GetConstant(Py_CONSTANT_EMPTY_BYTES);
262-
size = alloc = 0;
263-
ret = -1;
264-
}
265-
else {
266-
ret = 0;
267-
}
253+
_PyBytes_Resize(&obj->ob_bytes_object, alloc);
254+
}
255+
256+
int ret;
257+
if (obj->ob_bytes_object == NULL) {
258+
obj->ob_bytes_object = Py_GetConstant(Py_CONSTANT_EMPTY_BYTES);
259+
size = alloc = 0;
260+
ret = -1;
261+
}
262+
else {
263+
ret = 0;
268264
}
269265

270266
obj->ob_bytes = obj->ob_start = PyBytes_AS_STRING(obj->ob_bytes_object);

0 commit comments

Comments
 (0)