Skip to content
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
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
3 changes: 3 additions & 0 deletions Lib/test/test_struct.py
Original file line number Diff line number Diff line change
Expand Up @@ -540,6 +540,9 @@ def __bool__(self):

for c in [b'\x01', b'\x7f', b'\xff', b'\x0f', b'\xf0']:
self.assertTrue(struct.unpack('>?', c)[0])
self.assertTrue(struct.unpack('<?', c)[0])
self.assertTrue(struct.unpack('=?', c)[0])
self.assertTrue(struct.unpack('@?', c)[0])

def test_count_overflow(self):
hugecount = '{}b'.format(sys.maxsize+1)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Don't copy arbitrary values to :c:expr:`_Bool` in the :mod:`struct` module.
5 changes: 2 additions & 3 deletions Modules/_struct.c
Original file line number Diff line number Diff line change
Expand Up @@ -497,9 +497,8 @@ nu_ulonglong(_structmodulestate *state, const char *p, const formatdef *f)
static PyObject *
nu_bool(_structmodulestate *state, const char *p, const formatdef *f)
{
_Bool x;
memcpy(&x, p, sizeof x);
return PyBool_FromLong(x != 0);
const _Bool bool_false = false;
return PyBool_FromLong(memcmp(p, &bool_false, sizeof(_Bool)));
}


Expand Down
Loading