summaryrefslogtreecommitdiffstats
path: root/Objects/bytearrayobject.c
diff options
context:
space:
mode:
authorINADA Naoki <songofacandy@gmail.com>2017-01-06 08:32:01 (GMT)
committerINADA Naoki <songofacandy@gmail.com>2017-01-06 08:32:01 (GMT)
commita634e23209e90fd516fae1b4a303d57fdb1b9917 (patch)
tree33c88b1473930f36920e7d94f78fe39872b52f93 /Objects/bytearrayobject.c
parenta251fb02f4400a2ea32677110e430742fd1444bc (diff)
downloadcpython-a634e23209e90fd516fae1b4a303d57fdb1b9917.zip
cpython-a634e23209e90fd516fae1b4a303d57fdb1b9917.tar.gz
cpython-a634e23209e90fd516fae1b4a303d57fdb1b9917.tar.bz2
Issue #29159: Fix regression in bytes(x) when x.__index__() raises Exception.
Diffstat (limited to 'Objects/bytearrayobject.c')
-rw-r--r--Objects/bytearrayobject.c22
1 files changed, 13 insertions, 9 deletions
diff --git a/Objects/bytearrayobject.c b/Objects/bytearrayobject.c
index c6d0707..a8d6980 100644
--- a/Objects/bytearrayobject.c
+++ b/Objects/bytearrayobject.c
@@ -798,18 +798,22 @@ bytearray_init(PyByteArrayObject *self, PyObject *args, PyObject *kwds)
if (PyIndex_Check(arg)) {
count = PyNumber_AsSsize_t(arg, PyExc_OverflowError);
if (count == -1 && PyErr_Occurred()) {
- return -1;
- }
- if (count < 0) {
- PyErr_SetString(PyExc_ValueError, "negative count");
- return -1;
+ if (PyErr_ExceptionMatches(PyExc_OverflowError))
+ return -1;
+ PyErr_Clear(); /* fall through */
}
- if (count > 0) {
- if (PyByteArray_Resize((PyObject *)self, count))
+ else {
+ if (count < 0) {
+ PyErr_SetString(PyExc_ValueError, "negative count");
return -1;
- memset(PyByteArray_AS_STRING(self), 0, count);
+ }
+ if (count > 0) {
+ if (PyByteArray_Resize((PyObject *)self, count))
+ return -1;
+ memset(PyByteArray_AS_STRING(self), 0, count);
+ }
+ return 0;
}
- return 0;
}
/* Use the buffer API */