Objects: Fix incorrect Bitfield maths

Turns out that #133 exposed a mistake in how we were using the end_bit
field (and it should have been picked up in review, my bad).
Essentially we were masking based on the length of the end_bit after
*already* shifting by the start_bit.  We should mask then shift, not the
other way around.

May well fix issue #135 (pdb generation will have been affected by
this).
This commit is contained in:
Mike Auty
2019-11-13 16:48:14 +00:00
parent d0a5d4ba3f
commit 648cded5e1
+1 -1
View File
@@ -367,7 +367,7 @@ class BitField(interfaces.objects.ObjectInterface, int):
end_bit: int = 0,
**kwargs) -> 'BitField':
value = base_type(context = context, object_info = object_info)
return int.__new__(cls, (value >> start_bit) & ((1 << end_bit) - 1)) # type: ignore
return int.__new__(cls, ((value & ((1 << end_bit) - 1)) >> start_bit)) # type: ignore
def write(self, value):
raise NotImplementedError("Writing to BitFields is not yet implemented")