diff options
author | Abseil Team <absl-team@google.com> | 2022-08-04 05:19:56 -0700 |
---|---|---|
committer | Copybara-Service <copybara-worker@google.com> | 2022-08-04 05:20:40 -0700 |
commit | 751ade00ee347abef5dac7248db851e3f2012e14 (patch) | |
tree | d5946590986f065406933c68bda8fd6af3013473 /absl/numeric/int128.cc | |
parent | 07360899e64ded32e9a5e304bd6a3b6a0ff266bc (diff) |
Fix "unsafe narrowing" warnings in absl, 3/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 .cc files in dirs n-t, except string.)
Bug: chromium:1292951
PiperOrigin-RevId: 465287204
Change-Id: I0fe98ff78bf3c08d86992019eb626755f8b6803e
Diffstat (limited to 'absl/numeric/int128.cc')
-rw-r--r-- | absl/numeric/int128.cc | 18 |
1 files changed, 10 insertions, 8 deletions
diff --git a/absl/numeric/int128.cc b/absl/numeric/int128.cc index 8cdcbf05..e5526c6f 100644 --- a/absl/numeric/int128.cc +++ b/absl/numeric/int128.cc @@ -209,15 +209,16 @@ std::ostream& operator<<(std::ostream& os, uint128 v) { // Add the requisite padding. std::streamsize width = os.width(0); if (static_cast<size_t>(width) > rep.size()) { + const size_t count = static_cast<size_t>(width) - rep.size(); std::ios::fmtflags adjustfield = flags & std::ios::adjustfield; if (adjustfield == std::ios::left) { - rep.append(width - rep.size(), os.fill()); + rep.append(count, os.fill()); } else if (adjustfield == std::ios::internal && (flags & std::ios::showbase) && (flags & std::ios::basefield) == std::ios::hex && v != 0) { - rep.insert(2, width - rep.size(), os.fill()); + rep.insert(2, count, os.fill()); } else { - rep.insert(0, width - rep.size(), os.fill()); + rep.insert(0, count, os.fill()); } } @@ -306,22 +307,23 @@ std::ostream& operator<<(std::ostream& os, int128 v) { // Add the requisite padding. std::streamsize width = os.width(0); if (static_cast<size_t>(width) > rep.size()) { + const size_t count = static_cast<size_t>(width) - rep.size(); switch (flags & std::ios::adjustfield) { case std::ios::left: - rep.append(width - rep.size(), os.fill()); + rep.append(count, os.fill()); break; case std::ios::internal: if (print_as_decimal && (rep[0] == '+' || rep[0] == '-')) { - rep.insert(1, width - rep.size(), os.fill()); + rep.insert(1, count, os.fill()); } else if ((flags & std::ios::basefield) == std::ios::hex && (flags & std::ios::showbase) && v != 0) { - rep.insert(2, width - rep.size(), os.fill()); + rep.insert(2, count, os.fill()); } else { - rep.insert(0, width - rep.size(), os.fill()); + rep.insert(0, count, os.fill()); } break; default: // std::ios::right - rep.insert(0, width - rep.size(), os.fill()); + rep.insert(0, count, os.fill()); break; } } |