[issue39858] bitfield layout wrong in ctypes
Sam Price
report at bugs.python.org
Thu Mar 5 10:57:41 EST 2020
Sam Price <thesamprice at gmail.com> added the comment:
Does not happen on windows.
Error is in cfield.c
```
#ifndef MS_WIN32
} else if (bitsize /* this is a bitfield request */
&& *pfield_size /* we have a bitfield open */
&& dict->size * 8 >= *pfield_size
&& (*pbitofs + bitsize) <= dict->size * 8) {
/* expand bit field */
fieldtype = EXPAND_BITFIELD;
#endif
```
Specifically dict->size * 8 >= *pfield_size
if *bitofs == *pfield_size then the current field is filled, and expanding the bitfield should not be done.
Consider adding this *pfield_size != *bitofs
#ifndef MS_WIN32
} else if (bitsize /* this is a bitfield request */
&& *pfield_size /* we have a bitfield open */
&& *pfield_size != *pbitofs /* Current field has been filled, start new one */
&& dict->size * 8 >= *pfield_size
&& (*pbitofs + bitsize) <= dict->size * 8) {
/* expand bit field */
fieldtype = EXPAND_BITFIELD;
#endif
----------
versions: +Python 3.7, Python 3.8, Python 3.9
_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue39858>
_______________________________________
More information about the Python-bugs-list
mailing list