summaryrefslogtreecommitdiffstats
path: root/Objects
diff options
context:
space:
mode:
authorBerker Peksag <berker.peksag@gmail.com>2016-09-16 14:32:06 (GMT)
committerBerker Peksag <berker.peksag@gmail.com>2016-09-16 14:32:06 (GMT)
commit7b4bcd20041d25d5c5b5f416bc6d1090dd3e374a (patch)
treea840f7f6ce44a552b1e4b066ae79664e6d521e6d /Objects
parentde3f48ae9a5c807f1af26f2841a39a3667cc9760 (diff)
parent4a72a7b6c4c95f7613486f0e4e20a3d4815a16c5 (diff)
downloadcpython-7b4bcd20041d25d5c5b5f416bc6d1090dd3e374a.zip
cpython-7b4bcd20041d25d5c5b5f416bc6d1090dd3e374a.tar.gz
cpython-7b4bcd20041d25d5c5b5f416bc6d1090dd3e374a.tar.bz2
Issue #25270: Merge from 3.5
Diffstat (limited to 'Objects')
-rw-r--r--Objects/bytesobject.c19
1 files changed, 14 insertions, 5 deletions
diff --git a/Objects/bytesobject.c b/Objects/bytesobject.c
index 1550083..598f6a1 100644
--- a/Objects/bytesobject.c
+++ b/Objects/bytesobject.c
@@ -2910,11 +2910,15 @@ _PyBytes_Resize(PyObject **pv, Py_ssize_t newsize)
PyObject *v;
PyBytesObject *sv;
v = *pv;
- if (!PyBytes_Check(v) || Py_REFCNT(v) != 1 || newsize < 0) {
- *pv = 0;
- Py_DECREF(v);
- PyErr_BadInternalCall();
- return -1;
+ if (!PyBytes_Check(v) || newsize < 0) {
+ goto error;
+ }
+ if (Py_SIZE(v) == newsize) {
+ /* return early if newsize equals to v->ob_size */
+ return 0;
+ }
+ if (Py_REFCNT(v) != 1) {
+ goto error;
}
/* XXX UNREF/NEWREF interface should be more symmetrical */
_Py_DEC_REFTOTAL;
@@ -2932,6 +2936,11 @@ _PyBytes_Resize(PyObject **pv, Py_ssize_t newsize)
sv->ob_sval[newsize] = '\0';
sv->ob_shash = -1; /* invalidate cached hash value */
return 0;
+error:
+ *pv = 0;
+ Py_DECREF(v);
+ PyErr_BadInternalCall();
+ return -1;
}
void