Skip to content

Commit b15c219

Browse files
committed
gh-130824: Add tests for NULL in PyLong_*AndOverflow functions
1 parent 3929af5 commit b15c219

File tree

2 files changed

+5
-3
lines changed

2 files changed

+5
-3
lines changed

Lib/test/test_capi/test_long.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -211,9 +211,10 @@ def check_long_asintandoverflow(self, func, min_val, max_val):
211211

212212
self.assertEqual(func(min_val - 1), (-1, -1))
213213
self.assertEqual(func(max_val + 1), (-1, +1))
214+
with self.assertRaises(SystemError):
215+
func(None)
214216

215217
# CRASHES func(1.0)
216-
# CRASHES func(NULL)
217218

218219
def test_long_asint(self):
219220
# Test PyLong_AsInt()

Modules/_testlimitedcapi/long.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -625,7 +625,8 @@ pylong_aslongandoverflow(PyObject *module, PyObject *arg)
625625
int overflow = UNINITIALIZED_INT;
626626
long value = PyLong_AsLongAndOverflow(arg, &overflow);
627627
if (value == -1 && PyErr_Occurred()) {
628-
assert(overflow == -1);
628+
// overflow can be 0 if a seperate exception occurred
629+
assert(overflow == -1 || overflow == 0);
629630
return NULL;
630631
}
631632
return Py_BuildValue("li", value, overflow);
@@ -671,7 +672,7 @@ pylong_aslonglongandoverflow(PyObject *module, PyObject *arg)
671672
int overflow = UNINITIALIZED_INT;
672673
long long value = PyLong_AsLongLongAndOverflow(arg, &overflow);
673674
if (value == -1 && PyErr_Occurred()) {
674-
assert(overflow == -1);
675+
assert(overflow == -1 || overflow == 0);
675676
return NULL;
676677
}
677678
return Py_BuildValue("Li", value, overflow);

0 commit comments

Comments
 (0)