summaryrefslogtreecommitdiff
path: root/absl/strings/string_view.cc
diff options
context:
space:
mode:
authorGravatar Abseil Team <absl-team@google.com>2022-08-17 08:34:34 -0700
committerGravatar Copybara-Service <copybara-worker@google.com>2022-08-17 08:35:16 -0700
commit934f613818ffcb26c942dff4a80be9a4031c662c (patch)
treeef5ce22bc64d4758de1d7e339e6b4b70d8ff3e09 /absl/strings/string_view.cc
parent547802119dfa444540d8f2bb8a9f50bf64252a0f (diff)
Fix "unsafe narrowing" warnings in absl, 4/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 strings/, except /internal/.) Bug: chromium:1292951 PiperOrigin-RevId: 468205572 Change-Id: Ifce3f1a7a4b2b2c359bf7700a11279bebfef8a15
Diffstat (limited to 'absl/strings/string_view.cc')
-rw-r--r--absl/strings/string_view.cc12
1 files changed, 6 insertions, 6 deletions
diff --git a/absl/strings/string_view.cc b/absl/strings/string_view.cc
index adce3be9..e2261625 100644
--- a/absl/strings/string_view.cc
+++ b/absl/strings/string_view.cc
@@ -32,7 +32,7 @@ void WritePadding(std::ostream& o, size_t pad) {
memset(fill_buf, o.fill(), sizeof(fill_buf));
while (pad) {
size_t n = std::min(pad, sizeof(fill_buf));
- o.write(fill_buf, n);
+ o.write(fill_buf, static_cast<std::streamsize>(n));
pad -= n;
}
}
@@ -63,7 +63,7 @@ std::ostream& operator<<(std::ostream& o, string_view piece) {
size_t lpad = 0;
size_t rpad = 0;
if (static_cast<size_t>(o.width()) > piece.size()) {
- size_t pad = o.width() - piece.size();
+ size_t pad = static_cast<size_t>(o.width()) - piece.size();
if ((o.flags() & o.adjustfield) == o.left) {
rpad = pad;
} else {
@@ -71,7 +71,7 @@ std::ostream& operator<<(std::ostream& o, string_view piece) {
}
}
if (lpad) WritePadding(o, lpad);
- o.write(piece.data(), piece.size());
+ o.write(piece.data(), static_cast<std::streamsize>(piece.size()));
if (rpad) WritePadding(o, rpad);
o.width(0);
}
@@ -86,7 +86,7 @@ string_view::size_type string_view::find(string_view s,
}
const char* result =
strings_internal::memmatch(ptr_ + pos, length_ - pos, s.ptr_, s.length_);
- return result ? result - ptr_ : npos;
+ return result ? static_cast<size_type>(result - ptr_) : npos;
}
string_view::size_type string_view::find(char c, size_type pos) const noexcept {
@@ -95,7 +95,7 @@ string_view::size_type string_view::find(char c, size_type pos) const noexcept {
}
const char* result =
static_cast<const char*>(memchr(ptr_ + pos, c, length_ - pos));
- return result != nullptr ? result - ptr_ : npos;
+ return result != nullptr ? static_cast<size_type>(result - ptr_) : npos;
}
string_view::size_type string_view::rfind(string_view s,
@@ -104,7 +104,7 @@ string_view::size_type string_view::rfind(string_view s,
if (s.empty()) return std::min(length_, pos);
const char* last = ptr_ + std::min(length_ - s.length_, pos) + s.length_;
const char* result = std::find_end(ptr_, last, s.ptr_, s.ptr_ + s.length_);
- return result != last ? result - ptr_ : npos;
+ return result != last ? static_cast<size_type>(result - ptr_) : npos;
}
// Search range is [0..pos] inclusive. If pos == npos, search everything.