From e91faa6b5ce4f34c42180d61f4ae174c61faf9d5 Mon Sep 17 00:00:00 2001 From: Dmitry Selyutin Date: Tue, 16 Aug 2022 20:58:26 +0300 Subject: [PATCH] selectable_int: strengthen type checks --- src/openpower/decoder/selectable_int.py | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/openpower/decoder/selectable_int.py b/src/openpower/decoder/selectable_int.py index bb0ac4c3..46f7107e 100644 --- a/src/openpower/decoder/selectable_int.py +++ b/src/openpower/decoder/selectable_int.py @@ -23,6 +23,8 @@ class FieldSelectableInt: """ def __init__(self, si, br): + if not isinstance(si, SelectableInt): + raise ValueError(si) self.si = si # target selectable int if isinstance(br, (list, tuple, range)): _br = BitRange() @@ -186,8 +188,15 @@ class SelectableInt: def __init__(self, value, bits=None): if isinstance(value, SelectableInt): + if bits is not None: + raise ValueError(value) bits = value.bits value = value.value + else: + if not isinstance(value, int): + raise ValueError(value) + if bits is None: + raise ValueError(bits) mask = (1 << bits) - 1 self.value = value & mask self.bits = bits @@ -427,7 +436,7 @@ class SelectableInt: return self.value != 0 def __repr__(self): - value = f"value=0x{self.value:x}, bits={self.bits}" + value = f"value={hex(self.value)}, bits={self.bits}" return f"{self.__class__.__name__}({value})" def __len__(self): -- 2.30.2