diff options
author | Serhiy Storchaka <storchaka@gmail.com> | 2016-11-20 08:48:07 +0200 |
---|---|---|
committer | Serhiy Storchaka <storchaka@gmail.com> | 2016-11-20 08:48:07 +0200 |
commit | f16ff20fd73de317a70840fc339f8083c45ea466 (patch) | |
tree | 17e8e6412c0b8471ab9666fd61cda0212aa795f0 /Python/ast.c | |
parent | d97f310a9b3525c16d08f763bb3e5ed57bd62251 (diff) | |
parent | b4855ddb5ebfbc737cf9ac20197271250a73625b (diff) | |
download | cpython-f16ff20fd73de317a70840fc339f8083c45ea466.tar.gz |
Issue #28715: Added error checks for PyUnicode_AsUTF8().
Diffstat (limited to 'Python/ast.c')
-rw-r--r-- | Python/ast.c | 8 |
1 files changed, 5 insertions, 3 deletions
diff --git a/Python/ast.c b/Python/ast.c index 33b7df64ec..82f4529bf9 100644 --- a/Python/ast.c +++ b/Python/ast.c @@ -2118,17 +2118,19 @@ ast_for_atom(struct compiling *c, const node *n) errtype = "value error"; if (errtype) { char buf[128]; + const char *s = NULL; PyObject *type, *value, *tback, *errstr; PyErr_Fetch(&type, &value, &tback); errstr = PyObject_Str(value); - if (errstr) { - char *s = _PyUnicode_AsString(errstr); + if (errstr) + s = PyUnicode_AsUTF8(errstr); + if (s) { PyOS_snprintf(buf, sizeof(buf), "(%s) %s", errtype, s); - Py_DECREF(errstr); } else { PyErr_Clear(); PyOS_snprintf(buf, sizeof(buf), "(%s) unknown error", errtype); } + Py_XDECREF(errstr); ast_error(c, n, buf); Py_DECREF(type); Py_XDECREF(value); |