-
-
Notifications
You must be signed in to change notification settings - Fork 32.3k
bpo-29843: Raise ValueError instead of OverflowError in case of a negative _length_ in a ctypes.Array subclass #3822
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
Conversation
Modules/_ctypes/_ctypes.c
Outdated
assert(overflow < 0 || length < 0); | ||
PyErr_SetString(PyExc_ValueError, | ||
"The '_length_' attribute must be non-negative"); | ||
} | ||
Py_DECREF(length_attr); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this can be moved right after PyLong_AsLongAndOverflow()
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM.
@serhiy-storchaka, can this go in?
@orenmn: Can you please update or rebase this change? |
I am sorry, but I am currently very busy, and so I would be happy if someone else did that. |
3dddab3
to
8e3d4ba
Compare
It is not so easy, since In addition, there is a behavior difference between |
Can we just add a |
I mean |
Perhaps. Just now the solution of this issue requires different code. |
+1 to keep PyLong_AsSsize_t() but use _PyLong_Sign() to raise the ValueError (for negative number). @taleinat: are you interested to rework this PR or maybe create a new one based on this PR? |
This is superseded by PR GH-10029. |
_ctypes.c
: add checks to find whether_length_
is negative or too big, and raise an error accordingly.test_arrays.py
: add tests to verify that the right error is raised for various values of_length_
.https://bugs.python.org/issue29843