From: Petr Viktorin Date: Wed, 5 Mar 2025 11:52:40 +0000 (+0100) Subject: [3.12] gh-130824: Add tests for NULL in PyLong_*AndOverflow functions (GH-130828... X-Git-Tag: v3.12.10~124 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=8fe011af3864300df9b312584be449b3eb3e4bf8;p=thirdparty%2FPython%2Fcpython.git [3.12] gh-130824: Add tests for NULL in PyLong_*AndOverflow functions (GH-130828) (GH-130876) (cherry picked from commit 90130807d9c5a55b2a64024f5dfbee4785b9a27c) Co-authored-by: Peter Bierma Co-authored-by: Sergey B Kirpichev --- diff --git a/Lib/test/test_capi/test_long.py b/Lib/test/test_capi/test_long.py index 18507ed7c3bf..05b3a7ebd63d 100644 --- a/Lib/test/test_capi/test_long.py +++ b/Lib/test/test_capi/test_long.py @@ -208,9 +208,8 @@ class LongTests(unittest.TestCase): self.assertEqual(func(min_val - 1), (-1, -1)) self.assertEqual(func(max_val + 1), (-1, +1)) - - # CRASHES func(1.0) - # CRASHES func(NULL) + self.assertRaises(SystemError, func, None) + self.assertRaises(TypeError, func, 1.0) def test_long_aslong(self): # Test PyLong_AsLong() and PyLong_FromLong() diff --git a/Modules/_testcapi/long.c b/Modules/_testcapi/long.c index 9c5a0e386759..16eb437ffea1 100644 --- a/Modules/_testcapi/long.c +++ b/Modules/_testcapi/long.c @@ -629,7 +629,7 @@ pylong_aslongandoverflow(PyObject *module, PyObject *arg) int overflow = UNINITIALIZED_INT; long value = PyLong_AsLongAndOverflow(arg, &overflow); if (value == -1 && PyErr_Occurred()) { - assert(overflow == -1); + assert(overflow == 0); return NULL; } return Py_BuildValue("li", value, overflow); @@ -675,7 +675,7 @@ pylong_aslonglongandoverflow(PyObject *module, PyObject *arg) int overflow = UNINITIALIZED_INT; long long value = PyLong_AsLongLongAndOverflow(arg, &overflow); if (value == -1 && PyErr_Occurred()) { - assert(overflow == -1); + assert(overflow == 0); return NULL; } return Py_BuildValue("Li", value, overflow);