Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 42ecc03d authored by Qasim Javed's avatar Qasim Javed
Browse files

rusty-gd: Fix offsets for scalar fields.

Bug: 171749953
Tag: #gd-refactor
Test: gd/cert/run --rhost SimpleHalTest

Change-Id: I758f0a8397341ae0ec0f8356ab96e9c2ecea14ae
parent bb3440c6
Loading
Loading
Loading
Loading
+7 −4
Original line number Diff line number Diff line
@@ -156,13 +156,16 @@ int ScalarField::GetRustBitOffset(

void ScalarField::GenRustGetter(std::ostream& s, Size start_offset, Size end_offset) const {
  Size size = GetSize();

  int num_leading_bits = GetRustBitOffset(s, start_offset, end_offset, GetSize());

  s << "let " << GetName() << " = ";
  if (num_leading_bits == 0) {
    s << GetRustDataType() << "::from_le_bytes(bytes[" << start_offset.bytes() << "..";
  s << start_offset.bytes() + GetSize().bytes() << "].try_into().unwrap());";

  if (num_leading_bits != 0) {
    s << start_offset.bytes() + size.bytes() << "].try_into().unwrap());";
  } else {
    s << GetRustDataType() << "::from_le_bytes(bytes[" << start_offset.bytes() - 1 << "..";
    s << start_offset.bytes() + size.bytes() - 1 << "].try_into().unwrap());";
    s << "let " << GetName() << " = " << GetName() << " >> " << num_leading_bits << ";";
  }