mirror of
https://github.com/python/cpython.git
synced 2026-04-22 03:41:08 +00:00
bpo-33817: Fix _PyBytes_Resize() for empty bytes object. (GH-11516)
Add also tests for PyUnicode_FromFormat() and PyBytes_FromFormat()
with empty result.
(cherry picked from commit 44cc4822bb)
Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
This commit is contained in:
parent
059997d78e
commit
d39c192559
4 changed files with 26 additions and 0 deletions
|
|
@ -2990,9 +2990,22 @@ _PyBytes_Resize(PyObject **pv, Py_ssize_t newsize)
|
|||
/* return early if newsize equals to v->ob_size */
|
||||
return 0;
|
||||
}
|
||||
if (Py_SIZE(v) == 0) {
|
||||
if (newsize == 0) {
|
||||
return 0;
|
||||
}
|
||||
*pv = _PyBytes_FromSize(newsize, 0);
|
||||
Py_DECREF(v);
|
||||
return (*pv == NULL) ? -1 : 0;
|
||||
}
|
||||
if (Py_REFCNT(v) != 1) {
|
||||
goto error;
|
||||
}
|
||||
if (newsize == 0) {
|
||||
*pv = _PyBytes_FromSize(0, 0);
|
||||
Py_DECREF(v);
|
||||
return (*pv == NULL) ? -1 : 0;
|
||||
}
|
||||
/* XXX UNREF/NEWREF interface should be more symmetrical */
|
||||
_Py_DEC_REFTOTAL;
|
||||
_Py_ForgetReference(v);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue