From c0bf36647b3498c4a456c0b1463813f69c064bf1 Mon Sep 17 00:00:00 2001 From: Nick Kralevich Date: Fri, 5 Apr 2019 09:10:34 -0700 Subject: [PATCH] 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 a4e5433660228dae47530518bfb6fc49723f8882. Test: compiles and boots. Bug: 122975762 Change-Id: I1fa6d6f8a6fcfb93ba9916b7d2b3564ca1d8caf3 --- libziparchive/zip_archive.cc | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/libziparchive/zip_archive.cc b/libziparchive/zip_archive.cc index 96dbba1b8..e1ec47aef 100644 --- a/libziparchive/zip_archive.cc +++ b/libziparchive/zip_archive.cc @@ -102,9 +102,8 @@ static uint32_t RoundUpPower2(uint32_t val) { } static uint32_t ComputeHash(const ZipString& name) { - return std::hash{}( - std::string_view(reinterpret_cast(name.name), name.name_length)) & - UINT32_MAX; + return static_cast(std::hash{}( + std::string_view(reinterpret_cast(name.name), name.name_length))); } static bool isZipStringEqual(const uint8_t* start, const ZipString& zip_string,