in resolution of [Wsign-compare] warning id 1

This commit is contained in:
tg-at-google 2020-05-27 16:22:38 +00:00 committed by Taré Gaskin
parent b97bfb5d69
commit 42ca7c2063

View File

@ -23,7 +23,7 @@ const char* kProtobufUint64Typename = "::tensorflow::protobuf_uint64";
TStringOutputStream::TStringOutputStream(tstring* target) : target_(target) {}
bool TStringOutputStream::Next(void** data, int* size) {
int old_size = target_->size();
size_t old_size = target_->size();
// Grow the string.
if (old_size < target_->capacity()) {
@ -32,7 +32,7 @@ bool TStringOutputStream::Next(void** data, int* size) {
target_->resize_uninitialized(target_->capacity());
} else {
// Size has reached capacity, try to double the size.
if (old_size > std::numeric_limits<int>::max() / 2) {
if (old_size > std::numeric_limits<size_t>::max() / 2) {
// Can not double the size otherwise it is going to cause integer
// overflow in the expression below: old_size * 2 ";
return false;
@ -41,7 +41,7 @@ bool TStringOutputStream::Next(void** data, int* size) {
// kMinimumSize.
target_->resize_uninitialized(
std::max(old_size * 2,
kMinimumSize + 0)); // "+ 0" works around GCC4 weirdness.
(size_t)kMinimumSize + 0)); // "+ 0" works around GCC4 weirdness.
}
*data = target_->data() + old_size;