From e3c807d4e752b477b707f5d021264faf9b127304 Mon Sep 17 00:00:00 2001 From: Bo Yang Date: Fri, 23 Jun 2017 12:56:44 -0700 Subject: Fix more implicit type conversions in public headers and generated code. --- src/google/protobuf/stubs/stringpiece.h | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) (limited to 'src/google/protobuf/stubs/stringpiece.h') diff --git a/src/google/protobuf/stubs/stringpiece.h b/src/google/protobuf/stubs/stringpiece.h index 8910688b..563ff75d 100644 --- a/src/google/protobuf/stubs/stringpiece.h +++ b/src/google/protobuf/stubs/stringpiece.h @@ -292,7 +292,7 @@ class LIBPROTOBUF_EXPORT StringPiece { int compare(StringPiece x) const { const stringpiece_ssize_type min_size = length_ < x.length_ ? length_ : x.length_; - int r = memcmp(ptr_, x.ptr_, min_size); + int r = memcmp(ptr_, x.ptr_, static_cast(min_size)); if (r < 0) return -1; if (r > 0) return 1; if (length_ < x.length_) return -1; @@ -310,7 +310,7 @@ class LIBPROTOBUF_EXPORT StringPiece { // "as_string()" method defined here for existing code. string ToString() const { if (ptr_ == NULL) return string(); - return string(data(), size()); + return string(data(), static_cast(size())); } operator string() const { @@ -321,12 +321,14 @@ class LIBPROTOBUF_EXPORT StringPiece { void AppendToString(string* target) const; bool starts_with(StringPiece x) const { - return (length_ >= x.length_) && (memcmp(ptr_, x.ptr_, x.length_) == 0); + return (length_ >= x.length_) && + (memcmp(ptr_, x.ptr_, static_cast(x.length_)) == 0); } bool ends_with(StringPiece x) const { return ((length_ >= x.length_) && - (memcmp(ptr_ + (length_-x.length_), x.ptr_, x.length_) == 0)); + (memcmp(ptr_ + (length_-x.length_), x.ptr_, + static_cast(x.length_)) == 0)); } // Checks whether StringPiece starts with x and if so advances the beginning @@ -398,7 +400,7 @@ inline bool operator==(StringPiece x, StringPiece y) { } return x.data() == y.data() || len <= 0 || - memcmp(x.data(), y.data(), len) == 0; + memcmp(x.data(), y.data(), static_cast(len)) == 0; } inline bool operator!=(StringPiece x, StringPiece y) { @@ -408,7 +410,7 @@ inline bool operator!=(StringPiece x, StringPiece y) { inline bool operator<(StringPiece x, StringPiece y) { const stringpiece_ssize_type min_size = x.size() < y.size() ? x.size() : y.size(); - const int r = memcmp(x.data(), y.data(), min_size); + const int r = memcmp(x.data(), y.data(), static_cast(min_size)); return (r < 0) || (r == 0 && x.size() < y.size()); } @@ -458,7 +460,9 @@ struct StringPiecePod { return size_; } - std::string ToString() const { return std::string(data_, size_); } + std::string ToString() const { + return std::string(data_, static_cast(size_)); + } private: const char* data_; stringpiece_ssize_type size_; @@ -473,7 +477,7 @@ template<> struct hash { size_t operator()(const StringPiece& s) const { size_t result = 0; for (const char *str = s.data(), *end = str + s.size(); str < end; str++) { - result = 5 * result + *str; + result = 5 * result + static_cast(*str); } return result; } -- cgit v1.2.3