Tools: Fix C_union ensure consistency
Previously, we overrode the _actual_value variable in the C_union in the
_ensure_consistency function to a value which contains the bytes of the
union field we have updated. This works as long as we are updating the
longest field in the union. When this is not the case then we try and
set the value of longer length union fields to a value with a
shorter length, which results in failures in the set_value_from_bytes
method.
Instead, we keep the total length of the _actual_value variable the same
and just update the first n bytes of the variable where n is the number
of bytes in the updated binary.
Change-Id: I5773116360b3f7539716332259d1563775511201
Signed-off-by: Jackson Cooper-Driver <jackson.cooper-driver@arm.com>
diff --git a/tools/modules/c_struct.py b/tools/modules/c_struct.py
index e75db6d..a019fce 100644
--- a/tools/modules/c_struct.py
+++ b/tools/modules/c_struct.py
@@ -466,7 +466,7 @@
assert(len(new_binaries) < 2)
if new_binaries:
- self._actual_value = list(new_binaries)[0]
+ self._actual_value = new_binaries[0] + self._actual_value[len(new_binaries[0]):]
for f in self._fields:
f.set_value_from_bytes(self._actual_value[:f._size])