[Python-checkins] cpython (3.3): Issue #17715: Add missing NULL Check to PyNumber_Long.

mark.dickinson python-checkins at python.org
Sat Apr 13 18:46:24 CEST 2013


http://hg.python.org/cpython/rev/52bd2035e70a
changeset:   83295:52bd2035e70a
branch:      3.3
parent:      83288:e948154af406
user:        Mark Dickinson <dickinsm at gmail.com>
date:        Sat Apr 13 17:44:44 2013 +0100
summary:
  Issue #17715: Add missing NULL Check to PyNumber_Long.

files:
  Lib/test/test_int.py |  6 ++++++
  Misc/NEWS            |  3 +++
  Objects/abstract.c   |  2 ++
  3 files changed, 11 insertions(+), 0 deletions(-)


diff --git a/Lib/test/test_int.py b/Lib/test/test_int.py
--- a/Lib/test/test_int.py
+++ b/Lib/test/test_int.py
@@ -313,6 +313,12 @@
                     return 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):
                 class Integral(trunc_result_base):
                     def __int__(self):
diff --git a/Misc/NEWS b/Misc/NEWS
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -12,6 +12,9 @@
 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
   class.
 
diff --git a/Objects/abstract.c b/Objects/abstract.c
--- a/Objects/abstract.c
+++ b/Objects/abstract.c
@@ -1293,6 +1293,8 @@
         PyObject *truncated = PyEval_CallObject(trunc_func, NULL);
         PyObject *int_instance;
         Py_DECREF(trunc_func);
+        if (truncated == NULL)
+            return NULL;
         /* __trunc__ is specified to return an Integral type,
            but int() needs to return a int. */
         int_instance = convert_integral_to_int(truncated,

-- 
Repository URL: http://hg.python.org/cpython


More information about the Python-checkins mailing list