Avoid signed extension of chars for build ids.

Added a unit test that fails before the change and passes afterwards.

Bug: 120606663

Test: All unit tests pass.
Change-Id: I054c7eac0c55abc3babe1d48a041f5819ad9db81
This commit is contained in:
Christopher Ferris 2019-01-30 10:55:27 -08:00
parent 98910920ba
commit ce34d62351
2 changed files with 13 additions and 1 deletions

View file

@ -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;
}

View file

@ -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;