mirror of
https://github.com/python/cpython.git
synced 2025-10-07 15:42:02 +00:00
Issue #17715: Add missing NULL Check to PyNumber_Long.
This commit is contained in:
parent
b4fd468f12
commit
c9734484ca
3 changed files with 11 additions and 0 deletions
|
@ -313,6 +313,12 @@ class IntTestCases(unittest.TestCase):
|
||||||
return 42
|
return 42
|
||||||
self.assertEqual(int(JustTrunc()), 42)
|
self.assertEqual(int(JustTrunc()), 42)
|
||||||
|
|
||||||
|
class ExceptionalTrunc(base):
|
||||||
|
def __trunc__(self):
|
||||||
|
1 / 0
|
||||||
|
with self.assertRaises(ZeroDivisionError):
|
||||||
|
int(ExceptionalTrunc())
|
||||||
|
|
||||||
for trunc_result_base in (object, Classic):
|
for trunc_result_base in (object, Classic):
|
||||||
class Integral(trunc_result_base):
|
class Integral(trunc_result_base):
|
||||||
def __int__(self):
|
def __int__(self):
|
||||||
|
|
|
@ -12,6 +12,9 @@ What's New in Python 3.3.2?
|
||||||
Core and Builtins
|
Core and Builtins
|
||||||
-----------------
|
-----------------
|
||||||
|
|
||||||
|
- Issue #17715: Fix segmentation fault from raising an exception in a __trunc__
|
||||||
|
method.
|
||||||
|
|
||||||
- Issue #16447: Fixed potential segmentation fault when setting __name__ on a
|
- Issue #16447: Fixed potential segmentation fault when setting __name__ on a
|
||||||
class.
|
class.
|
||||||
|
|
||||||
|
|
|
@ -1293,6 +1293,8 @@ PyNumber_Long(PyObject *o)
|
||||||
PyObject *truncated = PyEval_CallObject(trunc_func, NULL);
|
PyObject *truncated = PyEval_CallObject(trunc_func, NULL);
|
||||||
PyObject *int_instance;
|
PyObject *int_instance;
|
||||||
Py_DECREF(trunc_func);
|
Py_DECREF(trunc_func);
|
||||||
|
if (truncated == NULL)
|
||||||
|
return NULL;
|
||||||
/* __trunc__ is specified to return an Integral type,
|
/* __trunc__ is specified to return an Integral type,
|
||||||
but int() needs to return a int. */
|
but int() needs to return a int. */
|
||||||
int_instance = convert_integral_to_int(truncated,
|
int_instance = convert_integral_to_int(truncated,
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue