Skip to content
Merged
Changes from 1 commit
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
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
Next Next commit
Fix rejection when non-bitfield fields are larger than 2^16 bytes
  • Loading branch information
Melissa0x1f992 committed Nov 17, 2024
commit 1962567aac71c16604a405c060b9a11ec6a82646
17 changes: 15 additions & 2 deletions Modules/_ctypes/cfield.c
Original file line number Diff line number Diff line change
Expand Up @@ -110,8 +110,21 @@ PyCField_new_impl(PyTypeObject *type, PyObject *name, PyObject *proto,
goto error;
}

Py_ssize_t bit_size = NUM_BITS(size);
if (bit_size) {
if (bit_size_obj != Py_None) {

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No need for a newline

Suggested change

Py_ssize_t bit_size;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lint is complaining about this. I'm assuming this just needs to get moved to before the if


if (PyLong_Check(bit_size_obj)) {
bit_size = PyLong_AsSsize_t(bit_size_obj);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PyLong_AsSsize_t can fail, you need to check for < 0 and then goto error.

} else {
PyErr_Format(
PyExc_ValueError,
"bit size of field %R must be an integer size for bit fields",
self->name
);
goto error;
}

assert(bit_size > 0);
assert(bit_size <= info->size * 8);
switch(info->ffi_type_pointer.type) {
Expand Down