-
-
Notifications
You must be signed in to change notification settings - Fork 31k
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
bpo-22273: Update ctypes to correctly handle arrays in small structur… #15839
Conversation
Modules/_ctypes/stgdict.c
Outdated
StgDictObject *dict; | ||
int bitsize = 0; | ||
|
||
if (!pair || !PyArg_ParseTuple(pair, "UO|i", &name, &desc, &bitsize)) { |
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.
According to PEP 7, lines should be limited to 79 chars.
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.
IMO we shouldn't apply this rule too strictly - it's intended to avoid too-deep nesting in code. In just about all cases in this file, the longer lines are due to verbose error messages or long variable names (neither of which are a bad thing).
Thanks @vsajip for the PR 🌮🎉.. I'm working now to backport this PR to: 3.7. |
Thanks @vsajip for the PR 🌮🎉.. I'm working now to backport this PR to: 3.8. |
GH-16369 is a backport of this pull request to the 3.7 branch. |
GH-16370 is a backport of this pull request to the 3.8 branch. |
pythonGH-15839) (cherry picked from commit 12f209e) Co-authored-by: Vinay Sajip <vinay_sajip@yahoo.co.uk>
|
|
|
|
|
|
||
#define MAX_ELEMENTS 16 | ||
|
||
if (arrays_seen && (size <= 16)) { |
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.
@vsajip Is it intentional that 16
is used here instead of MAX_ELEMENTS
?
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.
Whoops, no. That's a slip-up. Looks like I'll need to find a fix for the buildbot failures, anyway ... so I'll deal with this soon.
/* Copy over the element's type, length times. */ | ||
while (length > 0) { | ||
actual_types[actual_type_index++] = &edict->ffi_type_pointer; | ||
assert(actual_type_index <= MAX_ELEMENTS); |
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.
Assertion can be checked just once before the while loop.
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.
But actual_type_index
is incremented in the loop, and in theory the increment could take it past the end of the array, which is what the assertion is guarding against.
…es on x86_64.
https://bugs.python.org/issue22273