Merge pull request #39911 from tg-at-google:patch-1
PiperOrigin-RevId: 313528084 Change-Id: I19a18d73e0c8b47b1f921c19a32032092e7202d6
This commit is contained in:
commit
8404e3e296
@ -23,7 +23,7 @@ const char* kProtobufUint64Typename = "::tensorflow::protobuf_uint64";
|
|||||||
TStringOutputStream::TStringOutputStream(tstring* target) : target_(target) {}
|
TStringOutputStream::TStringOutputStream(tstring* target) : target_(target) {}
|
||||||
|
|
||||||
bool TStringOutputStream::Next(void** data, int* size) {
|
bool TStringOutputStream::Next(void** data, int* size) {
|
||||||
int old_size = target_->size();
|
size_t old_size = target_->size();
|
||||||
|
|
||||||
// Grow the string.
|
// Grow the string.
|
||||||
if (old_size < target_->capacity()) {
|
if (old_size < target_->capacity()) {
|
||||||
@ -32,16 +32,16 @@ bool TStringOutputStream::Next(void** data, int* size) {
|
|||||||
target_->resize_uninitialized(target_->capacity());
|
target_->resize_uninitialized(target_->capacity());
|
||||||
} else {
|
} else {
|
||||||
// Size has reached capacity, try to double the size.
|
// 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
|
// Can not double the size otherwise it is going to cause integer
|
||||||
// overflow in the expression below: old_size * 2 ";
|
// overflow in the expression below: old_size * 2 ";
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
// Double the size, also make sure that the new size is at least
|
// Double the size, also make sure that the new size is at least
|
||||||
// kMinimumSize.
|
// kMinimumSize.
|
||||||
target_->resize_uninitialized(
|
target_->resize_uninitialized(std::max(
|
||||||
std::max(old_size * 2,
|
old_size * 2,
|
||||||
kMinimumSize + 0)); // "+ 0" works around GCC4 weirdness.
|
(size_t)kMinimumSize + 0)); // "+ 0" works around GCC4 weirdness.
|
||||||
}
|
}
|
||||||
|
|
||||||
*data = target_->data() + old_size;
|
*data = target_->data() + old_size;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user