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

Commit a050cd06 authored by Christopher Ferris's avatar Christopher Ferris Committed by android-build-merger
Browse files

Merge "Avoid signed extension of chars for build ids." am: d451f392

am: 959013f3

Change-Id: Iefd9ff5e72dd2e9d552de2ee952dfa3e8a45dd00
parents 288e5d91 959013f3
Loading
Loading
Loading
Loading
+2 −1
Original line number Diff line number Diff line
@@ -320,7 +320,8 @@ std::string MapInfo::GetPrintableBuildID() {
  }
  std::string printable_build_id;
  for (const char& c : raw_build_id) {
    printable_build_id += android::base::StringPrintf("%02x", c);
    // Use %hhx to avoid sign extension on abis that have signed chars.
    printable_build_id += android::base::StringPrintf("%02hhx", c);
  }
  return printable_build_id;
}
+11 −0
Original line number Diff line number Diff line
@@ -78,6 +78,17 @@ TEST_F(MapInfoGetBuildIDTest, from_elf) {
  EXPECT_EQ("46414b455f4255494c445f4944", map_info_->GetPrintableBuildID());
}

TEST_F(MapInfoGetBuildIDTest, from_elf_no_sign_extension) {
  map_info_->elf.reset(elf_container_.release());

  std::string build_id = {static_cast<char>(0xfa), static_cast<char>(0xab), static_cast<char>(0x12),
                          static_cast<char>(0x02)};
  elf_interface_->FakeSetBuildID(build_id);

  EXPECT_EQ("\xFA\xAB\x12\x2", map_info_->GetBuildID());
  EXPECT_EQ("faab1202", map_info_->GetPrintableBuildID());
}

void MapInfoGetBuildIDTest::MultipleThreadTest(std::string expected_build_id) {
  static constexpr size_t kNumConcurrentThreads = 100;