diff options
author | INADA Naoki <songofacandy@gmail.com> | 2017-01-06 08:32:01 (GMT) |
---|---|---|
committer | INADA Naoki <songofacandy@gmail.com> | 2017-01-06 08:32:01 (GMT) |
commit | a634e23209e90fd516fae1b4a303d57fdb1b9917 (patch) | |
tree | 33c88b1473930f36920e7d94f78fe39872b52f93 /Objects/bytesobject.c | |
parent | a251fb02f4400a2ea32677110e430742fd1444bc (diff) | |
download | cpython-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/bytesobject.c')
-rw-r--r-- | Objects/bytesobject.c | 20 |
1 files changed, 12 insertions, 8 deletions
diff --git a/Objects/bytesobject.c b/Objects/bytesobject.c index b22e57e..5d48440 100644 --- a/Objects/bytesobject.c +++ b/Objects/bytesobject.c @@ -2593,16 +2593,20 @@ bytes_new(PyTypeObject *type, PyObject *args, PyObject *kwds) if (PyIndex_Check(x)) { size = PyNumber_AsSsize_t(x, PyExc_OverflowError); if (size == -1 && PyErr_Occurred()) { - return NULL; + if (PyErr_ExceptionMatches(PyExc_OverflowError)) + return NULL; + PyErr_Clear(); /* fall through */ } - if (size < 0) { - PyErr_SetString(PyExc_ValueError, "negative count"); - return NULL; + else { + if (size < 0) { + PyErr_SetString(PyExc_ValueError, "negative count"); + return NULL; + } + new = _PyBytes_FromSize(size, 1); + if (new == NULL) + return NULL; + return new; } - new = _PyBytes_FromSize(size, 1); - if (new == NULL) - return NULL; - return new; } return PyBytes_FromObject(x); |