zip_archive.cc: Use static cast instead of masking

Although ubsan's implicit-unsigned-integer-truncation sanitizer may be
happy, this code still performs an implicit conversion from a wider
width data structure to a narrower width data structure. Rather than
masking the bits, make the conversion explicit. This keeps ubsan happy
as well as addressing a -Wconversion warning.

This change addresses comments from the post-submit review
of a4e5433660.

Test: compiles and boots.
Bug: 122975762
Change-Id: I1fa6d6f8a6fcfb93ba9916b7d2b3564ca1d8caf3
This commit is contained in:
Nick Kralevich 2019-04-05 09:10:34 -07:00
parent 55ba959c13
commit c0bf36647b
1 changed files with 2 additions and 3 deletions

View File

@ -102,9 +102,8 @@ static uint32_t RoundUpPower2(uint32_t val) {
}
static uint32_t ComputeHash(const ZipString& name) {
return std::hash<std::string_view>{}(
std::string_view(reinterpret_cast<const char*>(name.name), name.name_length)) &
UINT32_MAX;
return static_cast<uint32_t>(std::hash<std::string_view>{}(
std::string_view(reinterpret_cast<const char*>(name.name), name.name_length)));
}
static bool isZipStringEqual(const uint8_t* start, const ZipString& zip_string,