diff options
author | Abseil Team <absl-team@google.com> | 2022-07-28 07:45:06 -0700 |
---|---|---|
committer | Copybara-Service <copybara-worker@google.com> | 2022-07-28 07:46:07 -0700 |
commit | 7f51ef5ed2740dab2bbf53c4dd5931b6e8ec6a5b (patch) | |
tree | 72096ff69ed2b4dac6db4e1bcc5d85d3ecb0ef8d /absl/strings/internal/char_map.h | |
parent | c7e60ccfcd708a73008ed2df040162c66697bc18 (diff) |
Fix "unsafe narrowing" warnings in absl, 1/n.
Addresses failures with the following, in some files:
-Wshorten-64-to-32
-Wimplicit-int-conversion
-Wsign-compare
-Wsign-conversion
-Wtautological-unsigned-zero-compare
(This specific CL focuses on .h and win32 .inc files.)
Bug: chromium:1292951
PiperOrigin-RevId: 463835431
Change-Id: If8e5f7f651d5cd96035e23e4623bdb08a7fedabe
Diffstat (limited to 'absl/strings/internal/char_map.h')
-rw-r--r-- | absl/strings/internal/char_map.h | 20 |
1 files changed, 11 insertions, 9 deletions
diff --git a/absl/strings/internal/char_map.h b/absl/strings/internal/char_map.h index 61484de0..5aabc1fc 100644 --- a/absl/strings/internal/char_map.h +++ b/absl/strings/internal/char_map.h @@ -103,10 +103,9 @@ class Charmap { constexpr Charmap(uint64_t b0, uint64_t b1, uint64_t b2, uint64_t b3) : m_{b0, b1, b2, b3} {} - static constexpr uint64_t RangeForWord(unsigned char lo, unsigned char hi, - uint64_t word) { - return OpenRangeFromZeroForWord(hi + 1, word) & - ~OpenRangeFromZeroForWord(lo, word); + static constexpr uint64_t RangeForWord(char lo, char hi, uint64_t word) { + return OpenRangeFromZeroForWord(static_cast<unsigned char>(hi) + 1, word) & + ~OpenRangeFromZeroForWord(static_cast<unsigned char>(lo), word); } // All the chars in the specified word of the range [0, upper). @@ -119,13 +118,16 @@ class Charmap { : (~static_cast<uint64_t>(0) >> (64 - upper % 64)); } - static constexpr uint64_t CharMaskForWord(unsigned char x, uint64_t word) { - return (x / 64 == word) ? (static_cast<uint64_t>(1) << (x % 64)) : 0; + static constexpr uint64_t CharMaskForWord(char x, uint64_t word) { + const auto unsigned_x = static_cast<unsigned char>(x); + return (unsigned_x / 64 == word) + ? (static_cast<uint64_t>(1) << (unsigned_x % 64)) + : 0; } - private: - void SetChar(unsigned char c) { - m_[c / 64] |= static_cast<uint64_t>(1) << (c % 64); + void SetChar(char c) { + const auto unsigned_c = static_cast<unsigned char>(c); + m_[unsigned_c / 64] |= static_cast<uint64_t>(1) << (unsigned_c % 64); } uint64_t m_[4]; |