-
-
Notifications
You must be signed in to change notification settings - Fork 30k
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
Wrong return value from PyLong_AsUnsignedLongLongMask on PyErr_BadInternalCall #81351
Comments
Hi, while checking the longobject implementation for a Stack Overflow answer, I noticed that the functions First case: Line 1379 in cb65202
static unsigned long long
_PyLong_AsUnsignedLongLongMask(PyObject *vv)
{
PyLongObject *v;
unsigned long long x;
Py_ssize_t i;
int sign;
if (vv == NULL || !PyLong_Check(vv)) {
PyErr_BadInternalCall();
return (unsigned long) -1; <<<<
} Second case: Line 1407 in cb65202
They seem to have been incorrect for quite some time, the other one blames back to the SVN era. The bug seems to be in 2.7 alike: Line 1025 in 20093b3
The correct return value should of course be |
-1 is documented: https://docs.python.org/dev/c-api/long.html#c.PyLong_AsUnsignedLongLongMask It's not a bug but a deliberate behavior. See also the general behavior described at: |
Victor, as a friendly reminder, (unsigned long)-1 is not necessarily the same number as (unsigned long long)-1. The documentation means the latter. |
As ztane says, the issue isn't the -1, it's the type of the cast. This looks like a legitimate issue to me. |
Aaaah, I didn't notice that the function returns unsigned *long long*, sorry :-) Which platform is impacted? Windows 64-bit? Does it mean that we have zero unit test on this function? Or does it mean that (unsigned long)-1 is compiled correctly as (unsigned long long)-1 on Windows 64-bit? Is "long long" 8 bytes long and "long" 4 bytes long on Windows 64-bit? |
Unsigned long long needs to be at least 64 bits wide, so it is probably all 32-bit platforms and 64-bit window at least. These functions are not used only in a few places within the CPython code and when they are they're guarded with |
Python 2.7 - 3.9 are affected. Python 3.6 no longer accept bugfixes. |
Thanks Antti Haapala for the bug report and thanks Zackery Spytz for the fix! |
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: