Skip to content

[3.13] gh-130824: Add tests for NULL in PyLong_*AndOverflow functions (GH-130828) #130869

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Mar 5, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions Lib/test/test_capi/test_long.py
Original file line number Diff line number Diff line change
Expand Up @@ -210,9 +210,8 @@ def check_long_asintandoverflow(self, func, min_val, max_val):

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_asint(self):
# Test PyLong_AsInt()
Expand Down
4 changes: 2 additions & 2 deletions Modules/_testlimitedcapi/long.c
Original file line number Diff line number Diff line change
Expand Up @@ -625,7 +625,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);
Expand Down Expand Up @@ -671,7 +671,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);
Expand Down
Loading